Module: DatastaxRails::AttributeMethods::Typecasting
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/datastax_rails/attribute_methods/typecasting.rb
Overview
Handles the mapping of attributes to their appropriate DatastaxRails::Column so that they can be typecasted.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Instance Method Details
#initialize_attributes(attributes) ⇒ Object
:nodoc:
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 17 def initialize_attributes(attributes) #:nodoc: attrs = {} attributes.each do |k, v| col = column_for_attribute(k) next unless col if col.type == :map && k.to_s != col.name.to_s # See if we have a matching dynamic attribute column self.class.map_columns.each do |mcol| if k.to_s.starts_with?(mcol.name.to_s) attrs[mcol.name.to_s] ||= mcol.wrap_collection({}, self) attrs[mcol.name.to_s][k.to_s] = v end end else attrs[k.to_s] = col.collection? ? col.wrap_collection(v, self) : v end end attrs end |