Module: ModelPack::AttributeMethods
- Extended by:
- Concern
- Defined in:
- lib/model_pack/attribute_methods.rb
Instance Method Summary
collapse
Methods included from Concern
append_features, class_methods, extended, included
Instance Method Details
#attributes ⇒ Object
18
19
20
|
# File 'lib/model_pack/attribute_methods.rb', line 18
def attributes
self.class.attribute_names.inject({}) { |h, name| h[name] = send(name); h }
end
|
#update_attributes(attributes) ⇒ Object
22
23
24
25
26
27
|
# File 'lib/model_pack/attribute_methods.rb', line 22
def update_attributes(attributes)
attributes.each do |name, attribute|
key = "#{name}="
send(key, attribute) if respond_to?(key)
end
end
|
#update_attributes!(attributes) ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/model_pack/attribute_methods.rb', line 29
def update_attributes!(attributes)
attributes.each do |name, attribute|
raise ArgumentError, "undefined attribute `#{name}`" unless attribute_names.include?(method)
key = "#{name}="
send(key, attribute) if respond_to?(key)
end
end
|