Class: Yao::Resources::Base
Direct Known Subclasses
Aggregates, Amphora, ComputeServices, Flavor, FloatingIP, Host, Hypervisor, Image, Keypair, LoadBalancer, LoadBalancerHealthMonitor, LoadBalancerListener, LoadBalancerPool, LoadBalancerPoolMember, Meter, Network, NetworkingAgents, OldSample, Port, Project, Resource, Role, RoleAssignment, Router, Sample, SecurityGroup, SecurityGroupRule, Server, ServerGroup, Subnet, Tenant, User, Volume, VolumeType
Instance Attribute Summary
#service
Class Method Summary
collapse
Instance Method Summary
collapse
admin=, api_version, api_version=, as_member, client, create, destroy, extended, find_by_name, get, get!, list, resources_path, resources_path=, return_single_on_querying, return_single_on_querying=, update
Constructor Details
#initialize(data_via_json) ⇒ Base
Returns a new instance of Base.
42
43
44
|
# File 'lib/yao/resources/base.rb', line 42
def initialize(data_via_json)
@data = data_via_json
end
|
Class Method Details
.friendly_attributes(*names) ⇒ Object
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/yao/resources/base.rb', line 6
def self.friendly_attributes(*names)
names.map(&:to_s).each do |name|
define_method(name) do
if !@data.key?(name) && id
@data = self.class.get(id)
end
self[name]
end
end
end
|
.map_attribute_to_attribute(k_and_v) ⇒ Object
17
18
19
20
21
22
|
# File 'lib/yao/resources/base.rb', line 17
def self.map_attribute_to_attribute(k_and_v)
as_json, as_method = *k_and_v.to_a.first.map(&:to_s)
define_method(as_method) do
self[as_json]
end
end
|
.map_attribute_to_resource(k_and_v) ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/yao/resources/base.rb', line 24
def self.map_attribute_to_resource(k_and_v)
_name, klass = *k_and_v.to_a.first
name = _name.to_s
define_method(name) do
self[[name, klass].join("__")] ||= klass.new(self[name])
end
end
|
.map_attribute_to_resources(k_and_v) ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/yao/resources/base.rb', line 32
def self.map_attribute_to_resources(k_and_v)
_name, klass = *k_and_v.to_a.first
name = _name.to_s
define_method(name) do
self[[name, klass].join("__")] ||= self[name].map {|d|
klass.new(d)
}
end
end
|
Instance Method Details
#[](name) ⇒ Object
46
47
48
|
# File 'lib/yao/resources/base.rb', line 46
def [](name)
@data[name]
end
|
#[]=(name, value) ⇒ Object
50
51
52
|
# File 'lib/yao/resources/base.rb', line 50
def []=(name, value)
@data[name] = value
end
|
#created ⇒ Object
58
59
60
61
62
|
# File 'lib/yao/resources/base.rb', line 58
def created
if date = self["created"] || self["created_at"]
Time.parse(date)
end
end
|
#id ⇒ Object
54
55
56
|
# File 'lib/yao/resources/base.rb', line 54
def id
self["id"]
end
|
#updated ⇒ Object
64
65
66
67
68
|
# File 'lib/yao/resources/base.rb', line 64
def updated
if date = self["updated"] || self["updated_at"]
Time.parse(date)
end
end
|