class Conjur::Policy::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

anchor[R]
parent[R]

Public Class Methods

new(parent, anchor) click to toggle source
# File lib/conjur/policy/yaml/handler.rb, line 17
def initialize parent, anchor
  @parent = parent
  @anchor = anchor
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/policy/yaml/handler.rb, line 38
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/policy/yaml/handler.rb, line 60
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/policy/yaml/handler.rb, line 55
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/policy/yaml/handler.rb, line 23
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/policy/yaml/handler.rb, line 33
def pop_handler
  handler.pop_handler
end
push_handler() click to toggle source

Push this handler onto the stack.

# File lib/conjur/policy/yaml/handler.rb, line 28
def push_handler
  handler.push_handler self
end
scalar(value, tag, quoted, anchor) click to toggle source

Process a scalar value. It may be a map key, a map value, or a sequence value.

# File lib/conjur/policy/yaml/handler.rb, line 65
def scalar value, tag, quoted, anchor
  raise "Unexpected scalar"
end
start_mapping(tag, anchor) 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/policy/yaml/handler.rb, line 44
def start_mapping tag, anchor
  raise "Unexpected mapping"
end
start_sequence(anchor) 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/policy/yaml/handler.rb, line 50
def start_sequence anchor
  raise "Unexpected sequence"
end

Protected Instance Methods

scalar_value(value, tag, quoted, record_type) click to toggle source
# File lib/conjur/policy/yaml/handler.rb, line 71
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/policy/yaml/handler.rb, line 81
def type_of tag, record_type
  if tag && tag.match(/!(.*)/)
    type_name = $1.underscore.camelize
    begin
      Conjur::Policy::Types.const_get(type_name)
    rescue NameError
      raise "Unrecognized data type '#{tag}'"
    end
  else
    record_type
  end
end