Class: Conjur::Policy::YAML::Handler::Mapping

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

Overview

Handles a mapping, each of which will be parsed into a structured record.

Instance Attribute Summary collapse

Attributes inherited from Base

#parent

Instance Method Summary collapse

Methods inherited from Base

#end_sequence, #handler, #pop_handler, #push_handler, #start_mapping, #start_sequence

Constructor Details

#initialize(parent, type) ⇒ Mapping

Returns a new instance of Mapping.



205
206
207
208
209
# File 'lib/conjur/policy/yaml/handler.rb', line 205

def initialize parent, type
  super parent
  
  @record = type.new
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



203
204
205
# File 'lib/conjur/policy/yaml/handler.rb', line 203

def type
  @type
end

Instance Method Details

#alias(anchor) ⇒ Object

Begins a mapping with the anchor value as the key.



226
227
228
229
230
231
# File 'lib/conjur/policy/yaml/handler.rb', line 226

def alias anchor
  key = handler.anchor(anchor)
  MapEntry.new(self, @record, key).tap do |h|
    h.push_handler
  end.result
end

#end_mappingObject



241
242
243
244
# File 'lib/conjur/policy/yaml/handler.rb', line 241

def end_mapping
  parent.mapping @record
  pop_handler
end

#map_entry(key, value) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
# File 'lib/conjur/policy/yaml/handler.rb', line 213

def map_entry key, value
  if @record.respond_to?(:[]=)
    @record.send(:[]=, key, value)
  else
    begin
      @record.send("#{key}=", value)
    rescue NoMethodError
      raise "No such attribute '#{key}' on type #{@record.class.short_name}"
    end
  end
end

#resultObject



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

def result; @record; end

#scalar(value, tag, quoted) ⇒ Object

Begins a new map entry.



234
235
236
237
238
239
# File 'lib/conjur/policy/yaml/handler.rb', line 234

def scalar value, tag, quoted
  value = scalar_value(value, tag, quoted, type)
  MapEntry.new(self, @record, value).tap do |h|
    h.push_handler
  end.result
end