Class: ActiveRecord::Fixture
- Includes:
- Enumerable
- Defined in:
- activerecord/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 ⇒ Object
- #find ⇒ Object
-
#initialize(fixture, model_class) ⇒ Fixture
constructor
A new instance of Fixture.
Methods included from Enumerable
#as_json, #each_with_object, #exclude?, #group_by, #index_by, #many?, #sum
Constructor Details
#initialize(fixture, model_class) ⇒ Fixture
Returns a new instance of Fixture.
694 695 696 697 |
# File 'activerecord/lib/active_record/fixtures.rb', line 694 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
692 693 694 |
# File 'activerecord/lib/active_record/fixtures.rb', line 692 def fixture @fixture end |
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class
692 693 694 |
# File 'activerecord/lib/active_record/fixtures.rb', line 692 def model_class @model_class end |
Instance Method Details
#[](key) ⇒ Object
707 708 709 |
# File 'activerecord/lib/active_record/fixtures.rb', line 707 def [](key) fixture[key] end |
#class_name ⇒ Object
699 700 701 |
# File 'activerecord/lib/active_record/fixtures.rb', line 699 def class_name model_class.name if model_class end |
#each ⇒ Object
703 704 705 |
# File 'activerecord/lib/active_record/fixtures.rb', line 703 def each fixture.each { |item| yield item } end |
#find ⇒ Object
713 714 715 716 717 718 719 |
# File 'activerecord/lib/active_record/fixtures.rb', line 713 def find if model_class model_class.find(fixture[model_class.primary_key]) else raise FixtureClassNotFound, "No class attached to find." end end |