Class: Fog::Collection

Inherits:
Array
  • Object
show all
Extended by:
Attributes::ClassMethods
Includes:
Attributes::InstanceMethods, Fog::Core::DeprecatedConnectionAccessors
Defined in:
lib/fog/core/collection.rb

Direct Known Subclasses

AWS::AutoScaling::Activities, AWS::AutoScaling::Configurations, AWS::AutoScaling::Groups, AWS::AutoScaling::Instances, AWS::AutoScaling::Policies, AWS::CloudWatch::AlarmData, AWS::CloudWatch::AlarmHistories, AWS::CloudWatch::Alarms, AWS::CloudWatch::MetricStatistics, AWS::CloudWatch::Metrics, AWS::DataPipeline::Pipelines, AWS::ELB::BackendServerDescriptions, 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::Elasticache::SubnetGroups, AWS::Glacier::Archives, AWS::Glacier::Jobs, AWS::Glacier::Vaults, AWS::IAM::AccessKeys, AWS::IAM::Policies, AWS::IAM::Roles, AWS::IAM::Users, AWS::RDS::LogFiles, AWS::RDS::ParameterGroups, AWS::RDS::Parameters, AWS::RDS::SecurityGroups, AWS::RDS::Servers, AWS::RDS::Snapshots, AWS::RDS::SubnetGroups, Account::StormOnDemand::Tokens, Billing::StormOnDemand::Invoices, Billing::StormOnDemand::Payments, Bluebox::BLB::LbApplications, Bluebox::BLB::LbBackends, Bluebox::BLB::LbServices, Fog::CDN::AWS::Distributions, Fog::CDN::AWS::Invalidations, Fog::CDN::AWS::StreamingDistributions, Fog::Compute::AWS::Addresses, Fog::Compute::AWS::DhcpOptions, Fog::Compute::AWS::Flavors, Fog::Compute::AWS::Images, Fog::Compute::AWS::InternetGateways, Fog::Compute::AWS::KeyPairs, Fog::Compute::AWS::NetworkAcls, Fog::Compute::AWS::NetworkInterfaces, Fog::Compute::AWS::RouteTables, 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::Accounts, Fog::Compute::Brightbox::ApiClients, Fog::Compute::Brightbox::Applications, Fog::Compute::Brightbox::CloudIps, Fog::Compute::Brightbox::Collaborations, Fog::Compute::Brightbox::DatabaseServers, Fog::Compute::Brightbox::DatabaseSnapshots, Fog::Compute::Brightbox::DatabaseTypes, 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::UserCollaborations, Fog::Compute::Brightbox::Users, Fog::Compute::Brightbox::Zones, Fog::Compute::Clodo::Images, Fog::Compute::Clodo::Servers, Fog::Compute::CloudSigma::Fwpolicies, Fog::Compute::CloudSigma::Ips, Fog::Compute::CloudSigma::LibVolumes, Fog::Compute::CloudSigma::Servers, Fog::Compute::CloudSigma::Subscriptions, Fog::Compute::CloudSigma::Vlans, Fog::Compute::CloudSigma::Volumes, Fog::Compute::Cloudstack::DiskOfferings, Fog::Compute::Cloudstack::Flavors, Fog::Compute::Cloudstack::Images, Fog::Compute::Cloudstack::Jobs, Fog::Compute::Cloudstack::SecurityGroupRules, Fog::Compute::Cloudstack::SecurityGroups, Fog::Compute::Cloudstack::Servers, Fog::Compute::Cloudstack::Snapshots, Fog::Compute::Cloudstack::Volumes, Fog::Compute::Cloudstack::Zones, Fog::Compute::DigitalOcean::Flavors, Fog::Compute::DigitalOcean::Images, Fog::Compute::DigitalOcean::Regions, Fog::Compute::DigitalOcean::Servers, Fog::Compute::DigitalOcean::SshKeys, 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::Google::Disks, Fog::Compute::Google::Flavors, Fog::Compute::Google::Images, Fog::Compute::Google::Operations, Fog::Compute::Google::Servers, Fog::Compute::Google::Snapshots, Fog::Compute::Google::Zones, Fog::Compute::HP::Addresses, Fog::Compute::HP::Flavors, Fog::Compute::HP::Images, Fog::Compute::HP::KeyPairs, Fog::Compute::HP::Metadata, Fog::Compute::HP::SecurityGroups, Fog::Compute::HP::Servers, Fog::Compute::HPV2::Addresses, Fog::Compute::HPV2::AvailabilityZones, Fog::Compute::HPV2::Flavors, Fog::Compute::HPV2::Images, Fog::Compute::HPV2::KeyPairs, Fog::Compute::HPV2::Metadata, Fog::Compute::HPV2::Servers, Fog::Compute::HPV2::VolumeAttachments, 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::Networks, 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::Addresses, Fog::Compute::OpenStack::Flavors, Fog::Compute::OpenStack::Hosts, Fog::Compute::OpenStack::Images, Fog::Compute::OpenStack::KeyPairs, Fog::Compute::OpenStack::Metadata, Fog::Compute::OpenStack::Networks, Fog::Compute::OpenStack::SecurityGroupRules, Fog::Compute::OpenStack::SecurityGroups, Fog::Compute::OpenStack::Servers, Fog::Compute::OpenStack::Snapshots, Fog::Compute::OpenStack::Tenants, Fog::Compute::OpenStack::Volumes, Fog::Compute::Openvz::Servers, Fog::Compute::Ovirt::Clusters, Fog::Compute::Ovirt::Interfaces, Fog::Compute::Ovirt::Quotas, 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::RackspaceV2::Attachments, Fog::Compute::RackspaceV2::Flavors, Fog::Compute::RackspaceV2::Images, Fog::Compute::RackspaceV2::KeyPairs, Fog::Compute::RackspaceV2::Metadata, Fog::Compute::RackspaceV2::Networks, Fog::Compute::RackspaceV2::Servers, Fog::Compute::Serverlove::Images, Fog::Compute::Serverlove::Servers, Fog::Compute::StormOnDemand::Configs, Fog::Compute::StormOnDemand::Images, Fog::Compute::StormOnDemand::Notifications, Fog::Compute::StormOnDemand::Products, Fog::Compute::StormOnDemand::Servers, Fog::Compute::StormOnDemand::Templates, Fog::Compute::VcloudDirector::Collection, Fog::Compute::Vmfusion::Servers, Fog::Compute::Voxel::Images, Fog::Compute::Voxel::Servers, Fog::Compute::Vsphere::Clusters, Fog::Compute::Vsphere::Customfields, Fog::Compute::Vsphere::Customvalues, Fog::Compute::Vsphere::Datacenters, Fog::Compute::Vsphere::Datastores, Fog::Compute::Vsphere::Folders, Fog::Compute::Vsphere::Interfaces, Fog::Compute::Vsphere::Interfacetypes, Fog::Compute::Vsphere::Networks, Fog::Compute::Vsphere::ResourcePools, Fog::Compute::Vsphere::Servers, Fog::Compute::Vsphere::Servertypes, Fog::Compute::Vsphere::Templates, Fog::Compute::Vsphere::Volumes, Fog::Compute::XenServer::Blobs, Fog::Compute::XenServer::Bonds, Fog::Compute::XenServer::Consoles, Fog::Compute::XenServer::DrTasks, Fog::Compute::XenServer::GpuGroups, Fog::Compute::XenServer::HostCrashDumps, Fog::Compute::XenServer::HostPatchs, Fog::Compute::XenServer::Hosts, Fog::Compute::XenServer::Networks, Fog::Compute::XenServer::Pbds, Fog::Compute::XenServer::Pcis, Fog::Compute::XenServer::Pgpus, Fog::Compute::XenServer::Pifs, Fog::Compute::XenServer::PifsMetrics, Fog::Compute::XenServer::PoolPatchs, Fog::Compute::XenServer::Pools, Fog::Compute::XenServer::Roles, Fog::Compute::XenServer::ServerAppliances, Fog::Compute::XenServer::Servers, Fog::Compute::XenServer::StorageManagers, Fog::Compute::XenServer::StorageRepositories, Fog::Compute::XenServer::Tunnels, Fog::Compute::XenServer::Vbds, Fog::Compute::XenServer::Vdis, Fog::Compute::XenServer::Vifs, Fog::Compute::XenServer::Vlans, Fog::Compute::XenServer::Vmpps, Fog::Compute::XenServer::Vtpms, 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::Dreamhost::Records, DNS::Dreamhost::Zones, DNS::Dynect::Records, DNS::Dynect::Zones, DNS::Linode::Records, DNS::Linode::Zones, DNS::Rackspace::Records, DNS::Rackspace::Zones, DNS::Rage4::Records, DNS::Rage4::Zones, DNS::StormOnDemand::Domains, DNS::StormOnDemand::Records, DNS::StormOnDemand::Reverses, DNS::StormOnDemand::Zones, DNS::Zerigo::Records, DNS::Zerigo::Zones, Ecloud::Collection, HP::BlockStorage::BootableVolumes, HP::BlockStorage::Snapshots, HP::BlockStorage::Volumes, HP::BlockStorageV2::Snapshots, HP::BlockStorageV2::VolumeBackups, HP::BlockStorageV2::Volumes, HP::DNS::Domains, HP::DNS::Records, HP::LB::Algorithms, HP::LB::LoadBalancers, HP::LB::Nodes, HP::LB::Protocols, HP::LB::VirtualIps, HP::Network::FloatingIps, HP::Network::Networks, HP::Network::Ports, HP::Network::Routers, HP::Network::SecurityGroupRules, HP::Network::SecurityGroups, HP::Network::Subnets, Identity::OpenStack::Ec2Credentials, Identity::OpenStack::Roles, Identity::OpenStack::Tenants, Identity::OpenStack::Users, Image::OpenStack::Images, Metering::OpenStack::Resources, Monitoring::StormOnDemand::Bandwidths, Monitoring::StormOnDemand::Loads, Monitoring::StormOnDemand::MonitorServices, Network::OpenStack::FloatingIps, Network::OpenStack::LbHealthMonitors, Network::OpenStack::LbMembers, Network::OpenStack::LbPools, Network::OpenStack::LbVips, Network::OpenStack::Networks, Network::OpenStack::Ports, Network::OpenStack::Routers, Network::OpenStack::SecurityGroupRules, Network::OpenStack::SecurityGroups, Network::OpenStack::Subnets, Network::StormOnDemand::Balancers, Network::StormOnDemand::Firewalls, Network::StormOnDemand::NetworkIPs, Network::StormOnDemand::Pools, Network::StormOnDemand::PrivateIps, Network::StormOnDemand::Rulesets, Network::StormOnDemand::Zones, Orchestration::OpenStack::Stacks, PagedCollection, Rackspace::AutoScale::Groups, Rackspace::AutoScale::Policies, Rackspace::AutoScale::Webhooks, Rackspace::BlockStorage::Snapshots, Rackspace::BlockStorage::VolumeTypes, Rackspace::BlockStorage::Volumes, Rackspace::Databases::Databases, Rackspace::Databases::Flavors, Rackspace::Databases::Instances, Rackspace::Databases::Users, Rackspace::Identity::Credentials, Rackspace::Identity::Roles, Rackspace::Identity::Tenants, Rackspace::Identity::Users, Rackspace::LoadBalancers::AccessRules, Rackspace::LoadBalancers::LoadBalancers, Rackspace::LoadBalancers::Nodes, Rackspace::LoadBalancers::VirtualIps, Rackspace::Monitoring::AgentTokens, Rackspace::Monitoring::AlarmExamples, Rackspace::Monitoring::Alarms, Rackspace::Monitoring::CheckTypes, Rackspace::Monitoring::Checks, Rackspace::Monitoring::DataPoints, Rackspace::Monitoring::Entities, Rackspace::Monitoring::Metrics, Rackspace::Monitoring::Notifications, Rackspace::Queues::Claims, Rackspace::Queues::Messages, Rackspace::Queues::Queues, Storage::AWS::Directories, Storage::AWS::Files, Storage::AWS::Versions, Storage::Atmos::Directories, Storage::Atmos::Files, Storage::Google::Directories, Storage::Google::Files, Storage::HP::Directories, Storage::HP::Files, Storage::HP::Metadata, Storage::HP::SharedDirectories, Storage::HP::SharedFiles, Storage::IBM::Offerings, Storage::IBM::Volumes, Storage::InternetArchive::Directories, Storage::InternetArchive::Files, Storage::Local::Directories, Storage::Local::Files, Storage::OpenStack::Directories, Storage::OpenStack::Files, Storage::Rackspace::Directories, Storage::Rackspace::Files, Storage::StormOnDemand::Clusters, Storage::StormOnDemand::Volumes, Support::StormOnDemand::Alerts, Support::StormOnDemand::Tickets, Terremark::Shared::Addresses, Terremark::Shared::Images, Terremark::Shared::InternetServices, Terremark::Shared::Networks, Terremark::Shared::NodeServices, Terremark::Shared::Servers, Terremark::Shared::Tasks, Terremark::Shared::Vdcs, VPN::StormOnDemand::Vpns, Vcloud::Collection, Volume::OpenStack::VolumeTypes, Volume::OpenStack::Volumes

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Attributes::ClassMethods

