Sha256: 217eb698505bd004e9969e64d58f116d3f0afd38048e14a255f1cc3e66447ea7

Contents?: true

Size: 673 Bytes

Versions: 3

Compression:

Stored size: 673 Bytes

Contents

require 'csv'

class Sniff
  module Fixture
    extend self
    
    def load_fixtures(fixtures_path)
      Encoding.default_external = 'UTF-8' if Object.const_defined?('Encoding')
      Dir.glob(File.join(fixtures_path, '**/*.csv')) do |fixture_file|
        model_name = File.basename(fixture_file, '.csv').singularize.camelize
        next unless Object.const_defined?(model_name)
        
        model = model_name.constantize
        model.delete_all
        CSV.foreach(fixture_file, :headers => true) do |row|
          ActiveRecord::Base.connection.insert_fixture(row, model.table_name) rescue ActiveRecord::RecordNotUnique
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sniff-1.1.0 lib/sniff/fixture.rb
sniff-1.0.1 lib/sniff/fixture.rb
sniff-1.0.0 lib/sniff/fixture.rb