Class: Fog::Model
Instance Attribute Summary collapse
Instance Method Summary
collapse
_load, aliases, associations, attribute, attributes, default_values, has_many, has_many_identities, has_one, has_one_identity, identity, ignore_attributes, ignored_attributes, masks
#connection, #connection=, #prepare_service_value
#_dump, #all_associations, #all_associations_and_attributes, #all_attributes, #associations, #attributes, #dup, #identity, #identity=, #identity_name, #masks, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one
Constructor Details
#initialize(new_attributes = {}) ⇒ Model
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/fog/core/model.rb', line 13
def initialize(new_attributes = {})
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
|
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
10
11
12
|
# File 'lib/fog/core/model.rb', line 10
def collection
@collection
end
|
#service ⇒ Object
Returns the value of attribute service.
11
12
13
|
# File 'lib/fog/core/model.rb', line 11
def service
@service
end
|
Instance Method Details
#==(o) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/fog/core/model.rb', line 32
def ==(o)
unless o.is_a?(Fog::Model)
super
else
if (o.identity.nil? and self.identity.nil?)
o.object_id == self.object_id
else
o.class == self.class and o.identity == self.identity
end
end
end
|
#cache ⇒ Object
24
25
26
|
# File 'lib/fog/core/model.rb', line 24
def cache
Fog::Cache.new(self)
end
|
#reload ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/fog/core/model.rb', line 44
def reload
requires :identity
object = collection.get(identity)
return unless object
merge_attributes(object.all_associations_and_attributes)
self
rescue Excon::Errors::SocketError
nil
end
|
#symbolize_keys(hash) ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/fog/core/model.rb', line 62
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 = {}) ⇒ Object
58
59
60
|
# File 'lib/fog/core/model.rb', line 58
def to_json(_options = {})
Fog::JSON.encode(attributes)
end
|
#wait_for(timeout = Fog.timeout, interval = Fog.interval, &block) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/fog/core/model.rb', line 70
def wait_for(timeout = Fog.timeout, interval = Fog.interval, &block)
reload_has_succeeded = false
duration = Fog.wait_for(timeout, interval) do if reload
reload_has_succeeded = true
instance_eval(&block)
else
false
end
end
if reload_has_succeeded
return duration else
raise Fog::Errors::Error, "Reload failed, #{self.class} #{identity} not present."
end
end
|