class ModelElement
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
Attributes
logical_resource_id[RW]
metadata[RW]
resource_type[RW]
Public Class Methods
new(cfn_model)
click to toggle source
the dreaded two way relationship
# 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
Public Instance Methods
==(another_model_element)
click to toggle source
# 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_s()
click to toggle source
# File lib/cfn-model/model/model_element.rb, line 70 def to_s <<END { #{emit_instance_vars} } END end
Private Instance Methods
emit_instance_vars()
click to toggle source
# File lib/cfn-model/model/model_element.rb, line 113 def emit_instance_vars instance_vars_str = '' self.instance_variables.each do |instance_variable| instance_vars_str += " #{instance_variable}=#{instance_variable_get(instance_variable)}\n" end instance_vars_str end
instance_variables_without_at_sign()
click to toggle source
# File lib/cfn-model/model/model_element.rb, line 105 def instance_variables_without_at_sign self.instance_variables.map { |instance_variable| strip(instance_variable) } end
method_missing(method_name, *args)
click to toggle source
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
# 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
strip(sym)
click to toggle source
# File lib/cfn-model/model/model_element.rb, line 109 def strip(sym) sym.to_s.gsub(/@/, '').to_sym end