Method: ActsAsTable::Mapper::RowModel#columns=

Defined in:
lib/acts_as_table/mapper.rb

#columns=(object) ⇒ ActsAsTable::Mapper::RowModel

Builds new ActsAsTable column models in the scope of this ActsAsTable row model and caches them by key, if given.

Parameters:

  • object (#each_pair, #each, #to_s)

Returns:



358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# File 'lib/acts_as_table/mapper.rb', line 358

def columns=(object)
  # @return [Integer]
  column_models_count = @row_model.column_models.size

  # @return [void]
  ::Enumerator.new { |enumerator|
    _dfs(object) { |path|
      enumerator << path
    }
  }.each do |path|
    # @return [Symbol, nil]
    key = path[-1].is_a?(::Symbol) ? path.pop : nil

    column_models_count += 1

    # @return [ActsAsTable::ColumnModel]
    column_model = @row_model.column_models.build(position: column_models_count, **_to_column_model_attributes(path))

    unless key.nil?
      @column_model_by_key[key] = column_model
    end
  end

  self
end