Class: Fog::Model

Inherits:
Object
  • Object
show all
Extended by:
Attributes::ClassMethods
Includes:
Attributes::InstanceMethods
Defined in:
lib/fog/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.



13
14
15
# File 'lib/fog/model.rb', line 13

def initialize(new_attributes = {})
  merge_attributes(new_attributes)
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



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

def connection
  @connection
end

Instance Method Details

#collectionObject



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

def collection
  @collection
end

#inspectObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/model.rb', line 17

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



30
31
32
33
34
35
36
# File 'lib/fog/model.rb', line 30

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

#to_jsonObject



38
39
40
# File 'lib/fog/model.rb', line 38

def to_json
  attributes.to_json
end

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



42
43
44
45
46
47
48
# File 'lib/fog/model.rb', line 42

def wait_for(timeout=600, interval=1, &block)
  reload
  Fog.wait_for(timeout, interval) do
    reload or raise StandardError.new("Reload failed, #{self.class} #{self.identity} went away.")
    instance_eval(&block)
  end
end