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, #exclude?, #index_by, #many?, #pluck, #sum, #without

Constructor Details

#initialize(fixture, model_class) ⇒ Fixture



833
834
835
836
# File 'activerecord/lib/active_record/fixtures.rb', line 833

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.



831
832
833
# File 'activerecord/lib/active_record/fixtures.rb', line 831

def fixture
  @fixture
end

#model_classObject (readonly)

Returns the value of attribute model_class.



831
832
833
# File 'activerecord/lib/active_record/fixtures.rb', line 831

def model_class
  @model_class
end

Instance Method Details

#[](key) ⇒ Object



846
847
848
# File 'activerecord/lib/active_record/fixtures.rb', line 846

def [](key)
  fixture[key]
end

#class_nameObject



838
839
840
# File 'activerecord/lib/active_record/fixtures.rb', line 838

def class_name
  model_class.name if model_class
end

#eachObject



842
843
844
# File 'activerecord/lib/active_record/fixtures.rb', line 842

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

#findObject



852
853
854
855
856
857
858
859
860
# File 'activerecord/lib/active_record/fixtures.rb', line 852

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