Class: Fog::CloudSigma::CloudsigmaModel
- Inherits:
-
Model
- Object
- Model
- Fog::CloudSigma::CloudsigmaModel
show all
- Defined in:
- lib/fog/cloudsigma/nested_model.rb
Direct Known Subclasses
Fog::Compute::CloudSigma::Balance, Fog::Compute::CloudSigma::CurrentUsage, Fog::Compute::CloudSigma::FWPolicy, Fog::Compute::CloudSigma::IP, Fog::Compute::CloudSigma::IPConf, Fog::Compute::CloudSigma::Nic, Fog::Compute::CloudSigma::PriceCalculation, Fog::Compute::CloudSigma::PriceRecord, Fog::Compute::CloudSigma::Pricing, Fog::Compute::CloudSigma::Profile, Fog::Compute::CloudSigma::Rule, Fog::Compute::CloudSigma::Server, Fog::Compute::CloudSigma::Snapshot, Fog::Compute::CloudSigma::Subscription, Fog::Compute::CloudSigma::UsageRecord, Fog::Compute::CloudSigma::VLAN, Fog::Compute::CloudSigma::Volume
Class Method Summary
collapse
Class Method Details
.model_attribute(name, model, options = {}) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/fog/cloudsigma/nested_model.rb', line 28
def model_attribute(name, model, options={})
attributes_key = options[:aliases] || name
class_eval " def \#{name}\n \#{name}_attrs = attributes[:\#{attributes_key}]\n if \#{name}_attrs\n refreshed_\#{name} = \#{name}_attrs ? \#{model}.new(\#{name}_attrs) : nil\n attributes[:\#{attributes_key}] = refreshed_\#{name}.attributes\n\n refreshed_\#{name}\n else\n nil\n end\n end\n def \#{name}=(new_\#{name})\n if new_\#{name}\n attributes[:\#{attributes_key}] = new_\#{name}.kind_of?(Hash) ? new_\#{name} : new_\#{name}.attributes\n else\n nil\n end\n end\n EOS\n\n @attributes ||= []\n @attributes |= [name]\n for new_alias in [*options[:aliases]]\n aliases[new_alias] = name\n end\nend\n", __FILE__, __LINE__
|
.model_attribute_array(name, model, options = {}) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/fog/cloudsigma/nested_model.rb', line 5
def model_attribute_array(name, model, options={})
attributes_key = options[:aliases] || name
class_eval " def \#{name}\n \#{name}_attrs = attributes[:\#{attributes_key}] || []\n refreshed_\#{name} = \#{name}_attrs.map { |x| \#{model}.new(x) }\n attributes[:\#{attributes_key}] = refreshed_\#{name}.map { |x| x.attributes }\n\n refreshed_\#{name}\n end\n def \#{name}=(new_\#{name})\n new_\#{name} ||= []\n attributes[:\#{attributes_key}] = new_\#{name}.map { |x| x.kind_of?(Hash) ? x : x.attributes}\n end\n EOS\n\n @attributes ||= []\n @attributes |= [name]\n for new_alias in [*options[:aliases]]\n aliases[new_alias] = name\n end\nend\n", __FILE__, __LINE__
|