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.



774
775
776
777
# File 'lib/active_record/fixtures.rb', line 774

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.



772
773
774
# File 'lib/active_record/fixtures.rb', line 772

def fixture
  @fixture
end

#model_classObject (readonly)

Returns the value of attribute model_class.



772
773
774
# File 'lib/active_record/fixtures.rb', line 772

def model_class
  @model_class
end

Instance Method Details

#[](key) ⇒ Object



787
788
789
# File 'lib/active_record/fixtures.rb', line 787

def [](key)
  fixture[key]
end

#class_nameObject



779
780
781
# File 'lib/active_record/fixtures.rb', line 779

def class_name
  model_class.name if model_class
end

#eachObject



783
784
785
# File 'lib/active_record/fixtures.rb', line 783

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

#findObject



793
794
795
796
797
798
799
# File 'lib/active_record/fixtures.rb', line 793

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