Class: ActiveRecord::FixtureBuilder::Fixture

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/fixture_builder/fixture.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject (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

#inspectObject



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_fileObject



12
13
14
# File 'lib/active_record/fixture_builder/fixture.rb', line 12

def records_from_file
  Array YAML.load_file @path
end

#table_nameObject



8
9
10
# File 'lib/active_record/fixture_builder/fixture.rb', line 8

def table_name
  @table_name ||= File.basename(@path, '.yml')
end