Class: Fog::Collection
- Inherits:
-
Array
- Object
- Array
- Fog::Collection
show all
- Defined in:
- lib/fog/collection.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attributes = {}) ⇒ Collection
Returns a new instance of Collection.
22
23
24
|
# File 'lib/fog/collection.rb', line 22
def initialize(attributes = {})
merge_attributes(attributes)
end
|
Class Method Details
.aliases ⇒ Object
14
15
16
|
# File 'lib/fog/collection.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/collection.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/collection.rb', line 18
def self.attributes
@attributes ||= []
end
|
Instance Method Details
#attributes ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/fog/collection.rb', line 39
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
33
34
35
36
37
|
# File 'lib/fog/collection.rb', line 26
def inspect
data = "#<#{self.class.name}"
for attribute in self.class.attributes
data << " #{attribute}=#{send(attribute).inspect}"
end
data << " ["
for member in self
data << "#{member.inspect},"
end
data.chop!
data << "]>"
end
|
#merge_attributes(new_attributes = {}) ⇒ Object
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/fog/collection.rb', line 47
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
|