Class: ActiveRecord::Fixture

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/fixtures.rb

Overview

:nodoc:

Defined Under Namespace

Classes: FixtureError, FormatError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#as_json, #compact_blank, #exclude?, #excluding, #in_order_of, #including, #index_by, #index_with, #many?, #maximum, #minimum, #pick, #pluck, #sole, #sum

Constructor Details

#initialize(fixture, model_class) ⇒ Fixture

Returns a new instance of Fixture.



750
751
752
753
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/fixtures.rb', line 750

def initialize(fixture, model_class)
  @fixture     = fixture
  @model_class = model_class
end

Instance Attribute Details

#fixtureObject (readonly) Also known as: to_hash

Returns the value of attribute fixture.



748
749
750
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/fixtures.rb', line 748

def fixture
  @fixture
end

#model_classObject (readonly)

Returns the value of attribute model_class.



748
749
750
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/fixtures.rb', line 748

def model_class
  @model_class
end

Instance Method Details

#[](key) ⇒ Object



763
764
765
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/fixtures.rb', line 763

def [](key)
  fixture[key]
end

#class_nameObject



755
756
757
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/fixtures.rb', line 755

def class_name
  model_class.name if model_class
end

#each(&block) ⇒ Object



759
760
761
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/fixtures.rb', line 759

def each(&block)
  fixture.each(&block)
end

#findObject



769
770
771
772
773
774
775
776
777
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/fixtures.rb', line 769

def find
  raise FixtureClassNotFound, "No class attached to find." unless model_class
  object = model_class.unscoped do
    model_class.find(fixture[model_class.primary_key])
  end
  # Fixtures can't be eagerly loaded
  object.instance_variable_set(:@strict_loading, false)
  object
end