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::ApiGateway::Deployment, AWS::ApiGateway::Stage, AWS::EC2::Instance, AWS::EC2::NetworkAcl, AWS::EC2::NetworkAclEntry, 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::KMS::Key, AWS::Lambda::Function, 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
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_id ⇒ Object
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 |
#metadata ⇒ Object
Returns the value of attribute metadata.
62 63 64 |
# File 'lib/cfn-model/model/model_element.rb', line 62 def @metadata end |
#resource_type ⇒ Object
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_s ⇒ Object
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 |