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.



736
737
738
739
# File 'lib/active_record/fixtures.rb', line 736

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.



734
735
736
# File 'lib/active_record/fixtures.rb', line 734

def fixture
  @fixture
end

#model_classObject (readonly)

Returns the value of attribute model_class.



734
735
736
# File 'lib/active_record/fixtures.rb', line 734

def model_class
  @model_class
end

Instance Method Details

#[](key) ⇒ Object



749
750
751
# File 'lib/active_record/fixtures.rb', line 749

def [](key)
  fixture[key]
end

#class_nameObject



741
742
743
# File 'lib/active_record/fixtures.rb', line 741

def class_name
  model_class.name if model_class
end

#eachObject



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

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

#findObject



755
756
757
758
759
760
761
# File 'lib/active_record/fixtures.rb', line 755

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