Class: Fog::Collection
Direct Known Subclasses
AWS::ELB::Listeners, AWS::ELB::LoadBalancers, AWS::ELB::Policies, AWS::RDS::ParameterGroups, AWS::RDS::Parameters, AWS::RDS::SecurityGroups, AWS::RDS::Servers, AWS::RDS::Snapshots, Fog::Compute::AWS::Addresses, Fog::Compute::AWS::Flavors, Fog::Compute::AWS::Images, Fog::Compute::AWS::KeyPairs, Fog::Compute::AWS::SecurityGroups, Fog::Compute::AWS::Servers, Fog::Compute::AWS::Snapshots, Fog::Compute::AWS::Tags, Fog::Compute::AWS::Volumes, Fog::Compute::Bluebox::Flavors, Fog::Compute::Bluebox::Images, Fog::Compute::Bluebox::Servers, Fog::Compute::Brightbox::CloudIps, Fog::Compute::Brightbox::Flavors, Fog::Compute::Brightbox::Images, Fog::Compute::Brightbox::LoadBalancers, Fog::Compute::Brightbox::Servers, Fog::Compute::Brightbox::Users, Fog::Compute::Brightbox::Zones, Fog::Compute::Ecloud::Vdcs, Fog::Compute::GoGrid::Images, Fog::Compute::GoGrid::Passwords, Fog::Compute::GoGrid::Servers, Fog::Compute::Linode::DataCenters, Fog::Compute::Linode::Disks, Fog::Compute::Linode::Flavors, Fog::Compute::Linode::Images, Fog::Compute::Linode::Ips, Fog::Compute::Linode::Kernels, Fog::Compute::Linode::Servers, Fog::Compute::Linode::StackScripts, Fog::Compute::Ninefold::Addresses, Fog::Compute::Ninefold::Flavors, Fog::Compute::Ninefold::Images, Fog::Compute::Ninefold::IpForwardingRules, Fog::Compute::Ninefold::Servers, Fog::Compute::Rackspace::Flavors, Fog::Compute::Rackspace::Images, Fog::Compute::Rackspace::Servers, Fog::Compute::Slicehost::Flavors, Fog::Compute::Slicehost::Images, Fog::Compute::Slicehost::Servers, Fog::Compute::StormOnDemand::Balancers, Fog::Compute::StormOnDemand::Configs, Fog::Compute::StormOnDemand::Images, Fog::Compute::StormOnDemand::PrivateIps, Fog::Compute::StormOnDemand::Servers, Fog::Compute::StormOnDemand::Stats, Fog::Compute::StormOnDemand::Templates, Fog::Compute::VirtualBox::Mediums, Fog::Compute::VirtualBox::NATRedirects, Fog::Compute::VirtualBox::NetworkAdapters, Fog::Compute::VirtualBox::Servers, Fog::Compute::VirtualBox::StorageControllers, Fog::Compute::Voxel::Images, Fog::Compute::Voxel::Servers, DNS::AWS::Records, DNS::AWS::Zones, DNS::Bluebox::Records, DNS::Bluebox::Zones, DNS::DNSMadeEasy::Records, DNS::DNSMadeEasy::Zones, DNS::DNSimple::Records, DNS::DNSimple::Zones, DNS::Linode::Records, DNS::Linode::Zones, DNS::Slicehost::Records, DNS::Slicehost::Zones, DNS::Zerigo::Records, DNS::Zerigo::Zones, Ecloud::Collection, Storage::AWS::Directories, Storage::AWS::Files, Storage::Google::Directories, Storage::Google::Files, Storage::Local::Directories, Storage::Local::Files, Storage::Rackspace::Directories, Storage::Rackspace::Files, Terremark::Shared::Addresses, Terremark::Shared::Networks, Terremark::Shared::Servers, Terremark::Shared::Tasks, Terremark::Shared::Vdcs
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
_load, aliases, attribute, attributes, identity, ignore_attributes, ignored_attributes
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires
Constructor Details
#initialize(attributes = {}) ⇒ Collection
Returns a new instance of Collection.
54
55
56
57
|
# File 'lib/fog/core/collection.rb', line 54
def initialize(attributes = {})
@loaded = false
merge_attributes(attributes)
end
|
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
40
41
42
|
# File 'lib/fog/core/collection.rb', line 40
def connection
@connection
end
|
Class Method Details
.model(new_model = nil) ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/fog/core/collection.rb', line 32
def self.model(new_model=nil)
if new_model == nil
@model
else
@model = new_model
end
end
|
Instance Method Details
#clear ⇒ Object
43
44
45
46
|
# File 'lib/fog/core/collection.rb', line 43
def clear
@loaded = true
super
end
|
#create(attributes = {}) ⇒ Object
48
49
50
51
52
|
# File 'lib/fog/core/collection.rb', line 48
def create(attributes = {})
object = new(attributes)
object.save
object
end
|
#inspect ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/fog/core/collection.rb', line 60
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
84
85
86
87
88
89
90
|
# File 'lib/fog/core/collection.rb', line 84
def load(objects)
clear
for object in objects
self << new(object)
end
self
end
|
#model ⇒ Object
92
93
94
|
# File 'lib/fog/core/collection.rb', line 92
def model
self.class.instance_variable_get('@model')
end
|
#new(attributes = {}) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/fog/core/collection.rb', line 96
def new(attributes = {})
unless attributes.is_a?(Hash)
raise(ArgumentError.new("Initialization parameters must be an attributes hash, got #{attributes.inspect}"))
end
model.new(
attributes.merge(
:collection => self,
:connection => connection
)
)
end
|
#reload ⇒ Object
108
109
110
111
112
|
# File 'lib/fog/core/collection.rb', line 108
def reload
clear
lazy_load
self
end
|
#table(attributes = nil) ⇒ Object
114
115
116
|
# File 'lib/fog/core/collection.rb', line 114
def table(attributes = nil)
Formatador.display_table(self.map {|instance| instance.attributes}, attributes)
end
|
#to_json ⇒ Object
118
119
120
121
|
# File 'lib/fog/core/collection.rb', line 118
def to_json
require 'json'
self.map {|member| member.attributes}.to_json
end
|