Sha256: 5b8055595d8d59d0abb704ecf38a94d458b6129cf67d0e828398a5e7785bb03b

Contents?: true

Size: 1.36 KB

Versions: 19

Compression:

Stored size: 1.36 KB

Contents

module Fog
  class Model

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

    attr_accessor :connection

    def collection
      @collection
    end

    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
      if data = collection.get(identity)
        new_attributes = data.attributes
        merge_attributes(new_attributes)
        self
      end
    end

    def to_json
      attributes.to_json
    end

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

    private

    def collection=(new_collection)
      @collection = new_collection
    end

  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
fog-0.2.15 lib/fog/model.rb
fog-0.2.14 lib/fog/model.rb
fog-0.2.13 lib/fog/model.rb
fog-0.2.12 lib/fog/model.rb
fog-0.2.11 lib/fog/model.rb
fog-0.2.10 lib/fog/model.rb
fog-0.2.9 lib/fog/model.rb
fog-0.2.8 lib/fog/model.rb
fog-0.2.7 lib/fog/model.rb
fog-0.2.6 lib/fog/model.rb
fog-0.2.5 lib/fog/model.rb
fog-0.2.4 lib/fog/model.rb
fog-0.2.3 lib/fog/model.rb
fog-0.2.2 lib/fog/model.rb
fog-0.2.1 lib/fog/model.rb
fog-0.2.0 lib/fog/model.rb
fog-0.1.10 lib/fog/model.rb
fog-0.1.9 lib/fog/model.rb
fog-0.1.8 lib/fog/model.rb