Permalink
Browse files

Maintained backwards compatibility with single parameter transformati…

…ons.
  • Loading branch information...
pillowfactory committed May 13, 2010
1 parent 95d7f4c commit 7184770bc598c937aea5c6e3063b9d5dbf9d9f7d
Showing with 17 additions and 3 deletions.
  1. +6 −2 lib/csv-mapper/attribute_map.rb
  2. +11 −1 spec/csv-mapper/csv-mapper_attribute_map_spec.rb
@@ -45,7 +45,11 @@ def parse_transform(csv_row)
@transformer = lambda{|row, index| @map_context.send(transform_name, row, index) }
end
- @transformer.call(csv_row, @index)
+ if @transformer.arity == 1
+ @transformer.call(csv_row)
+ else
+ @transformer.call(csv_row, @index)
+ end
end
end
-end
+end
@@ -38,11 +38,21 @@ def transform_it(row, index)
@row_attr.map( lambda{|row, index| :success } )
@row_attr.parse(@csv_row).should == :success
end
+
+ it "should parse values using a mapped lambda transformer that only accepts the row" do
+ @row_attr.map( lambda{|row| :success } )
+ @row_attr.parse(@csv_row).should == :success
+ end
it "should parse values using a mapped block transformers" do
@row_attr.map {|row, index| :success }
@row_attr.parse(@csv_row).should == :success
end
+
+ it "should parse values using a mapped block transformer that only accepts the row" do
+ @row_attr.map {|row, index| :success }
+ @row_attr.parse(@csv_row).should == :success
+ end
it "should parse values using a named method on the context" do
@row_attr.map(:transform_it).parse(@csv_row).should == :transform_it_success
@@ -52,4 +62,4 @@ def transform_it(row, index)
@row_attr.raw_value(@csv_row).should be(@csv_row[@row_attr.index])
end
-end
+end

0 comments on commit 7184770

Please sign in to comment.