Class: Fixture

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

Overview

:nodoc:

Defined Under Namespace

Classes: FixtureError, FormatError

Instance Method Summary collapse

Constructor Details

#initialize(fixture, class_name) ⇒ Fixture

Returns a new instance of Fixture.



271
272
273
274
# File 'lib/active_record/fixtures.rb', line 271

def initialize(fixture, class_name)
  @fixture = fixture.is_a?(Hash) ? fixture : read_fixture_file(fixture)
  @class_name = class_name
end

Instance Method Details

#[](key) ⇒ Object



280
281
282
# File 'lib/active_record/fixtures.rb', line 280

def [](key)
  @fixture[key]
end

#eachObject



276
277
278
# File 'lib/active_record/fixtures.rb', line 276

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

#findObject



296
297
298
# File 'lib/active_record/fixtures.rb', line 296

def find
  Object.const_get(@class_name).find(self[Object.const_get(@class_name).primary_key])
end

#key_listObject



288
289
290
# File 'lib/active_record/fixtures.rb', line 288

def key_list
  @fixture.keys.join(", ")
end

#to_hashObject



284
285
286
# File 'lib/active_record/fixtures.rb', line 284

def to_hash
  @fixture
end

#value_listObject



292
293
294
# File 'lib/active_record/fixtures.rb', line 292

def value_list
  @fixture.values.map { |v| ActiveRecord::Base.connection.quote(v).gsub('\\n', "\n").gsub('\\r', "\r") }.join(", ")
end