summaryrefslogtreecommitdiff
path: root/ext/psych/lib/psych
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2019-07-24 15:35:55 -0400
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-06-05 11:49:56 +0900
commit4085c51a5175aeff2aeb8b849214c2899a79eb19 (patch)
tree83fa480a412a7e94b26c4eab1b34ba7ad47bb22e /ext/psych/lib/psych
parent591a3326e33889858276d66b157125273491edee (diff)
[ruby/psych] Implement a freeze load option
https://github.com/ruby/psych/commit/04f97f7a56
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3188
Diffstat (limited to 'ext/psych/lib/psych')
-rw-r--r--ext/psych/lib/psych/nodes/node.rb4
-rw-r--r--ext/psych/lib/psych/visitors/to_ruby.rb7
2 files changed, 6 insertions, 5 deletions
diff --git a/ext/psych/lib/psych/nodes/node.rb b/ext/psych/lib/psych/nodes/node.rb
index 7e414e771f..05cb08dac0 100644
--- a/ext/psych/lib/psych/nodes/node.rb
+++ b/ext/psych/lib/psych/nodes/node.rb
@@ -46,8 +46,8 @@ module Psych
# Convert this node to Ruby.
#
# See also Psych::Visitors::ToRuby
- def to_ruby(symbolize_names: false)
- Visitors::ToRuby.create(symbolize_names: symbolize_names).accept(self)
+ def to_ruby(symbolize_names: false, freeze: false)
+ Visitors::ToRuby.create(symbolize_names: symbolize_names, freeze: freeze).accept(self)
end
alias :transform :to_ruby
diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb
index 3021aa7eda..68452e5c3e 100644
--- a/ext/psych/lib/psych/visitors/to_ruby.rb
+++ b/ext/psych/lib/psych/visitors/to_ruby.rb
@@ -12,21 +12,22 @@ module Psych
###
# This class walks a YAML AST, converting each node to Ruby
class ToRuby < Psych::Visitors::Visitor
- def self.create(symbolize_names: false)
+ def self.create(symbolize_names: false, freeze: false)
class_loader = ClassLoader.new
scanner = ScalarScanner.new class_loader
- new(scanner, class_loader, symbolize_names: symbolize_names)
+ new(scanner, class_loader, symbolize_names: symbolize_names, freeze: freeze)
end
attr_reader :class_loader
- def initialize ss, class_loader, symbolize_names: false
+ def initialize ss, class_loader, symbolize_names: false, freeze: false
super()
@st = {}
@ss = ss
@domain_types = Psych.domain_types
@class_loader = class_loader
@symbolize_names = symbolize_names
+ @freeze = freeze
end
def accept target