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, ServerMigrate, Subnet, Tenant, User, Volume, VolumeServices, 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, find_next_link, get, get!, list, resources_path, resources_path=, return_single_on_querying, return_single_on_querying=
Constructor Details
#initialize(data_via_json) ⇒ Hash
79
80
81
|
# File 'lib/yao/resources/base.rb', line 79
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
75
|
# 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 = self[name]
Time.parse(time) if time
end
end
end
|
Instance Method Details
#[](name) ⇒ String
85
86
87
88
89
90
|
# File 'lib/yao/resources/base.rb', line 85
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
95
96
97
|
# File 'lib/yao/resources/base.rb', line 95
def []=(name, value)
@data[name] = value
end
|
#destroy ⇒ String
Also known as:
delete
116
117
118
|
# File 'lib/yao/resources/base.rb', line 116
def destroy
self.class.destroy(id)
end
|
#id ⇒ String
105
106
107
|
# File 'lib/yao/resources/base.rb', line 105
def id
self["id"]
end
|
#to_hash ⇒ Hash
100
101
102
|
# File 'lib/yao/resources/base.rb', line 100
def to_hash
@data
end
|
111
112
113
|
# File 'lib/yao/resources/base.rb', line 111
def update(resource_params)
self.class.update(id, resource_params)
end
|