class Psych::Visitors::RestrictedYAMLTree - Documentation for Ruby 4.0
Description: Documentation for the Psych::Visitors::RestrictedYAMLTree class
Keywords: ruby,class,Psych::Visitors::RestrictedYAMLTree

🔍

No recent searches

# class Psych::Visitors::RestrictedYAMLTree

### Constants

DEFAULT_PERMITTED_CLASSES

### Public Class Methods

new (emitter, ss, options)
Source

    # File ext/psych/lib/psych/visitors/yaml_tree.rb, line 592
    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

Calls superclass method `Psych::Visitors::YAMLTree::new`

### Public Instance Methods

accept (target)
Source

    # File ext/psych/lib/psych/visitors/yaml_tree.rb, line 605
    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

Calls superclass method `Psych::Visitors::YAMLTree#accept`
visit_Symbol (sym)
Source

    # File ext/psych/lib/psych/visitors/yaml_tree.rb, line 617
    def visit_Symbol sym
      unless @permitted_classes[Symbol] || @permitted_symbols[sym]
        raise DisallowedClass.new('dump', "Symbol(#{sym.inspect})")
      end

      super
    end

Calls superclass method `Psych::Visitors::YAMLTree#visit_Symbol`