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.



6
7
8
9
# File 'lib/puppet/pops/serialization/from_data_converter.rb', line 6

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

Instance Method Details

#[](key) ⇒ Object



11
12
13
# File 'lib/puppet/pops/serialization/from_data_converter.rb', line 11

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

#[]=(key, value) ⇒ Object



15
16
17
18
# File 'lib/puppet/pops/serialization/from_data_converter.rb', line 15

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

#resolveObject



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

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