Class: Fog::Collection
Direct Known Subclasses
AWS::Compute::Addresses, AWS::Compute::Flavors, AWS::Compute::Images, AWS::Compute::KeyPairs, AWS::Compute::SecurityGroups, AWS::Compute::Servers, AWS::Compute::Snapshots, AWS::Compute::Tags, AWS::Compute::Volumes, AWS::Storage::Directories, AWS::Storage::Files, Bluebox::Compute::Flavors, Bluebox::Compute::Images, Bluebox::Compute::Servers, GoGrid::Compute::Images, GoGrid::Compute::Servers, Google::Storage::Directories, Google::Storage::Files, Local::Storage::Directories, Local::Storage::Files, Rackspace::Compute::Flavors, Rackspace::Compute::Images, Rackspace::Compute::Servers, Rackspace::Storage::Directories, Rackspace::Storage::Files, Slicehost::Compute::Flavors, Slicehost::Compute::Images, Slicehost::Compute::Servers, Terremark::Shared::Addresses, Terremark::Shared::Networks, Terremark::Shared::Servers, Terremark::Shared::Tasks, Terremark::Shared::Vdcs, Vcloud::Collection
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
_load, aliases, attribute, attributes, identity, ignore_attributes, ignored_attributes
#_dump, #attributes, #identity, #identity=, #merge_attributes, #new_record?, #requires
Constructor Details
#initialize(attributes = {}) ⇒ Collection
Returns a new instance of Collection.
53
54
55
56
|
# File 'lib/fog/core/collection.rb', line 53
def initialize(attributes = {})
@loaded = false
merge_attributes(attributes)
end
|
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
39
40
41
|
# File 'lib/fog/core/collection.rb', line 39
def connection
@connection
end
|
Class Method Details
.model(new_model = nil) ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/fog/core/collection.rb', line 31
def self.model(new_model=nil)
if new_model == nil
@model
else
@model = new_model
end
end
|
Instance Method Details
#clear ⇒ Object
42
43
44
45
|
# File 'lib/fog/core/collection.rb', line 42
def clear
@loaded = true
super
end
|
#create(attributes = {}) ⇒ Object
47
48
49
50
51
|
# File 'lib/fog/core/collection.rb', line 47
def create(attributes = {})
object = new(attributes)
object.save
object
end
|
#inspect ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/fog/core/collection.rb', line 59
def inspect
Thread.current[:formatador] ||= Formatador.new
data = "#{Thread.current[:formatador].indentation}<#{self.class.name}\n"
Thread.current[:formatador].indent do
unless self.class.attributes.empty?
data << "#{Thread.current[:formatador].indentation}"
data << self.class.attributes.map {|attribute| "#{attribute}=#{send(attribute).inspect}"}.join(",\n#{Thread.current[:formatador].indentation}")
data << "\n"
end
data << "#{Thread.current[:formatador].indentation}["
unless self.empty?
data << "\n"
Thread.current[:formatador].indent do
data << self.map {|member| member.inspect}.join(",\n")
data << "\n"
end
data << Thread.current[:formatador].indentation
end
data << "]\n"
end
data << "#{Thread.current[:formatador].indentation}>"
data
end
|
#load(objects) ⇒ Object
83
84
85
86
87
88
89
|
# File 'lib/fog/core/collection.rb', line 83
def load(objects)
clear
for object in objects
self << new(object)
end
self
end
|
#model ⇒ Object
91
92
93
|
# File 'lib/fog/core/collection.rb', line 91
def model
self.class.instance_variable_get('@model')
end
|
#new(attributes = {}) ⇒ Object
95
96
97
98
99
100
101
102
|
# File 'lib/fog/core/collection.rb', line 95
def new(attributes = {})
model.new(
attributes.merge(
:collection => self,
:connection => connection
)
)
end
|
#reload ⇒ Object
104
105
106
107
108
|
# File 'lib/fog/core/collection.rb', line 104
def reload
clear
lazy_load
self
end
|
#table(attributes = nil) ⇒ Object
110
111
112
|
# File 'lib/fog/core/collection.rb', line 110
def table(attributes = nil)
Formatador.display_table(self.map {|instance| instance.attributes}, attributes)
end
|
#to_json ⇒ Object
114
115
116
|
# File 'lib/fog/core/collection.rb', line 114
def to_json
self.map {|member| member.attributes}.to_json
end
|