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

#anchor, #parent

Instance Method Summary collapse

Methods inherited from Base

#end_mapping, #handler, #pop_handler, #push_handler

Constructor Details

#initialize(parent, anchor, record_type) ⇒ Sequence

Returns a new instance of Sequence.



134
135
136
137
138
139
# File 'lib/conjur/policy/yaml/handler.rb', line 134

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

Instance Attribute Details

#record_typeObject (readonly)

Returns the value of attribute record_type.



132
133
134
# File 'lib/conjur/policy/yaml/handler.rb', line 132

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.



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

def alias anchor
  handler.log { "#{handler.indent}Adding alias *#{anchor} to sequence, whose value is #{handler.anchor(anchor)}" }
  @list.push handler.anchor(anchor)
end

#end_sequenceObject



192
193
194
195
196
# File 'lib/conjur/policy/yaml/handler.rb', line 192

def end_sequence
  parent.sequence @list
  handler.anchor anchor, @list if anchor
  pop_handler
end

#mapping(value) ⇒ Object

Adds a mapping to the sequence.



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

def mapping value
  handler.log { "#{handler.indent}Adding mapping #{value} to sequence" }
  @list.push value
end

#scalar(value, tag, quoted, anchor) ⇒ Object

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



184
185
186
187
188
189
190
# File 'lib/conjur/policy/yaml/handler.rb', line 184

def scalar value, tag, quoted, anchor
  scalar_value(value, tag, quoted, record_type).tap do |value|
    handler.log { "#{handler.indent}Adding scalar *#{value} to sequence" }
    @list.push value
    handler.anchor anchor, value if anchor
  end
end

#sequence(value) ⇒ Object

Adds a sequence to the sequence.



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

def sequence value
  handler.log { "#{handler.indent}Adding sequence #{value} to sequence" }
  @list.push value
end

#start_mapping(tag, anchor) ⇒ 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.



166
167
168
169
170
171
172
173
174
# File 'lib/conjur/policy/yaml/handler.rb', line 166

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

#start_sequence(anchor) ⇒ Object

Process a sequence within a sequence.



177
178
179
180
181
# File 'lib/conjur/policy/yaml/handler.rb', line 177

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