Sha256: 59792a610cb0a478d3d0c8025e89032d50558facad18814bf666cf069d2bbdb6

Contents?: true

Size: 1.38 KB

Versions: 15

Compression:

Stored size: 1.38 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, 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

    private

    def collection=(new_collection)
      @collection = new_collection
    end

  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
fog-0.2.30 lib/fog/model.rb
fog-0.2.28 lib/fog/model.rb
fog-0.2.27 lib/fog/model.rb
fog-0.2.26 lib/fog/model.rb
fog-0.2.25 lib/fog/model.rb
fog-0.2.24 lib/fog/model.rb
tecnh-fog-0.2.23.vpc lib/fog/model.rb
fog-0.2.23 lib/fog/model.rb
fog-0.2.22 lib/fog/model.rb
fog-0.2.21 lib/fog/model.rb
fog-0.2.20 lib/fog/model.rb
fog-0.2.19 lib/fog/model.rb
fog-0.2.18 lib/fog/model.rb
fog-0.2.17 lib/fog/model.rb
fog-0.2.16 lib/fog/model.rb