Module Rails::DataMapper::MultiparameterAttributes
In: lib/dm-rails/multiparameter_attributes.rb

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.

@example

  # Assigning a hash with multiparameter values for a +Date+ property called
  # +written_on+:
  resource.attributes = {
      'written_on(1i)' => '2004',
      'written_on(2i)' => '6',
      'written_on(3i)' => '24' }

  # +Date+ will be initialized with each string cast to a number using
  # #to_i.
  resource.written_on == Date.new(2004, 6, 24)

Methods

Public Instance methods

Merges multiparameter attributes and calls super with the merged attributes.

@param [Hash{String,Symbol=>Object}] attributes

  Names and values of attributes to assign.

@return [Hash]

  Names and values of attributes assigned.

@raise [MultiparameterAssignmentErrors]

  One or more multiparameters could not be assigned.

@api public

Protected Instance methods

[Validate]