Class: AWS::Core::Resource
- Inherits:
-
Object
- Object
- AWS::Core::Resource
show all
- Includes:
- Cacheable, Model
- Defined in:
- lib/aws/core/resource.rb
Direct Known Subclasses
AutoScaling::Activity, AutoScaling::Group, AutoScaling::Instance, AutoScaling::LaunchConfiguration, AutoScaling::ScalingPolicy, AutoScaling::ScheduledAction, AWS::CloudFormation::Stack, AWS::CloudFormation::StackResource, DynamoDB::Item, DynamoDB::Resource, EC2::Resource, ELB::LoadBalancer, ELB::LoadBalancerPolicy, IAM::Resource, SimpleEmailService::Identity, SimpleWorkflow::Resource
Defined Under Namespace
Classes: Attribute, AttributeProvider, NotFound
Instance Attribute Summary
Attributes included from Model
#config
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Cacheable
included, #retrieve_attribute
Methods included from Model
#client, #config_prefix
Constructor Details
#initialize(*args) ⇒ Resource
Returns a new instance of Resource.
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/aws/core/resource.rb', line 28
def initialize *args
super
options = args.last.is_a?(Hash) ? args.last : {}
options.each_pair do |opt_name,opt_value|
if
self.class.attributes.has_key?(opt_name) and
self.class.attributes[opt_name].static?
then
static_attributes[opt_name] = opt_value
end
end
end
|
Class Method Details
.attribute_providers ⇒ Object
198
199
200
|
# File 'lib/aws/core/resource.rb', line 198
def attribute_providers
@attribute_providers ||= []
end
|
.attribute_providers_for(request_type) ⇒ Object
203
204
205
206
207
|
# File 'lib/aws/core/resource.rb', line 203
def attribute_providers_for request_type
attribute_providers.select do |provider|
provider.request_types.include?(request_type)
end
end
|
.attributes ⇒ Object
191
192
193
194
195
|
# File 'lib/aws/core/resource.rb', line 191
def attributes
@attributes ||= Hash.new do |hash,attr_name|
raise "uknown attribute #{attr_name}"
end
end
|
.define_attribute_type(type_name) ⇒ Object
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/aws/core/resource.rb', line 168
def define_attribute_type type_name
class_eval <<-METHODS
def self.#{type_name}_attributes
@#{type_name}_attributes ||= {}
end
def self.#{type_name}_attribute name, options = {}, &block
attr = attribute(name, options, &block)
#{type_name}_attributes[attr.name] = attr
end
METHODS
end
|
.new_from(request_type, resp_obj, *args) ⇒ Object
184
185
186
187
188
|
# File 'lib/aws/core/resource.rb', line 184
def new_from request_type, resp_obj, *args
resource = new(*args)
resource.send(:cache_static_attributes, request_type, resp_obj)
resource
end
|
Instance Method Details
#attributes_from_response(resp) ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/aws/core/resource.rb', line 123
def attributes_from_response resp
attributes = []
self.class.attribute_providers_for(resp.request_type).each do |provider|
attributes << provider.attributes_from_response(self, resp)
end
attributes.compact!
return nil if attributes.empty?
attributes = attributes.inject({}) {|hash,attribs| hash.merge(attribs) }
attributes.each_pair do |attr_name,value|
if self.class.attributes[attr_name].static?
static_attributes[attr_name] = value
end
end
attributes
end
|
#eql?(other) ⇒ Boolean
Also known as:
==
Returns true if the objects references the same AWS resource.
64
65
66
67
|
# File 'lib/aws/core/resource.rb', line 64
def eql? other
other.kind_of?(self.class) and
other.resource_identifiers == resource_identifiers
end
|
#inspect ⇒ String
Returns a simple string representation of this resource.
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/aws/core/resource.rb', line 47
def inspect
identifiers = []
resource_identifiers.each do |key, value|
if attr = self.class.attributes.values.find{|a| a.get_as == key }
identifiers << "#{attr.name}:#{value}"
else
identifiers << "#{key}:#{value}"
end
end
"<#{self::class} #{identifiers.join(' ')}>"
end
|