Class: SafeYAML::Resolver

### Home Classes Methods

### In Files

- lib/safe_yaml/resolver.rb

### Parent

Object

### Methods

- ::new
- #get_and_check_node_tag
- #options
- #resolve_map
- #resolve_node
- #resolve_scalar
- #resolve_seq
- #tag_is_whitelisted?

### Class/Module Index

Quicksearch

- SafeYAML
- SafeYAML::Deep
- SafeYAML::Parse
- SafeYAML::Parse::Date
- SafeYAML::Parse::Hexadecimal
- SafeYAML::Parse::Sexagesimal
- SafeYAML::PsychHandler
- SafeYAML::PsychResolver
- SafeYAML::Resolver
- SafeYAML::SafeToRubyVisitor
- SafeYAML::SyckResolver
- SafeYAML::Transform
- SafeYAML::Transform::ToBoolean
- SafeYAML::Transform::ToDate
- SafeYAML::Transform::ToFloat
- SafeYAML::Transform::ToInteger
- SafeYAML::Transform::ToNil
- SafeYAML::Transform::ToSymbol
- SafeYAML::Transform::TransformationMap
- SafeYAML::Transform::TransformationMap::CaseAgnosticMap
- SafeYAML::Transform::TransformationMap::ClassMethods
- Object
- YAML

No matching classes.

# SafeYAML::Resolver

### Public Class Methods

new(options) click to toggle source

    # File lib/safe_yaml/resolver.rb, line 3
    def initialize(options)
      @options              = SafeYAML::OPTIONS.merge(options || {})
      @whitelist            = @options[:whitelisted_tags] || []
      @initializers         = @options[:custom_initializers] || {}
      @raise_on_unknown_tag = @options[:raise_on_unknown_tag]
    end

### Public Instance Methods

get_and_check_node_tag(node) click to toggle source

    # File lib/safe_yaml/resolver.rb, line 62
    def get_and_check_node_tag(node)
      tag = self.get_node_tag(node)
      SafeYAML.tag_safety_check!(tag, @options)
      tag
    end

options() click to toggle source

    # File lib/safe_yaml/resolver.rb, line 72
    def options
      @options
    end

resolve_map(node) click to toggle source

    # File lib/safe_yaml/resolver.rb, line 30
    def resolve_map(node)
      tag  = get_and_check_node_tag(node)
      hash = @initializers.include?(tag) ? @initializers[tag].call : {}
      map  = normalize_map(self.get_node_value(node))

      # Take the "<<" key nodes first, as these are meant to approximate a form of inheritance.
      inheritors = map.select { |key_node, value_node| resolve_node(key_node) == "<<" }
      inheritors.each do |key_node, value_node|
        merge_into_hash(hash, resolve_node(value_node))
      end

      # All that's left should be normal (non-"<<") nodes.
      (map - inheritors).each do |key_node, value_node|
        hash[resolve_node(key_node)] = resolve_node(value_node)
      end

      return hash
    end

resolve_node(node) click to toggle source

    # File lib/safe_yaml/resolver.rb, line 10
    def resolve_node(node)
      return node if !node
      return self.native_resolve(node) if tag_is_whitelisted?(self.get_node_tag(node))

      case self.get_node_type(node)
      when :root
        resolve_root(node)
      when :map
        resolve_map(node)
      when :seq
        resolve_seq(node)
      when :scalar
        resolve_scalar(node)
      when :alias
        resolve_alias(node)
      else
        raise "Don't know how to resolve this node: #{node.inspect}"
      end
    end

resolve_scalar(node) click to toggle source

    # File lib/safe_yaml/resolver.rb, line 58
    def resolve_scalar(node)
      Transform.to_proper_type(self.get_node_value(node), self.value_is_quoted?(node), get_and_check_node_tag(node), @options)
    end

resolve_seq(node) click to toggle source

    # File lib/safe_yaml/resolver.rb, line 49
    def resolve_seq(node)
      seq = self.get_node_value(node)

      tag = get_and_check_node_tag(node)
      arr = @initializers.include?(tag) ? @initializers[tag].call : []

      seq.inject(arr) { |array, node| array << resolve_node(node) }
    end

tag_is_whitelisted?(tag) click to toggle source

    # File lib/safe_yaml/resolver.rb, line 68
    def tag_is_whitelisted?(tag)
      @whitelist.include?(tag)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.