Class: ActiveRecord::FixtureBuilder::Fixture
- Inherits:
-
Object
- Object
- ActiveRecord::FixtureBuilder::Fixture
- Defined in:
- lib/active_record/fixture_builder/fixture.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(fixture_builder, path) ⇒ Fixture
constructor
A new instance of Fixture.
- #inspect ⇒ Object
-
#load! ⇒ Object
def write! path.open(‘w’) do |file| file.write records_from_database.to_yaml end end.
- #records_from_file ⇒ Object
- #table_name ⇒ Object
Constructor Details
#initialize(fixture_builder, path) ⇒ Fixture
Returns a new instance of Fixture.
3 4 5 |
# File 'lib/active_record/fixture_builder/fixture.rb', line 3 def initialize fixture_builder, path @fixture_builder, @path = fixture_builder, path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/active_record/fixture_builder/fixture.rb', line 6 def path @path end |
Instance Method Details
#inspect ⇒ Object
34 35 36 37 |
# File 'lib/active_record/fixture_builder/fixture.rb', line 34 def inspect path = @path.relative_path_from(@fixture_builder.config.fixtures_path) %[#<#{self.class} #{path.to_s}>] end |
#load! ⇒ Object
def write!
path.open('w') do |file|
file.write records_from_database.to_yaml
end
end
26 27 28 29 30 31 32 |
# File 'lib/active_record/fixture_builder/fixture.rb', line 26 def load! @fixture_builder.database.truncate table_name records_from_file.each do |fixture_name, record| @fixture_builder.database.insert(table_name, fixture_name, record) end @fixture_builder.database.reset_pk_sequence table_name end |
#records_from_file ⇒ Object
12 13 14 |
# File 'lib/active_record/fixture_builder/fixture.rb', line 12 def records_from_file Array YAML.load_file @path end |
#table_name ⇒ Object
8 9 10 |
# File 'lib/active_record/fixture_builder/fixture.rb', line 8 def table_name @table_name ||= File.basename(@path, '.yml') end |