Module: Fog::Attributes::InstanceMethods

Included in:
Collection, Model
Defined in:
lib/fog/attributes.rb

Instance Method Summary collapse

Instance Method Details

#_dumpObject



37
38
39
# File 'lib/fog/attributes.rb', line 37

def _dump
  Marshal.dump(attributes)
end

#attributesObject



41
42
43
44
45
46
47
# File 'lib/fog/attributes.rb', line 41

def attributes
  attributes = {}
  for attribute in self.class.attributes
    attributes[attribute] = send("#{attribute}")
  end
  attributes
end

#identityObject



49
50
51
# File 'lib/fog/attributes.rb', line 49

def identity
  send(self.class.instance_variable_get('@identity'))
end

#identity=(new_identity) ⇒ Object



53
54
55
# File 'lib/fog/attributes.rb', line 53

def identity=(new_identity)
  send("#{self.class.instance_variable_get('@identity')}=", new_identity)
end

#merge_attributes(new_attributes = {}) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/fog/attributes.rb', line 57

def merge_attributes(new_attributes = {})
  for key, value in new_attributes
    if aliased_key = self.class.aliases[key]
      send("#{aliased_key}=", value)
    else
      send("#{key}=", value)
    end
  end
  self
end

#new_record?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/fog/attributes.rb', line 68

def new_record?
  !identity
end

#requires(*args) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fog/attributes.rb', line 72

def requires(*args)
  missing = []
  for arg in [:connection] | args
    missing << arg unless send("#{arg}")
  end
  unless missing.empty?
    if missing.length == 1
      raise(ArgumentError, "#{missing.first} is required for this operation")
    else
      raise(ArgumentError, "#{missing[0...-1].join(", ")} and #{missing[-1]} are required for this operation")
    end
  end
end