Class: ActiveRecord::Fixture

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
activerecord/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, #including, #index_by, #index_with, #many?, #pick, #pluck, #sum, #without

Constructor Details

#initialize(fixture, model_class) ⇒ Fixture

Returns a new instance of Fixture.


747
748
749
750
# File 'activerecord/lib/active_record/fixtures.rb', line 747

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


745
746
747
# File 'activerecord/lib/active_record/fixtures.rb', line 745

def fixture
  @fixture
end

#model_classObject (readonly)

Returns the value of attribute model_class


745
746
747
# File 'activerecord/lib/active_record/fixtures.rb', line 745

def model_class
  @model_class
end

Instance Method Details

#[](key) ⇒ Object


760
761
762
# File 'activerecord/lib/active_record/fixtures.rb', line 760

def [](key)
  fixture[key]
end

#class_nameObject


752
753
754
# File 'activerecord/lib/active_record/fixtures.rb', line 752

def class_name
  model_class.name if model_class
end

#eachObject


756
757
758
# File 'activerecord/lib/active_record/fixtures.rb', line 756

def each
  fixture.each { |item| yield item }
end

#findObject


766
767
768
769
770
771
# File 'activerecord/lib/active_record/fixtures.rb', line 766

def find
  raise FixtureClassNotFound, "No class attached to find." unless model_class
  model_class.unscoped do
    model_class.find(fixture[model_class.primary_key])
  end
end