Class: OpenStax::Aws::ResourceFactory
- Inherits:
-
Object
- Object
- OpenStax::Aws::ResourceFactory
- Defined in:
- lib/openstax/aws/resource_factory.rb
Constant Summary collapse
- ALL_TYPES =
All classes listed here should implement the self.physical_resource_id method
{ 'AWS::AutoScaling::AutoScalingGroup' => OpenStax::Aws::AutoScalingGroup, 'AWS::CloudWatch::Alarm' => OpenStax::Aws::Alarm, 'AWS::Events::Rule' => OpenStax::Aws::EventRule, 'AWS::RDS::DBInstance' => OpenStax::Aws::RdsInstance, 'AWS::MSK::Cluster' => OpenStax::Aws::MskCluster }
Instance Attribute Summary collapse
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
- #from_stack_resource_or_summary(stack_resource) ⇒ Object
- #from_stack_resource_or_summary!(stack_resource) ⇒ Object
-
#initialize(region:, types: nil) ⇒ ResourceFactory
constructor
A new instance of ResourceFactory.
Constructor Details
#initialize(region:, types: nil) ⇒ ResourceFactory
Returns a new instance of ResourceFactory.
14 15 16 17 |
# File 'lib/openstax/aws/resource_factory.rb', line 14 def initialize(region:, types: nil) @region = region @types = types.nil? ? ALL_TYPES : ALL_TYPES.select { |type, _| types.include? type } end |
Instance Attribute Details
#region ⇒ Object (readonly)
Returns the value of attribute region.
12 13 14 |
# File 'lib/openstax/aws/resource_factory.rb', line 12 def region @region end |
#types ⇒ Object (readonly)
Returns the value of attribute types.
12 13 14 |
# File 'lib/openstax/aws/resource_factory.rb', line 12 def types @types end |
Instance Method Details
#from_stack_resource_or_summary(stack_resource) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/openstax/aws/resource_factory.rb', line 19 def from_stack_resource_or_summary(stack_resource) klass = types[stack_resource.resource_type] return if klass.nil? klass.new( region: region, klass.physical_resource_id_attribute => stack_resource.physical_resource_id ) end |
#from_stack_resource_or_summary!(stack_resource) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/openstax/aws/resource_factory.rb', line 29 def from_stack_resource_or_summary!(stack_resource) from_stack_resource_or_summary(stack_resource).tap do |resource| raise "'#{stack_resource.resource_type}' is not yet implemented in `ResourceFactory`" \ if resource.nil? end end |