Module: Rails::DataMapper::MultiparameterAttributes
- Defined in:
- lib/dm-rails/multiparameter_attributes.rb
Overview
Include this module into a DataMapper model to enable multiparameter attributes.
A multiparameter attribute has attr(Xc) as name where attr
specifies the attribute, X
the position of the value, and c
an optional typecast identifier. All values that share an attr
are sorted by their position, optionally cast using #to_c
(where c
is the typecast identifier) and then used to instantiate the proper attribute value.
Instance Method Summary collapse
-
#attributes=(attributes) ⇒ Hash
Merges multiparameter attributes and calls
super
with the merged attributes.
Instance Method Details
#attributes=(attributes) ⇒ Hash
Merges multiparameter attributes and calls super
with the merged attributes.
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/dm-rails/multiparameter_attributes.rb', line 82 def attributes=(attributes) attribs = attributes.dup multi_parameter_attributes = [] attribs.each do |k, v| if k.to_s.include?("(") multi_parameter_attributes << [ k, v ] attribs.delete(k) end end attribs.merge!(merge_multiparameter_attributes(multi_parameter_attributes)) super(attribs) end |