class Conjur::DSL2::YAML::Handler

Attributes

filename[RW]
parser[RW]
result[RW]

Public Class Methods

new() click to toggle source
# File lib/conjur/dsl2/yaml/handler.rb, line 308
def initialize
  @root = Root.new self
  @handlers = [ @root ]
  @anchors = {}
  @filename = "<no-filename>"
end

Public Instance Methods

alias(key) click to toggle source
# File lib/conjur/dsl2/yaml/handler.rb, line 345
def alias key
  log {"#{indent}anchor '#{key}'=#{anchor(key)}"}
  handler.alias key
end
anchor(*args) click to toggle source

Get or set an anchor. Invoke with just the anchor name to get the value. Invoke with the anchor name and value to set the value.

# File lib/conjur/dsl2/yaml/handler.rb, line 327
def anchor *args
  key, value, _ = args
  if _
    raise ArgumentError, "Expecting 1 or 2 arguments, got #{args.length}"
  elsif key && value
    raise "Duplicate anchor #{key}" if @anchors[key]
    @anchors[key] = value
  elsif key
    @anchors[key]
  else
    nil
  end
end
end_mapping() click to toggle source
# File lib/conjur/dsl2/yaml/handler.rb, line 369
def end_mapping
  log {"#{indent}end mapping"}
  handler.end_mapping
end
end_sequence() click to toggle source
# File lib/conjur/dsl2/yaml/handler.rb, line 364
def end_sequence
  log {"#{indent}end sequence"}
  handler.end_sequence
end
handler() click to toggle source
# File lib/conjur/dsl2/yaml/handler.rb, line 343
def handler; @handlers.last; end
indent() click to toggle source
# File lib/conjur/dsl2/yaml/handler.rb, line 388
def indent
  "  " * [ @handlers.length - 1, 0 ].max
end
log() { || ... } click to toggle source
# File lib/conjur/dsl2/yaml/handler.rb, line 382
def log &block
  logger.debug('conjur/dsl2/handler') {
    yield
  }
end
pop_handler() click to toggle source
# File lib/conjur/dsl2/yaml/handler.rb, line 320
def pop_handler
  @handlers.pop
  log {"#{indent}popped to handler #{handler.class}"}
end
push_handler(handler) click to toggle source
# File lib/conjur/dsl2/yaml/handler.rb, line 315
def push_handler handler
  log {"#{indent}pushing handler #{handler.class}"}
  @handlers.push handler
end
scalar(*args) click to toggle source
# File lib/conjur/dsl2/yaml/handler.rb, line 374
def scalar *args
  # value, anchor, tag, plain, quoted, style
  value, anchor, tag, _, quoted = args
  log {"#{indent}got scalar #{tag ? tag + '=' : ''}#{value}#{anchor ? '#' + anchor : ''}"}
  value = handler.scalar value, tag, quoted
  anchor anchor, value
end
start_mapping(*args) click to toggle source
# File lib/conjur/dsl2/yaml/handler.rb, line 350
def start_mapping *args
  log {"#{indent}start mapping #{args}"}
  anchor, tag, _ = args
  value = handler.start_mapping tag
  anchor anchor, value
end
start_sequence(*args) click to toggle source
# File lib/conjur/dsl2/yaml/handler.rb, line 357
def start_sequence *args
  log {"#{indent}start sequence : #{args}"}
  anchor, _ = args
  value = handler.start_sequence
  anchor anchor, value
end