Class: Fog::Model
- Inherits:
-
Object
show all
- Defined in:
- lib/fog/model.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(new_attributes = {}) ⇒ Model
Returns a new instance of Model.
22
23
24
|
# File 'lib/fog/model.rb', line 22
def initialize(new_attributes = {})
merge_attributes(new_attributes)
end
|
Class Method Details
.aliases ⇒ Object
14
15
16
|
# File 'lib/fog/model.rb', line 14
def self.aliases
@aliases ||= {}
end
|
.attribute(name, other_names = []) ⇒ Object
4
5
6
7
8
9
10
11
12
|
# File 'lib/fog/model.rb', line 4
def self.attribute(name, other_names = [])
class_eval <<-EOS, __FILE__, __LINE__
attr_accessor :#{name}
EOS
attributes << name
for other_name in [*other_names]
aliases[other_name] = name
end
end
|
.attributes ⇒ Object
18
19
20
|
# File 'lib/fog/model.rb', line 18
def self.attributes
@attributes ||= []
end
|
Instance Method Details
#attributes ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/fog/model.rb', line 34
def attributes
attributes = {}
for attribute in self.class.attributes
attributes[attribute] = send(:"#{attribute}")
end
attributes
end
|
#inspect ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/fog/model.rb', line 26
def inspect
data = "#<#{self.class.name}"
for attribute in self.class.attributes
data << " #{attribute}=#{send(attribute).inspect}"
end
data << ">"
end
|
#merge_attributes(new_attributes = {}) ⇒ Object
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/fog/model.rb', line 42
def merge_attributes(new_attributes = {})
for key, value in new_attributes
if aliased_key = self.class.aliases[key]
send(:"#{aliased_key}=", value)
else
send(:"#{key}=", value)
end
end
self
end
|