Class: Puppet::Pops::Serialization::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/pops/serialization/from_data_converter.rb

Direct Known Subclasses

ObjectArrayBuilder, ObjectHashBuilder

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ Builder

Returns a new instance of Builder


4
5
6
7
# File 'lib/puppet/pops/serialization/from_data_converter.rb', line 4

def initialize(values)
  @values = values
  @resolved = true
end

Instance Method Details

#[](key) ⇒ Object


9
10
11
# File 'lib/puppet/pops/serialization/from_data_converter.rb', line 9

def [](key)
  @values[key]
end

#[]=(key, value) ⇒ Object


13
14
15
16
# File 'lib/puppet/pops/serialization/from_data_converter.rb', line 13

def []=(key, value)
  @values[key] = value
  @resolved = false if value.is_a?(Builder)
end

#resolveObject


18
19
20
21
22
23
24
25
26
27
28
# File 'lib/puppet/pops/serialization/from_data_converter.rb', line 18

def resolve
  unless @resolved
    @resolved = true
    if @values.is_a?(Array)
      @values.each_with_index { |v, idx| @values[idx] = v.resolve if v.is_a?(Builder) }
    elsif @values.is_a?(Hash)
      @values.each_pair { |k, v| @values[k] = v.resolve if v.is_a?(Builder) }
    end
  end
  @values
end