_load, aliases, attribute, attributes, identity, ignore_attributes, ignored_attributes

Methods included from Fog::Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

#initialize(attributes = {}) ⇒ Fog::Collection

Creates a new Fog::Collection based around the passed service

Parameters:

  • attributes (Hash) (defaults to: {})

Options Hash (attributes):



67
68
69
70
71
# File 'lib/fog/core/collection.rb', line 67

def initialize(attributes = {})
  @service = attributes.delete(:service)
  @loaded = false
  merge_attributes(attributes)
end

Instance Attribute Details

#serviceObject (readonly)

Returns the value of attribute service.



9
10
11
# File 'lib/fog/core/collection.rb', line 9

def service
  @service
end

Class Method Details

.model(new_model = nil) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/fog/core/collection.rb', line 36

def self.model(new_model=nil)
  if new_model == nil
    @model
  else
    @model = new_model
  end
end

Instance Method Details

#clearObject



44
45
46
47
# File 'lib/fog/core/collection.rb', line 44

def clear
  @loaded = true
  super
end

#create(attributes = {}) ⇒ Object



49
50
51
52
53
# File 'lib/fog/core/collection.rb', line 49

def create(attributes = {})
  object = new(attributes)
  object.save
  object
end

#destroy(identity) ⇒ Object



55
56
57
58
# File 'lib/fog/core/collection.rb', line 55

