Class: Fog::Model

Inherits:
Object
  • Object
show all
Extended by:
Attributes::ClassMethods
Includes:
Attributes::InstanceMethods
Defined in:
lib/fog/core/model.rb

Direct Known Subclasses

AWS::Compute::Address, AWS::Compute::Flavor, AWS::Compute::Image, AWS::Compute::KeyPair, AWS::Compute::SecurityGroup, AWS::Compute::Server, AWS::Compute::Snapshot, AWS::Compute::Tag, AWS::Compute::Volume, AWS::DNS::Record, AWS::DNS::Zone, AWS::RDS::Parameter, AWS::RDS::ParameterGroup, AWS::RDS::SecurityGroup, AWS::RDS::Server, AWS::RDS::Snapshot, AWS::Storage::Directory, AWS::Storage::File, Bluebox::Compute::Flavor, Bluebox::Compute::Image, Bluebox::Compute::Server, Bluebox::DNS::Record, Bluebox::DNS::Zone, Brightbox::Compute::Account, Brightbox::Compute::CloudIp, Brightbox::Compute::Flavor, Brightbox::Compute::Image, Brightbox::Compute::LoadBalancer, Brightbox::Compute::Server, Brightbox::Compute::User, Brightbox::Compute::Zone, DNSimple::DNS::Record, DNSimple::DNS::Zone, Ecloud::Model, GoGrid::Compute::Image, GoGrid::Compute::Password, GoGrid::Compute::Server, Google::Storage::Directory, Google::Storage::File, Linode::DNS::Record, Linode::DNS::Zone, Local::Storage::Directory, Local::Storage::File, Rackspace::Compute::Flavor, Rackspace::Compute::Image, Rackspace::Compute::Server, Rackspace::Storage::Directory, Rackspace::Storage::File, Slicehost::Compute::Flavor, Slicehost::Compute::Image, Slicehost::Compute::Server, Slicehost::DNS::Record, Slicehost::DNS::Zone, Terremark::Shared::Address, Terremark::Shared::Network, Terremark::Shared::Server, Terremark::Shared::Task, Terremark::Shared::Vdc, VirtualBox::Compute::Medium, VirtualBox::Compute::MediumFormat, VirtualBox::Compute::NATEngine, VirtualBox::Compute::NATRedirect, VirtualBox::Compute::NetworkAdapter, VirtualBox::Compute::Server, VirtualBox::Compute::StorageController, Voxel::Compute::Image, Voxel::Compute::Server, Zerigo::DNS::Record, Zerigo::DNS::Zone

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Attributes::ClassMethods

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

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #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

#collectionObject

Returns the value of attribute collection.



7
8
9
# File 'lib/fog/core/model.rb', line 7

def collection
  @collection
end

#connectionObject

Returns the value of attribute connection.



7
8
9
# File 'lib/fog/core/model.rb', line 7

def connection
  @connection
end

Instance Method Details

#inspectObject



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

#reloadObject



26
27
28
29
30
31
32
33
# File 'lib/fog/core/model.rb', line 26

def reload
  requires :identity
  if data = collection.get(identity)
    new_attributes = data.attributes
    merge_attributes(new_attributes)
    self
  end
end

#to_jsonObject



35
36
37
38
# File 'lib/fog/core/model.rb', line 35

def to_json
  require 'json'
  attributes.to_json
end

#wait_for(timeout = 600, interval = 1, &block) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fog/core/model.rb', line 40

def wait_for(timeout=600, interval=1, &block)
  reload
  Fog.wait_for(timeout, interval) do
    retries = 3
    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