Class: ModelElement

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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



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

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

Instance Attribute Details

#logical_resource_idObject

Returns the value of attribute logical_resource_id.



49
50
51
# File 'lib/cfn-model/model/model_element.rb', line 49

def logical_resource_id
  @logical_resource_id
end

#resource_typeObject

Returns the value of attribute resource_type.



49
50
51
# File 'lib/cfn-model/model/model_element.rb', line 49

def resource_type
  @resource_type
end

Instance Method Details

#==(another_model_element) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cfn-model/model/model_element.rb', line 59

def ==(another_model_element)
  found_unequal_instance_var = false
  instance_variables_without_at_sign.each do |instance_variable|
    if instance_variable != :logical_resource_id
      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



51
52
53
54
55
56
57
# File 'lib/cfn-model/model/model_element.rb', line 51

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