123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::FixtureSet::TableRows

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: activerecord/lib/active_record/fixture_set/table_rows.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(table_name, model_class:, fixtures:) ⇒ TableRows

[ GitHub ]

  
# File 'activerecord/lib/active_record/fixture_set/table_rows.rb', line 9

def initialize(table_name, model_class:, fixtures:)
  @model_class = model_class

  # track any join tables we need to insert later
  @tables = Hash.new { |h, table| h[table] = [] }

  # ensure this table is loaded before any HABTM associations
  @tables[table_name] = nil

  build_table_rows_from(table_name, fixtures)
end

Instance Attribute Details

#model_class (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/fixture_set/table_rows.rb', line 21

attr_reader :tables, :model_class

#tables (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/fixture_set/table_rows.rb', line 21

attr_reader :tables, :model_class

Instance Method Details

#build_table_rows_from(table_name, fixtures) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/fixture_set/table_rows.rb', line 32

def build_table_rows_from(table_name, fixtures)
  now = ActiveRecord.default_timezone == :utc ? Time.now.utc : Time.now

  @tables[table_name] = fixtures.map do |label, fixture|
    TableRow.new(
      fixture,
      table_rows: self,
      label: label,
      now: now,
    )
  end
end

#model_metadata

[ GitHub ]

  
# File 'activerecord/lib/active_record/fixture_set/table_rows.rb', line 27

def 
  @model_metadata ||= ModelMetadata.new(model_class)
end

#to_hash

[ GitHub ]

  
# File 'activerecord/lib/active_record/fixture_set/table_rows.rb', line 23

def to_hash
  @tables.transform_values { |rows| rows.map(&:to_hash) }
end