class ActiveRecord::FixtureSet::TableRow
Experimental RBS support (using type sampling data from the type_fusion
project).
# sig/active_record/fixture_set/table_row.rbs class ActiveRecord::FixtureSet::TableRow def add_join_records: (ActiveRecord::FixtureSet::TableRow::HasManyThroughProxy association) -> nil def fill_row_model_attributes: () -> untyped def fill_timestamps: () -> untyped def generate_primary_key: () -> Integer def initialize: (ActiveRecord::Fixture fixture, table_rows: ActiveRecord::FixtureSet::TableRows, label: String, now: Time) -> void def interpolate_label: () -> untyped def model_class: () -> Class def model_metadata: () -> ActiveRecord::FixtureSet::ModelMetadata def reflection_class: () -> Class end
:nodoc:
def add_join_records(association)
Experimental RBS support (using type sampling data from the type_fusion
project).
def add_join_records: (ActiveRecord::FixtureSet::TableRow::HasManyThroughProxy association) -> nil
This signature was generated using 3 samples from 1 application.
def add_join_records(association) # This is the case when the join table has no fixtures file if (targets = @row.delete(association.name.to_s)) table_name = association.join_table column_type = association.primary_key_type lhs_key = association.lhs_key rhs_key = association.rhs_key targets = targets.is_a?(Array) ? targets : targets.split(/\s*,\s*/) joins = targets.map do |target| join = { lhs_key => @row[model_metadata.primary_key_name], rhs_key => ActiveRecord::FixtureSet.identify(target, column_type) } association.timestamp_column_names.each do |col| join[col] = @now end join end @table_rows.tables[table_name].concat(joins) end end
def fill_row_model_attributes
Experimental RBS support (using type sampling data from the type_fusion
project).
def fill_row_model_attributes: () -> untyped
This signature was generated using 2 samples from 1 application.
def fill_row_model_attributes return unless model_class fill_timestamps interpolate_label generate_primary_key resolve_enums resolve_sti_reflections end
def fill_timestamps
Experimental RBS support (using type sampling data from the type_fusion
project).
def fill_timestamps: () -> untyped
This signature was generated using 1 sample from 1 application.
def fill_timestamps # fill in timestamp columns if they aren't specified and the model is set to record_timestamps if model_class.record_timestamps model_metadata.timestamp_column_names.each do |c_name| @row[c_name] = @now unless @row.key?(c_name) end end end
def generate_primary_key
Experimental RBS support (using type sampling data from the type_fusion
project).
def generate_primary_key: () -> Integer
This signature was generated using 2 samples from 1 application.
def generate_primary_key # generate a primary key if necessary if model_metadata.has_primary_key_column? && !@row.include?(model_metadata.primary_key_name) @row[model_metadata.primary_key_name] = ActiveRecord::FixtureSet.identify( @label, model_metadata.primary_key_type ) end end
def initialize(fixture, table_rows:, label:, now:)
Experimental RBS support (using type sampling data from the type_fusion
project).
def initialize: (ActiveRecord::Fixture fixture, table_rows: ActiveRecord::FixtureSet::TableRows, label: String, now: Time) -> void
This signature was generated using 1 sample from 1 application.
def initialize(fixture, table_rows:, label:, now:) @table_rows = table_rows @label = label @now = now @row = fixture.to_hash fill_row_model_attributes end
def interpolate_label
Experimental RBS support (using type sampling data from the type_fusion
project).
def interpolate_label: () -> untyped
This signature was generated using 1 sample from 1 application.
def interpolate_label # interpolate the fixture label @row.each do |key, value| @row[key] = value.gsub("$LABEL", @label.to_s) if value.is_a?(String) end end
def model_class
Experimental RBS support (using type sampling data from the type_fusion
project).
def model_class: () -> Class
This signature was generated using 4 samples from 1 application.
def model_class @table_rows.model_class end
def model_metadata
Experimental RBS support (using type sampling data from the type_fusion
project).
def model_metadata: () -> ActiveRecord::FixtureSet::ModelMetadata
This signature was generated using 6 samples from 1 application.
def model_metadata @table_rows.model_metadata end
def reflection_class
Experimental RBS support (using type sampling data from the type_fusion
project).
def reflection_class: () -> Class
This signature was generated using 5 samples from 1 application.
def reflection_class @reflection_class ||= if @row.include?(model_metadata.inheritance_column_name) @row[model_metadata.inheritance_column_name].constantize rescue model_class else model_class end end
def resolve_enums
def resolve_enums reflection_class.defined_enums.each do |name, values| if @row.include?(name) @row[name] = values.fetch(@row[name], @row[name]) end end end
def resolve_sti_reflections
def resolve_sti_reflections # If STI is used, find the correct subclass for association reflection reflection_class._reflections.each_value do |association| case association.macro when :belongs_to # Do not replace association name with association foreign key if they are named the same fk_name = association.join_foreign_key if association.name.to_s != fk_name && value = @row.delete(association.name.to_s) if association.polymorphic? if value.sub!(/\s*\(([^)]*)\)\s*$/, "") # support polymorphic belongs_to as "label (Type)" @row[association.join_foreign_type] = $1 end elsif association.join_primary_key != association.klass.primary_key raise PrimaryKeyError.new(@label, association, value) end fk_type = reflection_class.type_for_attribute(fk_name).type @row[fk_name] = ActiveRecord::FixtureSet.identify(value, fk_type) end when :has_many if association.options[:through] add_join_records(HasManyThroughProxy.new(association)) end end end end
def to_hash
def to_hash @row end