Class: Convection::Model::Template::Resource::HashPropertyInstance

Inherits:
PropertyInstance
  • Object
show all
Defined in:
lib/convection/model/template/resource.rb

Overview

Instance of a hash property

Instance Attribute Summary

Attributes inherited from PropertyInstance

#current_value, #property, #resource, #value

Instance Method Summary collapse

Methods inherited from PropertyInstance

#current, #default, #transform, #validate!

Constructor Details

#initialize(*_) ⇒ HashPropertyInstance

Returns a new instance of HashPropertyInstance



205
206
207
208
209
210
# File 'lib/convection/model/template/resource.rb', line 205

def initialize(*_)
  super

  @value = {}
  @current_value = {}
end

Instance Method Details

#renderObject



216
217
218
219
220
221
222
223
224
225
226
# File 'lib/convection/model/template/resource.rb', line 216

def render
  value.keys.each_with_object({}) do |i, memo|
    memo[i] = if value[i].is_a?(Resource)
                value[i].reference
              elsif value[i].respond_to?(:render)
                value[i].render
              else
                value[i]
              end
  end
end

#set(key, new_value) ⇒ Object



212
213
214
# File 'lib/convection/model/template/resource.rb', line 212

def set(key, new_value)
  @value[key] = validate!(transform(new_value))
end