Class: Fog::Model
- Inherits:
-
Object
- Object
- Fog::Model
- Extended by:
- Attributes::ClassMethods
- Includes:
- Attributes::InstanceMethods
- Defined in:
- lib/fog/core/model.rb
Direct Known Subclasses
AWS::ELB::Listener, AWS::ELB::LoadBalancer, AWS::ELB::Policy, AWS::RDS::Parameter, AWS::RDS::ParameterGroup, AWS::RDS::SecurityGroup, AWS::RDS::Server, AWS::RDS::Snapshot, Compute::AWS::Address, Compute::AWS::Flavor, Compute::AWS::Image, Compute::AWS::KeyPair, Compute::AWS::SecurityGroup, Compute::AWS::Server, Compute::AWS::Snapshot, Compute::AWS::Tag, Compute::AWS::Volume, Compute::Bluebox::Flavor, Compute::Bluebox::Image, Compute::Bluebox::Server, Compute::Brightbox::Account, Compute::Brightbox::CloudIp, Compute::Brightbox::Flavor, Compute::Brightbox::Image, Compute::Brightbox::LoadBalancer, Compute::Brightbox::Server, Compute::Brightbox::User, Compute::Brightbox::Zone, Compute::GoGrid::Image, Compute::GoGrid::Password, Compute::GoGrid::Server, Compute::Linode::DataCenter, Compute::Linode::Disk, Compute::Linode::Flavor, Compute::Linode::Image, Compute::Linode::Ip, Compute::Linode::Kernel, Compute::Linode::Server, Compute::Linode::StackScript, Compute::Ninefold::Address, Compute::Ninefold::Flavor, Compute::Ninefold::Image, Compute::Ninefold::IpForwardingRule, Compute::Ninefold::Server, Compute::Rackspace::Flavor, Compute::Rackspace::Image, Compute::Rackspace::Server, Compute::Slicehost::Flavor, Compute::Slicehost::Image, Compute::Slicehost::Server, Compute::StormOnDemand::Balancer, Compute::StormOnDemand::Config, Compute::StormOnDemand::Image, Compute::StormOnDemand::PrivateIp, Compute::StormOnDemand::Server, Compute::StormOnDemand::Stat, Compute::StormOnDemand::Template, Compute::VirtualBox::Medium, Compute::VirtualBox::MediumFormat, Compute::VirtualBox::NATEngine, Compute::VirtualBox::NATRedirect, Compute::VirtualBox::NetworkAdapter, Compute::VirtualBox::Server, Compute::VirtualBox::StorageController, Compute::Voxel::Image, Compute::Voxel::Server, DNS::AWS::Record, DNS::AWS::Zone, DNS::Bluebox::Record, DNS::Bluebox::Zone, DNS::DNSMadeEasy::Record, DNS::DNSMadeEasy::Zone, DNS::DNSimple::Record, DNS::DNSimple::Zone, DNS::Linode::Record, DNS::Linode::Zone, DNS::Slicehost::Record, DNS::Slicehost::Zone, DNS::Zerigo::Record, DNS::Zerigo::Zone, Ecloud::Model, Storage::AWS::Directory, Storage::AWS::File, Storage::Google::Directory, Storage::Google::File, Storage::Local::Directory, Storage::Local::File, Storage::Rackspace::Directory, Storage::Rackspace::File, Terremark::Shared::Address, Terremark::Shared::Network, Terremark::Shared::Server, Terremark::Shared::Task, Terremark::Shared::Vdc
Instance Attribute Summary collapse
-
#collection ⇒ Object
Returns the value of attribute collection.
-
#connection ⇒ Object
Returns the value of attribute connection.
Instance Method Summary collapse
-
#initialize(new_attributes = {}) ⇒ Model
constructor
A new instance of Model.
- #inspect ⇒ Object
- #reload ⇒ Object
- #to_json ⇒ Object
- #wait_for(timeout = 600, interval = 1, &block) ⇒ Object
Methods included from Attributes::ClassMethods
_load, aliases, attribute, attributes, identity, ignore_attributes, ignored_attributes
Methods included from Attributes::InstanceMethods
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires
Constructor Details
#initialize(new_attributes = {}) ⇒ Model
Returns a new instance of Model.
9 10 11 |
# File 'lib/fog/core/model.rb', line 9 def initialize(new_attributes = {}) merge_attributes(new_attributes) end |
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
7 8 9 |
# File 'lib/fog/core/model.rb', line 7 def collection @collection end |
#connection ⇒ Object
Returns the value of attribute connection.
7 8 9 |
# File 'lib/fog/core/model.rb', line 7 def connection @connection end |
Instance Method Details
#inspect ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fog/core/model.rb', line 13 def inspect Thread.current[:formatador] ||= Formatador.new data = "#{Thread.current[:formatador].indentation}<#{self.class.name}" Thread.current[:formatador].indent do unless self.class.attributes.empty? data << "\n#{Thread.current[:formatador].indentation}" data << self.class.attributes.map {|attribute| "#{attribute}=#{send(attribute).inspect}"}.join(",\n#{Thread.current[:formatador].indentation}") end end data << "\n#{Thread.current[:formatador].indentation}>" data end |
#reload ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fog/core/model.rb', line 26 def reload requires :identity return unless data = begin collection.get(identity) rescue Excon::Errors::SocketError nil end new_attributes = data.attributes merge_attributes(new_attributes) self end |
#to_json ⇒ Object
40 41 42 43 |
# File 'lib/fog/core/model.rb', line 40 def to_json require 'json' attributes.to_json end |
#wait_for(timeout = 600, interval = 1, &block) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fog/core/model.rb', line 45 def wait_for(timeout=600, interval=1, &block) reload retries = 3 Fog.wait_for(timeout, interval) do if reload retries = 3 elsif retries > 0 retries -= 1 sleep(1) elsif retries == 0 raise Fog::Errors::Error.new("Reload failed, #{self.class} #{self.identity} went away.") end instance_eval(&block) end end |