class ActiveRecord::FixtureBuilder

Constants

PUBLIC_INSTANCE_METHODS
VERSION

Public Class Methods

instance() click to toggle source
# File lib/active_record/fixture_builder.rb, line 78
def instance
  @instance ||= new
end
new(&block) click to toggle source
# File lib/active_record/fixture_builder.rb, line 15
def initialize(&block)
  configure(&block) if block_given?
end

Public Instance Methods

build_fixtures!() click to toggle source
# File lib/active_record/fixture_builder.rb, line 51
def build_fixtures!
  database.truncate_all_tables!
  builders.each(&:build!)
end
builders() click to toggle source
# File lib/active_record/fixture_builder.rb, line 40
def builders
  config.freeze
  @builders ||= Dir[config.builders_path+'*.rb'].map do |path|
    Builder.new self, Pathname(path)
  end
end
config() click to toggle source
# File lib/active_record/fixture_builder.rb, line 19
def config
  @config ||= Configuration.new
end
configure() { |config| ... } click to toggle source
# File lib/active_record/fixture_builder.rb, line 23
def configure
  yield config
  self
end
database() click to toggle source
# File lib/active_record/fixture_builder.rb, line 28
def database
  config.freeze
  @database ||= Database.new(config)
end
fixtures() click to toggle source
# File lib/active_record/fixture_builder.rb, line 33
def fixtures
  config.freeze
  @fixtures ||= Dir[config.fixtures_path+'*.yml'].map do |path|
    Fixture.new self, Pathname(path)
  end
end
inspect() click to toggle source
Calls superclass method
# File lib/active_record/fixture_builder.rb, line 71
def inspect
  super.split(/ |>/).first+'>'
end
load_fixtures!() click to toggle source
# File lib/active_record/fixture_builder.rb, line 47
def load_fixtures!
  fixtures.each(&:load!)
end
write_fixtures!() click to toggle source
# File lib/active_record/fixture_builder.rb, line 56
def write_fixtures!
  database.table_names.each do |table_name|
    config.fixtures_path.join("#{table_name}.yml").open('w') do |file|
      records = database.select_all(table_name)

      fixture_data = {}
      records.each_with_index do |record, index|
        fixture_data["#{table_name}_#{index.to_s.rjust(3,'0')}"] = record
      end

      file.write fixture_data.to_yaml
    end
  end
end