Class: ActiveRecord::FixtureSet::TableRows
- Inherits:
-
Object
- Object
- ActiveRecord::FixtureSet::TableRows
- Defined in:
- lib/active_record/fixture_set/table_rows.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
Instance Method Summary collapse
-
#initialize(table_name, model_class:, fixtures:) ⇒ TableRows
constructor
A new instance of TableRows.
- #model_metadata ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(table_name, model_class:, fixtures:) ⇒ TableRows
Returns a new instance of TableRows.
9 10 11 12 13 14 15 16 17 18 19 |
# File '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 ⇒ Object (readonly)
Returns the value of attribute model_class.
21 22 23 |
# File 'lib/active_record/fixture_set/table_rows.rb', line 21 def model_class @model_class end |
#tables ⇒ Object (readonly)
Returns the value of attribute tables.
21 22 23 |
# File 'lib/active_record/fixture_set/table_rows.rb', line 21 def tables @tables end |
Instance Method Details
#model_metadata ⇒ Object
27 28 29 |
# File 'lib/active_record/fixture_set/table_rows.rb', line 27 def @model_metadata ||= ModelMetadata.new(model_class) end |
#to_hash ⇒ Object
23 24 25 |
# File 'lib/active_record/fixture_set/table_rows.rb', line 23 def to_hash @tables.transform_values { |rows| rows.map(&:to_hash) } end |