Class: Conjur::DSL2::YAML::Handler::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/conjur/dsl2/yaml/handler.rb

Overview

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.

Direct Known Subclasses

MapEntry, Mapping, Root, Sequence

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ Base

Returns a new instance of Base.



17
18
19
# File 'lib/conjur/dsl2/yaml/handler.rb', line 17

def initialize parent
  @parent = parent
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



15
16
17
# File 'lib/conjur/dsl2/yaml/handler.rb', line 15

def parent
  @parent
end

Instance Method Details

#alias(anchor) ⇒ Object

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



42
43
44
# File 'lib/conjur/dsl2/yaml/handler.rb', line 42

def alias anchor
  raise "Unexpected alias #{anchor}"
end

#end_mappingObject

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



64
65
66
# File 'lib/conjur/dsl2/yaml/handler.rb', line 64

def end_mapping
  raise "Unexpected end of mapping"
end

#end_sequenceObject

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



59
60
61
# File 'lib/conjur/dsl2/yaml/handler.rb', line 59

def end_sequence
  raise "Unexpected end of sequence"
end

#handlerObject

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



27
28
29
# File 'lib/conjur/dsl2/yaml/handler.rb', line 27

def handler
  parent.handler
end

#pop_handlerObject

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



37
38
39
# File 'lib/conjur/dsl2/yaml/handler.rb', line 37

def pop_handler
  handler.pop_handler
end

#push_handlerObject

Push this handler onto the stack.



32
33
34
# File 'lib/conjur/dsl2/yaml/handler.rb', line 32

def push_handler
  handler.push_handler self
end

#resultObject

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).



24
# File 'lib/conjur/dsl2/yaml/handler.rb', line 24

def result; raise "Not implemented"; end

#scalar(value, tag, quoted) ⇒ Object

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.



71
72
73
# File 'lib/conjur/dsl2/yaml/handler.rb', line 71

def scalar value, tag, quoted
  raise "Unexpected scalar"
end

#start_mapping(tag) ⇒ Object

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



48
49
50
# File 'lib/conjur/dsl2/yaml/handler.rb', line 48

def start_mapping tag
  raise "Unexpected mapping"
end

#start_sequenceObject

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



54
55
56
# File 'lib/conjur/dsl2/yaml/handler.rb', line 54

def start_sequence
  raise "Unexpected sequence"
end