Sha256: d94cc90dd8703fa440bc61e7dd2cacc6a89c2b28acf09dde303bfd99b999a420

Contents?: true

Size: 1.2 KB

Versions: 59

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require "active_record/fixture_set/table_row"
require "active_record/fixture_set/model_metadata"

module ActiveRecord
  class FixtureSet
    class TableRows # :nodoc:
      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

      attr_reader :tables, :model_class

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

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

      private
        def build_table_rows_from(table_name, fixtures, config)
          now = config.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
    end
  end
end

Version data entries

59 entries across 59 versions & 4 rubygems

Version Path
activerecord-6.1.7.10 lib/active_record/fixture_set/table_rows.rb
activerecord-6.1.7.9 lib/active_record/fixture_set/table_rows.rb
activerecord-6.1.7.8 lib/active_record/fixture_set/table_rows.rb
activerecord-6.1.7.7 lib/active_record/fixture_set/table_rows.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activerecord-6.1.6.1/lib/active_record/fixture_set/table_rows.rb
activerecord-6.1.7.6 lib/active_record/fixture_set/table_rows.rb
activerecord-6.1.7.5 lib/active_record/fixture_set/table_rows.rb
activerecord-6.1.7.4 lib/active_record/fixture_set/table_rows.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activerecord-6.1.6.1/lib/active_record/fixture_set/table_rows.rb
activerecord-6.1.7.3 lib/active_record/fixture_set/table_rows.rb
activerecord-6.1.7.2 lib/active_record/fixture_set/table_rows.rb
activerecord-6.1.7.1 lib/active_record/fixture_set/table_rows.rb
activerecord-6.0.6.1 lib/active_record/fixture_set/table_rows.rb
activerecord-6.1.7 lib/active_record/fixture_set/table_rows.rb
activerecord-6.0.6 lib/active_record/fixture_set/table_rows.rb
activerecord-6.1.6.1 lib/active_record/fixture_set/table_rows.rb
activerecord-6.0.5.1 lib/active_record/fixture_set/table_rows.rb
activerecord-6.0.5 lib/active_record/fixture_set/table_rows.rb
activerecord-6.1.6 lib/active_record/fixture_set/table_rows.rb
activerecord-6.1.5.1 lib/active_record/fixture_set/table_rows.rb