Class: ModelElement

Inherits:
Object
  • Object
show all
Defined in:
lib/cfn-model/model/model_element.rb

Overview

ModelElement is a bit of a misnomer I think.… this is really a Resource, and Parameter and Resource have a lot in common, but are different

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cfn_model) ⇒ ModelElement

the dreaded two way relationship



65
66
67
68
# File 'lib/cfn-model/model/model_element.rb', line 65

def initialize(cfn_model)
  raise 'cfn_model must be specificed' if cfn_model.nil?
  @cfn_model = cfn_model
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object (private)

Treat any missing method as an instance variable get/set

This will allow arbitrary elements in Resource/Properties definitions to map to instance variables without having to anticipate them in a schema



97
98
99
100
101
102
103
# File 'lib/cfn-model/model/model_element.rb', line 97

def method_missing(method_name, *args)
  if method_name =~ /^(\w+)=$/
    instance_variable_set "@#{$1}", args[0]
  else
    References.resolve_value(@cfn_model, instance_variable_get("@#{method_name}"))
  end
end

Instance Attribute Details

#logical_resource_idObject

Returns the value of attribute logical_resource_id.



62
63
64
# File 'lib/cfn-model/model/model_element.rb', line 62

def logical_resource_id
  @logical_resource_id
end

#metadataObject

Returns the value of attribute metadata.



62
63
64
# File 'lib/cfn-model/model/model_element.rb', line 62

def 
  @metadata
end

#resource_typeObject

Returns the value of attribute resource_type.



62
63
64
# File 'lib/cfn-model/model/model_element.rb', line 62

def resource_type
  @resource_type
end

Instance Method Details

#==(another_model_element) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/cfn-model/model/model_element.rb', line 78

def ==(another_model_element)
  found_unequal_instance_var = false
  instance_variables_without_at_sign.each do |instance_variable|
    if instance_variable != :logical_resource_id && instance_variable != :cfn_model
      if self.send(instance_variable) != another_model_element.send(instance_variable)
        found_unequal_instance_var = true
      end
    end
  end
  !found_unequal_instance_var
end

#to_sObject



70
71
72
73
74
75
76
# File 'lib/cfn-model/model/model_element.rb', line 70

def to_s
  <<END
{
#{emit_instance_vars}
}
END
end