Skip to content

Commit

Permalink
CSV / FasterCSV compatibility modifications for Ruby-1.8 and Ruby-1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
byrnejb committed Sep 3, 2010
1 parent 7614ad5 commit 6a1d0cc
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
0.9.3.jbb - 2010 September 03
* CSV / FasterCSV compatibility modifications for Ruby-1.8 and Ruby-1.9.

0.9.2.jbb - 2010 June 01
* New OptionParser implemented
* Help text extensively expanded
Expand Down
6 changes: 5 additions & 1 deletion lib/etl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@
require 'active_record'
require 'adapter_extensions'


if RUBY_VERSION < '1.9'
require 'faster_csv'
require 'fastercsv'
ETL_CSV = FasterCSV if not defined?(ETL_CSV)
else
require 'csv'
ETL_CSV = CSV if not defined?(ETL_CSV)
end


$:.unshift(File.dirname(__FILE__))

require 'etl/core_ext'
Expand Down
6 changes: 3 additions & 3 deletions lib/etl/control/source/database_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def read_rows(file)
raise "Local cache trigger file not found" unless File.exists?(local_file_trigger(file))

t = Benchmark.realtime do
FasterCSV.open(file, :headers => true).each do |row|
ETL_CSV.open(file, :headers => true).each do |row|
result_row = ETL::Row.new
result_row.source = self
row.each do |header, field|
Expand All @@ -150,7 +150,7 @@ def count_locally
def write_local(file)
lines = 0
t = Benchmark.realtime do
FasterCSV.open(file, 'w') do |f|
ETL_CSV.open(file, 'w') do |f|
f << columns
query_rows.each do |row|
f << columns.collect { |column| row[column.to_s] }
Expand Down Expand Up @@ -217,4 +217,4 @@ def database
end
end
end
end
end
4 changes: 2 additions & 2 deletions lib/etl/parser/delimited_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def each
ETL::Engine.logger.debug "parsing #{file}"
line = 0
lines_skipped = 0
FasterCSV.foreach(file, options) do |raw_row|
ETL_CSV.foreach(file, options) do |raw_row|
if lines_skipped < source.skip_lines
ETL::Engine.logger.debug "skipping line"
lines_skipped += 1
Expand Down Expand Up @@ -71,4 +71,4 @@ def initialize(name)
end
end
end
end
end
3 changes: 2 additions & 1 deletion lib/etl/transform/foreign_key_lookup_transform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ def initialize(file, match_index, result_field_index)
end

# Get the rows from the file specified in the initializer.

def rows
@rows ||= FasterCSV.read(@file)
@rows ||= ETL_CSV.read(@file)
end
protected :rows

Expand Down
2 changes: 1 addition & 1 deletion lib/etl/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module ETL#:nodoc:
module VERSION #:nodoc:
MAJOR = 0
MINOR = 9
TINY = 1
TINY = 3

STRING = [MAJOR, MINOR, TINY].join('.')
end
Expand Down

0 comments on commit 6a1d0cc

Please sign in to comment.