class CloudFormer::PropertyOrAttribute
Attributes
options[R]
Public Class Methods
new(name, options)
click to toggle source
# File lib/cloud_former/property_or_attribute.rb, line 6 def initialize(name, options) @name = name @options = options end
Public Instance Methods
as_json_for(instance)
click to toggle source
# File lib/cloud_former/property_or_attribute.rb, line 15 def as_json_for(instance) val_as_json(instance.send(get_name)) end
get_name()
click to toggle source
# File lib/cloud_former/property_or_attribute.rb, line 11 def get_name @name end
Private Instance Methods
val_as_json(val)
click to toggle source
# File lib/cloud_former/property_or_attribute.rb, line 21 def val_as_json(val) if val.is_a?(Parameter) || val.is_a?(PseudoParameter) { 'Ref' => val.get_name } elsif val.is_a?(Function) val.dump_json elsif val.is_a?(Resource) || val.is_a?(ResourceProperty) if options[:embed] thing = val.dump_json thing.delete('Type') if options[:skip_properties] props = thing.delete('Properties') props.each do |name, value| thing[name] = value end end thing else if val.get_name.nil? || val.get_name.empty? fail ArgumentError, "Attempting to reference a resource of type #{val.class.name} with no name" end { 'Ref' => val.get_name } end elsif val.is_a?(Hash) mapped_hash = {} val.each do |k, v| mapped_hash[k] = val_as_json(v) end mapped_hash elsif val.is_a?(Array) val.map do |v| val_as_json(v) end else val end end