123456789_123456789_123456789_123456789_123456789_

Class: Psych::Visitors::RestrictedYAMLTree

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, YAMLTree, Visitor
Instance Chain:
self, YAMLTree, Visitor
Inherits: Psych::Visitors::YAMLTree
Defined in: ext/psych/lib/psych/visitors/yaml_tree.rb

Constant Summary

Class Method Summary

Instance Attribute Summary

YAMLTree - Inherited

Instance Method Summary

Constructor Details

.new(emitter, ss, options) ⇒ RestrictedYAMLTree

[ GitHub ]

  
# File 'ext/psych/lib/psych/visitors/yaml_tree.rb', line 553

def initialize emitter, ss, options
  super
  @permitted_classes = DEFAULT_PERMITTED_CLASSES.dup
  Array(options[:permitted_classes]).each do |klass|
    @permitted_classes[klass] = true
  end
  @permitted_symbols = {}.compare_by_identity
  Array(options[:permitted_symbols]).each do |symbol|
    @permitted_symbols[symbol] = true
  end
  @aliases = options.fetch(:aliases, false)
end

Instance Method Details

#accept(target)

[ GitHub ]

  
# File 'ext/psych/lib/psych/visitors/yaml_tree.rb', line 566

def accept target
  if !@aliases && @st.key?(target)
    raise BadAlias, "Tried to dump an aliased object"
  end

  unless @permitted_classes[target.class]
    raise DisallowedClass.new('dump', target.class.name || target.class.inspect)
  end

  super
end

#visit_Symbol(sym)

[ GitHub ]

  
# File 'ext/psych/lib/psych/visitors/yaml_tree.rb', line 578

def visit_Symbol sym
  unless @permitted_symbols[sym]
    raise DisallowedClass.new('dump', "Symbol(#{sym.inspect})")
  end

  super
end