Class: ActiveRecord::FixtureSet::TableRows

Inherits:
Object
  • Object
show all
Defined in:
activerecord/lib/active_record/fixture_set/table_rows.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_name, model_class:, fixtures:, config:) ⇒ TableRows

Returns a new instance of TableRows.



9
10
11
12
13
14
15
16
17
18
19
# File 'activerecord/lib/active_record/fixture_set/table_rows.rb', line 9

def initialize(table_name, model_class:, fixtures:, config:)
  @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, config)
end

Instance Attribute Details

#model_classObject (readonly)

Returns the value of attribute model_class



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

def model_class
  @model_class
end

#tablesObject (readonly)

Returns the value of attribute tables



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

def tables
  @tables
end

Instance Method Details

#model_metadataObject



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

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

#to_hashObject



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

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