Class: ActiveRecord::Fixture
- Inherits:
-
Object
- Object
- ActiveRecord::Fixture
- Includes:
- Enumerable
- Defined in:
- lib/active_record/fixtures.rb
Overview
:nodoc:
Defined Under Namespace
Classes: FixtureError, FormatError
Instance Attribute Summary collapse
-
#fixture ⇒ Object
(also: #to_hash)
readonly
Returns the value of attribute fixture.
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #class_name ⇒ Object
- #each(&block) ⇒ Object
- #find ⇒ Object
-
#initialize(fixture, model_class) ⇒ Fixture
constructor
A new instance of Fixture.
Constructor Details
#initialize(fixture, model_class) ⇒ Fixture
Returns a new instance of Fixture.
813 814 815 816 |
# File 'lib/active_record/fixtures.rb', line 813 def initialize(fixture, model_class) @fixture = fixture @model_class = model_class end |
Instance Attribute Details
#fixture ⇒ Object (readonly) Also known as: to_hash
Returns the value of attribute fixture.
811 812 813 |
# File 'lib/active_record/fixtures.rb', line 811 def fixture @fixture end |
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
811 812 813 |
# File 'lib/active_record/fixtures.rb', line 811 def model_class @model_class end |
Instance Method Details
#[](key) ⇒ Object
826 827 828 |
# File 'lib/active_record/fixtures.rb', line 826 def [](key) fixture[key] end |
#class_name ⇒ Object
818 819 820 |
# File 'lib/active_record/fixtures.rb', line 818 def class_name model_class.name if model_class end |
#each(&block) ⇒ Object
822 823 824 |
# File 'lib/active_record/fixtures.rb', line 822 def each(&block) fixture.each(&block) end |
#find ⇒ Object
832 833 834 835 836 837 838 839 840 841 |
# File 'lib/active_record/fixtures.rb', line 832 def find raise FixtureClassNotFound, "No class attached to find." unless model_class object = model_class.unscoped do pk_clauses = fixture.slice(*Array(model_class.primary_key)) model_class.find_by!(pk_clauses) end # Fixtures can't be eagerly loaded object.instance_variable_set(:@strict_loading, false) object end |