Class: Fog::Model

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

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
# File 'lib/fog/core/model.rb', line 35

def to_json
  attributes.to_json
end

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



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

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