类 Psych::Visitors::RestrictedYAMLTree

常量

DEFAULT_PERMITTED_CLASSES

公共类方法

new(emitter, ss, options) 点击切换源代码
调用超类方法 Psych::Visitors::YAMLTree::new
# File psych/lib/psych/visitors/yaml_tree.rb, line 552
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

公共实例方法

accept(target) 点击切换源代码
# File psych/lib/psych/visitors/yaml_tree.rb, line 565
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) 点击切换源代码
# File psych/lib/psych/visitors/yaml_tree.rb, line 577
def visit_Symbol sym
  unless @permitted_classes[Symbol] || @permitted_symbols[sym]
    raise DisallowedClass.new('dump', "Symbol(#{sym.inspect})")
  end

  super
end