Module: Fog::Attributes::InstanceMethods

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

Instance Method Summary collapse

Instance Method Details

#_dump(level) ⇒ Object



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

def _dump(level)
  Marshal.dump(attributes)
end

#attributesObject



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

def attributes
  @attributes ||= {}
end

#dupObject



57
58
59
60
61
# File 'lib/fog/core/attributes.rb', line 57

def dup
  copy = super
  copy.dup_attributes!
  copy
end

#identityObject



63
64
65
# File 'lib/fog/core/attributes.rb', line 63

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

#identity=(new_identity) ⇒ Object



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

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

#merge_attributes(new_attributes = {}) ⇒ Object



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

def merge_attributes(new_attributes = {})
  for key, value in new_attributes
    unless self.class.ignored_attributes.include?(key)
      if aliased_key = self.class.aliases[key]
        send("#{aliased_key}=", value)
      elsif self.respond_to?("#{key}=",true)
        send("#{key}=", value)
      else
        attributes[key] = value
      end
    end
  end
  self
end

#new_record?Boolean

Deprecated.

Use inverted form of #persisted?

Returns true if a remote resource has not been assigned an identity.

This was added for a ActiveRecord like feel but has been outdated by ActiveModel API using #persisted?

Returns:



102
103
104
105
# File 'lib/fog/core/attributes.rb', line 102

def new_record?
  Fog::Logger.deprecation("#new_record? is deprecated, use !persisted? instead [light_black](#{caller.first})[/]")
  !persisted?
end

#persisted?Boolean

Returns true if a remote resource has been assigned an identity and we can assume it has been persisted.

Returns:



90
91
92
# File 'lib/fog/core/attributes.rb', line 90

def persisted?
  !!identity
end

#requires(*args) ⇒ Object

check that the attributes specified in args exist and is not nil



108
109
110
111
112
113
114
115
# File 'lib/fog/core/attributes.rb', line 108

def requires(*args)
  missing = missing_attributes(args)
  if missing.length == 1
    raise(ArgumentError, "#{missing.first} is required for this operation")
  elsif missing.any?
    raise(ArgumentError, "#{missing[0...-1].join(", ")} and #{missing[-1]} are required for this operation")
  end
end

#requires_one(*args) ⇒ Object



117
118
119
120
121
122
# File 'lib/fog/core/attributes.rb', line 117

def requires_one(*args)
  missing = missing_attributes(args)
  if missing.length == args.length
    raise(ArgumentError, "#{missing[0...-1].join(", ")} or #{missing[-1]} are required for this operation")
  end
end