Class: Fog::Collection
Direct Known Subclasses
AWS::AutoScaling::Activities, AWS::AutoScaling::Configurations, AWS::AutoScaling::Groups, AWS::AutoScaling::Instances, AWS::CloudWatch::AlarmData, AWS::CloudWatch::AlarmHistories, AWS::CloudWatch::Alarms, AWS::CloudWatch::MetricStatistics, AWS::CloudWatch::Metrics, AWS::ELB::Listeners, AWS::ELB::LoadBalancers, AWS::ELB::Policies, AWS::ElasticBeanstalk::Applications, AWS::ElasticBeanstalk::Environments, AWS::ElasticBeanstalk::Events, AWS::ElasticBeanstalk::Templates, AWS::ElasticBeanstalk::Versions, AWS::Elasticache::Clusters, AWS::Elasticache::ParameterGroups, AWS::Elasticache::SecurityGroups, 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::NetworkInterfaces, Fog::Compute::AWS::SecurityGroups, Fog::Compute::AWS::Servers, Fog::Compute::AWS::Snapshots, Fog::Compute::AWS::SpotRequests, Fog::Compute::AWS::Subnets, Fog::Compute::AWS::Tags, Fog::Compute::AWS::Volumes, Fog::Compute::AWS::Vpcs, Fog::Compute::Bluebox::Flavors, Fog::Compute::Bluebox::Images, Fog::Compute::Bluebox::Locations, Fog::Compute::Bluebox::Servers, Fog::Compute::Brightbox::CloudIps, Fog::Compute::Brightbox::FirewallPolicies, Fog::Compute::Brightbox::FirewallRules, Fog::Compute::Brightbox::Flavors, Fog::Compute::Brightbox::Images, Fog::Compute::Brightbox::LoadBalancers, Fog::Compute::Brightbox::ServerGroups, Fog::Compute::Brightbox::Servers, Fog::Compute::Brightbox::Users, Fog::Compute::Brightbox::Zones, Fog::Compute::Clodo::Images, Fog::Compute::Clodo::Servers, Fog::Compute::Ecloud::Vdcs, Fog::Compute::Glesys::Ips, Fog::Compute::Glesys::Servers, Fog::Compute::Glesys::Templates, Fog::Compute::GoGrid::Images, Fog::Compute::GoGrid::Passwords, Fog::Compute::GoGrid::Servers, Fog::Compute::IBM::Addresses, Fog::Compute::IBM::Images, Fog::Compute::IBM::InstanceTypes, Fog::Compute::IBM::Keys, Fog::Compute::IBM::Locations, Fog::Compute::IBM::Servers, Fog::Compute::IBM::Vlans, Fog::Compute::Joyent::Flavors, Fog::Compute::Joyent::Images, Fog::Compute::Joyent::Keys, Fog::Compute::Joyent::Servers, Fog::Compute::Joyent::Snapshots, Fog::Compute::Libvirt::Interfaces, Fog::Compute::Libvirt::Networks, Fog::Compute::Libvirt::Nics, Fog::Compute::Libvirt::Nodes, Fog::Compute::Libvirt::Pools, Fog::Compute::Libvirt::Servers, Fog::Compute::Libvirt::Volumes, 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::OpenStack::Flavors, Fog::Compute::OpenStack::Images, Fog::Compute::OpenStack::Metadata, Fog::Compute::OpenStack::Servers, Fog::Compute::Ovirt::Clusters, Fog::Compute::Ovirt::Interfaces, Fog::Compute::Ovirt::Servers, Fog::Compute::Ovirt::Templates, Fog::Compute::Ovirt::Volumes, 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::Vmfusion::Servers, Fog::Compute::Voxel::Images, Fog::Compute::Voxel::Servers, Fog::Compute::Vsphere::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::Dynect::Records, DNS::Dynect::Zones, DNS::Linode::Records, DNS::Linode::Zones, DNS::Rackspace::Records, DNS::Rackspace::Zones, DNS::Slicehost::Records, DNS::Slicehost::Zones, DNS::Zerigo::Records, DNS::Zerigo::Zones, Ecloud::Collection, Rackspace::LoadBalancers::AccessRules, Rackspace::LoadBalancers::LoadBalancers, Rackspace::LoadBalancers::Nodes, Rackspace::LoadBalancers::VirtualIps, Storage::AWS::Directories, Storage::AWS::Files, Storage::AWS::Versions, Storage::Google::Directories, Storage::Google::Files, Storage::IBM::Offerings, Storage::IBM::Volumes, Storage::Local::Directories, Storage::Local::Files, Storage::Ninefold::Directories, Storage::Ninefold::Files, Storage::Rackspace::Directories, Storage::Rackspace::Files, 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, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one
Constructor Details
#initialize(attributes = {}) ⇒ Collection
Returns a new instance of Collection.
59
60
61
62
|
# File 'lib/fog/core/collection.rb', line 59
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
|
#destroy(identity) ⇒ Object
54
55
56
57
|
# File 'lib/fog/core/collection.rb', line 54
def destroy(identity)
object = new(:identity => identity)
object.destroy
end
|
#inspect ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/fog/core/collection.rb', line 65
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
89
90
91
92
93
94
95
|
# File 'lib/fog/core/collection.rb', line 89
def load(objects)
clear
for object in objects
self << new(object)
end
self
end
|
#model ⇒ Object
97
98
99
|
# File 'lib/fog/core/collection.rb', line 97
def model
self.class.instance_variable_get('@model')
end
|
#new(attributes = {}) ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/fog/core/collection.rb', line 101
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
113
114
115
116
117
|
# File 'lib/fog/core/collection.rb', line 113
def reload
clear
lazy_load
self
end
|
#table(attributes = nil) ⇒ Object
119
120
121
|
# File 'lib/fog/core/collection.rb', line 119
def table(attributes = nil)
Formatador.display_table(self.map {|instance| instance.attributes}, attributes)
end
|
#to_json(options = {}) ⇒ Object
123
124
125
126
|
# File 'lib/fog/core/collection.rb', line 123
def to_json(options = {})
require 'multi_json'
MultiJson.encode(self.map {|member| member.attributes})
end
|