Module: Dinamo::Model::Attributes
- Extended by:
- ActiveSupport::Concern
- Included in:
- Dinamo::Model
- Defined in:
- lib/dinamo/model/attributes.rb
Defined Under Namespace
Modules: ClassMethods
Classes: Key
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
99
100
101
|
# File 'lib/dinamo/model/attributes.rb', line 99
def attributes
@attributes
end
|
Instance Method Details
#==(other) ⇒ Object
Also known as:
equal?
134
135
136
137
|
# File 'lib/dinamo/model/attributes.rb', line 134
def ==(other)
return false unless other.kind_of?(Dinamo::Model)
hash_key == other.hash_key && range_key == other.range_key
end
|
#[](key) ⇒ Object
101
102
103
|
# File 'lib/dinamo/model/attributes.rb', line 101
def [](key)
attributes[key]
end
|
#[]=(key, value) ⇒ Object
105
106
107
|
# File 'lib/dinamo/model/attributes.rb', line 105
def []=(key, value)
self.attributes = { key => value }
end
|
#hash_key ⇒ Object
122
123
124
|
# File 'lib/dinamo/model/attributes.rb', line 122
def hash_key
attributes[self.class.primary_keys[:hash]]
end
|
#primary_keys ⇒ Object
140
141
142
143
144
|
# File 'lib/dinamo/model/attributes.rb', line 140
def primary_keys
@primary_keys ||= self.class.primary_keys.inject({}) do |keys, (_, key)|
keys.merge(key => attributes[key])
end
end
|
#range_key ⇒ Object
126
127
128
|
# File 'lib/dinamo/model/attributes.rb', line 126
def range_key
attributes[self.class.primary_keys[:range]]
end
|
#silent_assign(new_attributes) ⇒ Object
130
131
132
|
# File 'lib/dinamo/model/attributes.rb', line 130
def silent_assign(new_attributes)
@attributes.merge!(new_attributes)
end
|
#variable_attributes ⇒ Object
109
110
111
112
|
# File 'lib/dinamo/model/attributes.rb', line 109
def variable_attributes
keys = primary_keys.keys
attributes.select { |key, _| !keys.include?(key.to_sym) }
end
|