Class: Psych::Visitors::RestrictedYAMLTree
- Defined in:
- lib/psych/visitors/yaml_tree.rb
Constant Summary collapse
- DEFAULT_PERMITTED_CLASSES =
{ TrueClass => true, FalseClass => true, NilClass => true, Integer => true, Float => true, String => true, Array => true, Hash => true, }.compare_by_identity.freeze
Instance Attribute Summary
Attributes inherited from YAMLTree
Instance Method Summary collapse
- #accept(target) ⇒ Object
-
#initialize(emitter, ss, options) ⇒ RestrictedYAMLTree
constructor
A new instance of RestrictedYAMLTree.
- #visit_Symbol(sym) ⇒ Object
Methods inherited from YAMLTree
create, #finish, #push, #start, #tree, #visit_Array, #visit_BasicObject, #visit_BigDecimal, #visit_Class, #visit_Complex, #visit_Date, #visit_DateTime, #visit_Encoding, #visit_Enumerator, #visit_Exception, #visit_Float, #visit_Hash, #visit_Integer, #visit_Module, #visit_NameError, #visit_NilClass, #visit_Object, #visit_Psych_Omap, #visit_Psych_Set, #visit_Range, #visit_Rational, #visit_Regexp, #visit_String, #visit_Struct, #visit_Time
Constructor Details
#initialize(emitter, ss, options) ⇒ RestrictedYAMLTree
Returns a new instance of RestrictedYAMLTree.
549 550 551 552 553 554 555 556 557 558 559 560 |
# File 'lib/psych/visitors/yaml_tree.rb', line 549 def initialize emitter, ss, super @permitted_classes = DEFAULT_PERMITTED_CLASSES.dup Array([:permitted_classes]).each do |klass| @permitted_classes[klass] = true end @permitted_symbols = {}.compare_by_identity Array([:permitted_symbols]).each do |symbol| @permitted_symbols[symbol] = true end @aliases = .fetch(:aliases, false) end |
Instance Method Details
#accept(target) ⇒ Object
562 563 564 565 566 567 568 569 570 571 572 |
# File 'lib/psych/visitors/yaml_tree.rb', line 562 def accept target if !@aliases && @st.key?(target) raise BadAlias, "Tried to dump an aliased object" end unless Symbol === target || @permitted_classes[target.class] raise DisallowedClass.new('dump', target.class.name || target.class.inspect) end super end |
#visit_Symbol(sym) ⇒ Object
574 575 576 577 578 579 580 |
# File 'lib/psych/visitors/yaml_tree.rb', line 574 def visit_Symbol sym unless @permitted_classes[Symbol] || @permitted_symbols[sym] raise DisallowedClass.new('dump', "Symbol(#{sym.inspect})") end super end |