Class: Convection::Model::Template::Resource::ListPropertyInstance

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

Overview

Instance of a list 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(*_) ⇒ ListPropertyInstance

Returns a new instance of ListPropertyInstance



253
254
255
256
257
258
# File 'lib/convection/model/template/resource.rb', line 253

def initialize(*_)
  super

  @value = []
  @current_value = []
end

Instance Method Details

#renderObject



270
271
272
273
274
275
276
# File 'lib/convection/model/template/resource.rb', line 270

def render
  return default if value.nil? || value.empty?
  value.map do |val|
    next val.reference if val.is_a?(Resource)
    val.respond_to?(:render) ? val.render : val
  end
end

#set(values) ⇒ Object Also known as: <<, push



260
261
262
263
264
265
266
# File 'lib/convection/model/template/resource.rb', line 260

def set(values)
  values.map! do |new_value|
    validate!(transform(new_value))
  end

  @value.push(*values)
end