Class: ApigeePlatform::CustomAttributes
- Inherits:
-
Object
- Object
- ApigeePlatform::CustomAttributes
show all
- Defined in:
- lib/apigee-platform/custom_attributes.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of CustomAttributes.
4
5
6
7
8
|
# File 'lib/apigee-platform/custom_attributes.rb', line 4
def initialize(obj)
@object = obj
@object.attributes['attributes'] ||= []
@attributes = @object.attributes['attributes'].inject({}.with_indifferent_access){|res, a| res[a['name']] = a['value']; res}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
25
26
27
|
# File 'lib/apigee-platform/custom_attributes.rb', line 25
def method_missing(name)
@attributes.send(name)
end
|
Instance Method Details
#[](key) ⇒ Object
10
11
12
|
# File 'lib/apigee-platform/custom_attributes.rb', line 10
def [](key)
@attributes[key.to_s]
end
|
#[]=(key, value) ⇒ Object
14
15
16
17
18
|
# File 'lib/apigee-platform/custom_attributes.rb', line 14
def []=(key, value)
delete(key.to_s)
@object.attributes['attributes'] << {'name' => key.to_s, 'value' => value}
@attributes[key.to_s] = value
end
|
#delete(key) ⇒ Object
20
21
22
23
|
# File 'lib/apigee-platform/custom_attributes.rb', line 20
def delete(key)
@object.attributes['attributes'].reject!{|a| a['name'] == key.to_s}
@attributes.delete(key.to_s)
end
|
#inspect ⇒ Object
29
30
31
|
# File 'lib/apigee-platform/custom_attributes.rb', line 29
def inspect
@attributes.inspect
end
|