Class: Fixture
- Inherits:
-
Object
show all
- Includes:
- Enumerable
- Defined in:
- lib/active_record/fixtures.rb
Overview
Defined Under Namespace
Classes: FixtureError, FormatError
Instance Method Summary
collapse
Constructor Details
#initialize(fixture, class_name) ⇒ Fixture
303
304
305
306
|
# File 'lib/active_record/fixtures.rb', line 303
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
312
313
314
|
# File 'lib/active_record/fixtures.rb', line 312
def [](key)
@fixture[key]
end
|
#each ⇒ Object
308
309
310
|
# File 'lib/active_record/fixtures.rb', line 308
def each
@fixture.each { |item| yield item }
end
|
#find ⇒ Object
328
329
330
331
332
333
|
# File 'lib/active_record/fixtures.rb', line 328
def find
if Object.const_defined?(@class_name)
klass = Object.const_get(@class_name)
klass.find(self[klass.primary_key])
end
end
|
#key_list ⇒ Object
320
321
322
|
# File 'lib/active_record/fixtures.rb', line 320
def key_list
@fixture.keys.join(", ")
end
|
#to_hash ⇒ Object
316
317
318
|
# File 'lib/active_record/fixtures.rb', line 316
def to_hash
@fixture
end
|
#value_list ⇒ Object
324
325
326
|
# File 'lib/active_record/fixtures.rb', line 324
def value_list
@fixture.values.map { |v| ActiveRecord::Base.connection.quote(v).gsub('\\n', "\n").gsub('\\r', "\r") }.join(", ")
end
|