Class: ActsAsTable::Mapper::RowModel

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

Overview

ActsAsTable mapper object for an instance of the RowModel class.

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(row_model) {|row_model| ... } ⇒ ActsAsTable::Mapper::RowModel

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

Parameters:

Yield Parameters:

Yield Returns:

  • (void)


348
349
350
351
352
# File 'lib/acts_as_table/mapper.rb', line 348

def initialize(row_model, &block)
  @row_model, @column_model_by_key = row_model, {}

  super(&block)
end

Instance Method Details

#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

#model(class_name) {|record_model| ... } ⇒ ActsAsTable::Mapper::RecordModel

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

Parameters:

  • class_name (#to_s)

Yield Parameters:

Yield Returns:

  • (void)

Returns:



400
401
402
# File 'lib/acts_as_table/mapper.rb', line 400

def model(class_name, &block)
  ActsAsTable::Mapper::RecordModel.new(@row_model, @column_model_by_key, class_name, &block)
end

#root_model=(target) ⇒ ActsAsTable::Mapper::RowModel

Set the root ActsAsTable record model for this ActsAsTable row model.



388
389
390
391
392
# File 'lib/acts_as_table/mapper.rb', line 388

def root_model=(target)
  @row_model.root_record_model = target.send(:instance_variable_get, :@record_model)

  self
end