Class: Conjur::Policy::YAML::Handler::Sequence

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

Overview

Handles a sequence. The sequence has: record_type default record type, inferred from the field name on the parent record. args the start_sequence arguments.

Instance Attribute Summary collapse

Attributes inherited from Base

#parent

Instance Method Summary collapse

Methods inherited from Base

#end_mapping, #handler, #pop_handler, #push_handler

Constructor Details

#initialize(parent, record_type) ⇒ Sequence

Returns a new instance of Sequence.



140
141
142
143
144
145
# File 'lib/conjur/policy/yaml/handler.rb', line 140

def initialize parent, record_type
  super parent
  
  @record_type = record_type
  @list = []
end

Instance Attribute Details

#record_typeObject (readonly)

Returns the value of attribute record_type.



138
139
140
# File 'lib/conjur/policy/yaml/handler.rb', line 138

def record_type
  @record_type
end

Instance Method Details

#alias(anchor) ⇒ Object

When the sequence receives an alias, the alias should be mapped to the previously stored value and added to the result list.



161
162
163
# File 'lib/conjur/policy/yaml/handler.rb', line 161

def alias anchor
  @list.push handler.anchor(anchor)
end

#end_sequenceObject



195
196
197
198
# File 'lib/conjur/policy/yaml/handler.rb', line 195

def end_sequence
  parent.sequence @list
  pop_handler
end

#mapping(value) ⇒ Object

Adds a mapping to the sequence.



150
151
152
# File 'lib/conjur/policy/yaml/handler.rb', line 150

def mapping value
  @list.push value
end

#resultObject



147
# File 'lib/conjur/policy/yaml/handler.rb', line 147

def result; @list; end

#scalar(value, tag, quoted) ⇒ Object

When the sequence contains a scalar, the value should be appended to the result.



189
190
191
192
193
# File 'lib/conjur/policy/yaml/handler.rb', line 189

def scalar value, tag, quoted
  scalar_value(value, tag, quoted, record_type).tap do |value|
    @list.push value
  end
end

#sequence(value) ⇒ Object

Adds a sequence to the sequence.



155
156
157
# File 'lib/conjur/policy/yaml/handler.rb', line 155

def sequence value
  @list.push value
end

#start_mapping(tag) ⇒ Object

When the sequence contains a mapping, a new record should be created corresponding to either:

  • The explicit stated type (tag) of the mapping

  • The implicit field type of the sequence

If neither of these is available, it’s an error.



171
172
173
174
175
176
177
178
179
# File 'lib/conjur/policy/yaml/handler.rb', line 171

def start_mapping tag
  if type = type_of(tag, record_type)
    Mapping.new(self, type).tap do |h|
      h.push_handler
    end.result
  else
    raise "No type given or inferred for sequence entry"
  end
end

#start_sequenceObject

Process a sequence within a sequence.



182
183
184
185
186
# File 'lib/conjur/policy/yaml/handler.rb', line 182

def start_sequence
  Sequence.new(self, record_type).tap do |h|
    h.push_handler
  end.result
end