Class: ModelElement
- Inherits:
-
Object
- Object
- ModelElement
- 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
Direct Known Subclasses
AWS::EC2::Instance, AWS::EC2::NetworkInterface, AWS::EC2::SecurityGroup, AWS::EC2::SecurityGroupEgress, AWS::EC2::SecurityGroupIngress, AWS::ElasticLoadBalancing::LoadBalancer, AWS::ElasticLoadBalancingV2::LoadBalancer, AWS::IAM::Group, AWS::IAM::ManagedPolicy, AWS::IAM::Policy, AWS::IAM::Role, AWS::IAM::User, AWS::S3::BucketPolicy, AWS::SNS::TopicPolicy, AWS::SQS::QueuePolicy
Instance Attribute Summary collapse
-
#logical_resource_id ⇒ Object
Returns the value of attribute logical_resource_id.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#resource_type ⇒ Object
Returns the value of attribute resource_type.
Instance Method Summary collapse
- #==(another_model_element) ⇒ Object
-
#initialize(cfn_model) ⇒ ModelElement
constructor
the dreaded two way relationship.
- #to_s ⇒ Object
Constructor Details
#initialize(cfn_model) ⇒ ModelElement
the dreaded two way relationship
55 56 57 58 |
# File 'lib/cfn-model/model/model_element.rb', line 55 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
87 88 89 90 91 92 93 |
# File 'lib/cfn-model/model/model_element.rb', line 87 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_id ⇒ Object
Returns the value of attribute logical_resource_id.
52 53 54 |
# File 'lib/cfn-model/model/model_element.rb', line 52 def logical_resource_id @logical_resource_id end |
#metadata ⇒ Object
Returns the value of attribute metadata.
52 53 54 |
# File 'lib/cfn-model/model/model_element.rb', line 52 def @metadata end |
#resource_type ⇒ Object
Returns the value of attribute resource_type.
52 53 54 |
# File 'lib/cfn-model/model/model_element.rb', line 52 def resource_type @resource_type end |
Instance Method Details
#==(another_model_element) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/cfn-model/model/model_element.rb', line 68 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 ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/cfn-model/model/model_element.rb', line 60 def to_s <<END { #{emit_instance_vars} } END end |