class Fog::Model
Attributes
collection[RW]
service[R]
Public Class Methods
new(new_attributes = {})
click to toggle source
# File lib/fog/core/model.rb, line 12 def initialize(new_attributes = {}) # TODO: Remove compatibility with old connection option attribs = new_attributes.clone @service = attribs.delete(:service) if @service.nil? && attribs[:connection] Fog::Logger.deprecation("Passing :connection option is deprecated, use :service instead [light_black](#{caller.first})[/]") @service = attribs[:connection] end merge_attributes(attribs) end
Public Instance Methods
inspect()
click to toggle source
# File lib/fog/core/model.rb, line 23 def inspect Fog::Formatador.format(self) end
reload()
click to toggle source
# File lib/fog/core/model.rb, line 27 def reload requires :identity data = begin collection.get(identity) rescue Excon::Errors::SocketError nil end return unless data new_attributes = data.attributes merge_attributes(new_attributes) self end
symbolize_keys(hash)
click to toggle source
# File lib/fog/core/model.rb, line 47 def symbolize_keys(hash) return nil if hash.nil? hash.reduce({}) do |options, (key, value)| options[(key.to_sym rescue key) || key] = value options end end
to_json(_options = {})
click to toggle source
# File lib/fog/core/model.rb, line 43 def to_json(_options = {}) Fog::JSON.encode(attributes) end
wait_for(timeout = Fog.timeout, interval = 1, &block)
click to toggle source
# File lib/fog/core/model.rb, line 55 def wait_for(timeout = Fog.timeout, interval = 1, &block) reload_has_succeeded = false duration = Fog.wait_for(timeout, interval) do # Note that duration = false if it times out if reload reload_has_succeeded = true instance_eval(&block) else false end end if reload_has_succeeded return duration # false if timeout; otherwise {:duration => elapsed time } else raise Fog::Errors::Error, "Reload failed, #{self.class} #{identity} not present." end end