Sha256: 9c6659977dcb44b5f3db6f7700ee86b87e16f79f319b7f236a876c9f7e4c3db8

Contents?: true

Size: 1.46 KB

Versions: 8

Compression:

Stored size: 1.46 KB

Contents

module Fog
  class Model

    extend Fog::Attributes::ClassMethods
    include Fog::Attributes::InstanceMethods

    attr_accessor :collection, :connection

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

    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

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

    def to_json
      require 'json'
      attributes.to_json
    end

    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

  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
fog-0.7.2 lib/fog/core/model.rb
fog-0.7.1 lib/fog/core/model.rb
fog-0.7.0 lib/fog/core/model.rb
bbcloud-0.11.2 lib/bbcloud/vendor/fog/lib/fog/core/model.rb
bbcloud-0.11.1 lib/bbcloud/vendor/fog/lib/fog/core/model.rb
bbcloud-0.11.0 lib/bbcloud/vendor/fog/lib/fog/core/model.rb
fog-0.6.0 lib/fog/core/model.rb
fog-0.5.3 lib/fog/core/model.rb