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, extended, find_by_name, get, get!, list, resources_path, resources_path=, return_single_on_querying, return_single_on_querying=
Constructor Details
#initialize(data_via_json) ⇒ Hash
78
79
80
|
# File 'lib/yao/resources/base.rb', line 78
def initialize(data_via_json)
@data = data_via_json
end
|
Class Method Details
.add_instantiation_name_list(name) ⇒ Object
8
9
10
11
|
# File 'lib/yao/resources/base.rb', line 8
def self.add_instantiation_name_list(name)
@instantiation_list ||= []
@instantiation_list << name
end
|
.friendly_attributes(*names) ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/yao/resources/base.rb', line 20
def self.friendly_attributes(*names)
names.map(&:to_s).each do |name|
add_instantiation_name_list(name)
define_method(name) do
self[name]
end
end
end
|
.instantiation?(name) ⇒ bool
15
16
17
|
# File 'lib/yao/resources/base.rb', line 15
def self.instantiation?(name)
@instantiation_list.include?(name)
end
|
.map_attribute_to_attribute(k_and_v) ⇒ Symbol
31
32
33
34
35
36
37
|
# File 'lib/yao/resources/base.rb', line 31
def self.map_attribute_to_attribute(k_and_v)
as_json, as_method = *k_and_v.to_a.first.map(&:to_s)
add_instantiation_name_list(as_method)
define_method(as_method) do
self[as_json]
end
end
|
.map_attribute_to_resource(k_and_v) ⇒ Symbol
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/yao/resources/base.rb', line 41
def self.map_attribute_to_resource(k_and_v)
_name, klass = *k_and_v.to_a.first
name = _name.to_s
add_instantiation_name_list(name)
define_method(name) do
unless self[name].empty?
self[[name, klass].join("__")] ||= klass.new(self[name])
end
end
end
|
.map_attribute_to_resources(k_and_v) ⇒ Symbol
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/yao/resources/base.rb', line 54
def self.map_attribute_to_resources(k_and_v)
_name, klass = *k_and_v.to_a.first
name = _name.to_s
add_instantiation_name_list(name)
define_method(name) do
self[[name, klass].join("__")] ||= self[name].map {|d|
klass.new(d)
}
end
end
|
.map_attributes_to_time(*names) ⇒ Symbol
67
68
69
70
71
72
73
74
|
# File 'lib/yao/resources/base.rb', line 67
def self.map_attributes_to_time(*names)
names.map(&:to_s).each do |name|
add_instantiation_name_list(name)
define_method(name) do
Time.parse(self[name])
end
end
end
|
Instance Method Details
#[](name) ⇒ String
84
85
86
87
88
89
|
# File 'lib/yao/resources/base.rb', line 84
def [](name)
if @data["id"] && !@data.key?(name) && self.class.instantiation?(name)
@data = self.class.get(@data["id"]).to_hash
end
@data[name]
end
|
#[]=(name, value) ⇒ String
94
95
96
|
# File 'lib/yao/resources/base.rb', line 94
def []=(name, value)
@data[name] = value
end
|
#destroy ⇒ String
Also known as:
delete
115
116
117
|
# File 'lib/yao/resources/base.rb', line 115
def destroy
self.class.destroy(id)
end
|
#id ⇒ String
104
105
106
|
# File 'lib/yao/resources/base.rb', line 104
def id
self["id"]
end
|
#to_hash ⇒ Hash
99
100
101
|
# File 'lib/yao/resources/base.rb', line 99
def to_hash
@data
end
|
110
111
112
|
# File 'lib/yao/resources/base.rb', line 110
def update(resource_params)
self.class.update(id, resource_params)
end
|