def destroy(identity)
  object = new(:identity => identity)
  object.destroy
end

#inspectObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/fog/core/collection.rb', line 74

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



98
99
100
101
102
103
104
# File 'lib/fog/core/collection.rb', line 98

def load(objects)
  clear
  for object in objects
    self << new(object)
  end
  self
end

#modelObject



106
107
108
# File 'lib/fog/core/collection.rb', line 106

def model
  self.class.instance_variable_get('@model')
end

#new(attributes = {}) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
# File 'lib/fog/core/collection.rb', line 110

def new(attributes = {})
  unless attributes.is_a?(::Hash)
    raise(ArgumentError.new("Initialization parameters must be an attributes hash, got #{attributes.class} #{attributes.inspect}"))
  end
  model.new(
    {
      :collection => self,
      :service => service
    }.merge(attributes)
  )
end

#reloadObject



122
123
124
125
126
# File 'lib/fog/core/collection.rb', line 122

def reload
  clear
  lazy_load
  self
end

#table(attributes = nil) ⇒ Object



128
129
130
# File 'lib/fog/core/collection.rb', line 128

def table(attributes = nil)
  Formatador.display_table(self.map {|instance| instance.attributes}, attributes)
end

#to_json(options = {}) ⇒ Object



132
133
134
# File 'lib/fog/core/collection.rb', line 132

def to_json(options = {})
  Fog::JSON.encode(self.map {|member| member.attributes})
end