Class: ActsAsTable::Mapper::Lense

Inherits:
Base
  • Object
show all
Defined in:
lib/acts_as_table/mapper.rb

Overview

ActsAsTable mapper object for an instance of the Lense class.

Instance Method Summary collapse

Constructor Details

#initialize(row_model, column_model_by_key, record_model, method_name, position_or_key = nil, **options) {|lense| ... } ⇒ ActsAsTable::Mapper::Lense

Returns a new ActsAsTable mapper object an instance of the Lense class.

Parameters:

Options Hash (**options):

  • :default (Boolean)
  • :primary_key (#to_s)

Yield Parameters:

Yield Returns:

  • (void)


204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/acts_as_table/mapper.rb', line 204

def initialize(row_model, column_model_by_key, record_model, method_name, position_or_key = nil, **options, &block)
  options.assert_valid_keys(:default)

  @row_model, @column_model_by_key, @record_model = row_model, column_model_by_key, record_model

  @record_model.lenses.build(method_name: method_name, default_value: options[:default]) do |lens|
    unless position_or_key.nil?
      lens.column_model = position_or_key.is_a?(::Symbol) ? @column_model_by_key[position_or_key] : @row_model.column_models[position_or_key - 1]
    end
  end

  super(&block)
end