class Conjur::DSL2::YAML::Handler::Base

An abstract Base handler. The handler will receive each document message within its particular context (sequence, mapping, etc).

The handler can decide that the message is not allowed by not implementing the message.

Attributes

parent[R]

Public Class Methods

new(parent) click to toggle source
# File lib/conjur/dsl2/yaml/handler.rb, line 17
def initialize parent
  @parent = parent
end

Public Instance Methods

alias(anchor) click to toggle source

An alias is encountered in the document. The value may be looked up in the root Handler anchor hash.

# File lib/conjur/dsl2/yaml/handler.rb, line 42
def alias anchor
  raise "Unexpected alias #{anchor}"
end
end_mapping() click to toggle source

End the current mapping. The handler should populate the mapping into the parent handler.

# File lib/conjur/dsl2/yaml/handler.rb, line 64
def end_mapping
  raise "Unexpected end of mapping"
end
end_sequence() click to toggle source

End the current sequence. The handler should populate the sequence into the parent handler.

# File lib/conjur/dsl2/yaml/handler.rb, line 59
def end_sequence
  raise "Unexpected end of sequence"
end
handler() click to toggle source

Handlers are organized in a stack. Each handler can find the root Handler by traversing up the stack.

# File lib/conjur/dsl2/yaml/handler.rb, line 27
def handler
  parent.handler
end
pop_handler() click to toggle source

Pop this handler off the stack, indicating that it’s complete.

# File lib/conjur/dsl2/yaml/handler.rb, line 37
def pop_handler
  handler.pop_handler
end
push_handler() click to toggle source

Push this handler onto the stack.

# File lib/conjur/dsl2/yaml/handler.rb, line 32
def push_handler
  handler.push_handler self
end
result() click to toggle source

Each handler should implement this method to return the result object (which may only be partially constructed). This method is used by the root handler to associate the handler result with an anchor (if applicable).

# File lib/conjur/dsl2/yaml/handler.rb, line 24
def result; raise "Not implemented"; end
scalar(value, tag, quoted) click to toggle source

Process a scalar value. It may be a map key, a map value, or a sequence value. The handler should return a result from this method, so that the root Handler can associate it with an anchor, if any.

# File lib/conjur/dsl2/yaml/handler.rb, line 71
def scalar value, tag, quoted
  raise "Unexpected scalar"
end
start_mapping(tag) click to toggle source

Start a new mapping with the specified tag. If the handler wants to accept the message, it should return a new handler.

# File lib/conjur/dsl2/yaml/handler.rb, line 48
def start_mapping tag
  raise "Unexpected mapping"
end
start_sequence() click to toggle source

Start a new sequence. If the handler wants to accept the message, it should return a new handler.

# File lib/conjur/dsl2/yaml/handler.rb, line 54
def start_sequence
  raise "Unexpected sequence"
end

Protected Instance Methods

scalar_value(value, tag, quoted, record_type) click to toggle source
# File lib/conjur/dsl2/yaml/handler.rb, line 77
def scalar_value value, tag, quoted, record_type
  if type = type_of(tag, record_type)
    type.new.tap do |record|
      record.id = value
    end
  else
    SafeYAML::Transform.to_guessed_type(value, quoted, SafeYAML::OPTIONS)
  end
end
type_of(tag, record_type) click to toggle source
# File lib/conjur/dsl2/yaml/handler.rb, line 87
def type_of tag, record_type
  if tag && tag.match(/!(.*)/)
    type_name = $1.underscore.camelize
    begin
      Conjur::DSL2::Types.const_get(type_name)
    rescue NameError
      raise "Unrecognized data type '#{tag}'"
    end
  else
    record_type
  end
end