Class: ActiveRecord::Fixture

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/active_record/fixtures.rb

Overview

:nodoc:

Defined Under Namespace

Classes: FixtureError, FormatError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fixture, model_class) ⇒ Fixture

Returns a new instance of Fixture.


815
816
817
818
# File 'lib/active_record/fixtures.rb', line 815

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


813
814
815
# File 'lib/active_record/fixtures.rb', line 813

def fixture
  @fixture
end

#model_classObject (readonly)

Returns the value of attribute model_class


813
814
815
# File 'lib/active_record/fixtures.rb', line 813

def model_class
  @model_class
end

Instance Method Details

#[](key) ⇒ Object


828
829
830
# File 'lib/active_record/fixtures.rb', line 828

def [](key)
  fixture[key]
end

#class_nameObject


820
821
822
# File 'lib/active_record/fixtures.rb', line 820

def class_name
  model_class.name if model_class
end

#eachObject


824
825
826
# File 'lib/active_record/fixtures.rb', line 824

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

#findObject


834
835
836
837
838
839
840
841
842
# File 'lib/active_record/fixtures.rb', line 834

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