Sha256: 758a7f306fc76d67ec3e514a286ad6d85be05336211a157ef5262e4c49fe825a

Contents?: true

Size: 1.18 KB

Versions: 84

Compression:

Stored size: 1.18 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:)
        @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

      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)
          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
    end
  end
end

Version data entries

84 entries across 81 versions & 9 rubygems

Version Path
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activerecord-7.0.3.1/lib/active_record/fixture_set/table_rows.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/fixture_set/table_rows.rb
activerecord-7.0.5 lib/active_record/fixture_set/table_rows.rb
activerecord-7.0.4.3 lib/active_record/fixture_set/table_rows.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/fixture_set/table_rows.rb
activerecord-7.0.4.2 lib/active_record/fixture_set/table_rows.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/fixture_set/table_rows.rb
activerecord-7.0.4.1 lib/active_record/fixture_set/table_rows.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/fixture_set/table_rows.rb
activerecord-7.0.4 lib/active_record/fixture_set/table_rows.rb
activerecord-7.0.3.1 lib/active_record/fixture_set/table_rows.rb
activerecord-7.0.3 lib/active_record/fixture_set/table_rows.rb
activerecord-7.0.2.4 lib/active_record/fixture_set/table_rows.rb
activerecord-7.0.2.3 lib/active_record/fixture_set/table_rows.rb
activerecord-7.0.2.2 lib/active_record/fixture_set/table_rows.rb
activerecord-7.0.2.1 lib/active_record/fixture_set/table_rows.rb
activerecord-7.0.2 lib/active_record/fixture_set/table_rows.rb
activerecord-7.0.1 lib/active_record/fixture_set/table_rows.rb
activerecord-7.0.0 lib/active_record/fixture_set/table_rows.rb
activerecord-7.0.0.rc3 lib/active_record/fixture_set/table_rows.rb