@@ -52,18 +52,19 @@ def set_attributes(model)
5252 # Set the attribute using the column_definition and the csv_value
5353 def set_attribute ( model , column , csv_value )
5454 column_definition = column . definition
55- if column_definition . to && column_definition . to . is_a? ( Proc )
56- to_proc = column_definition . to
55+ transformer = column_definition . to
56+ if transformer . respond_to? ( :call )
57+ arity = transformer . is_a? ( Proc ) ? transformer . arity : transformer . method ( :call ) . arity
5758
58- case to_proc . arity
59+ case arity
5960 when 1 # to: ->(email) { email.downcase }
60- model . public_send ( "#{ column_definition . name } =" , to_proc . call ( csv_value ) )
61+ model . public_send ( "#{ column_definition . name } =" , transformer . call ( csv_value ) )
6162 when 2 # to: ->(published, post) { post.published_at = Time.now if published == "true" }
62- to_proc . call ( csv_value , model )
63+ transformer . call ( csv_value , model )
6364 when 3 # to: ->(field_value, post, column) { post.hash_field[column.name] = field_value }
64- to_proc . call ( csv_value , model , column )
65+ transformer . call ( csv_value , model , column )
6566 else
66- raise ArgumentError , "`to` proc can only have 1, 2 or 3 arguments"
67+ raise ArgumentError , "arity: #{ transformer . arity . inspect } - `to` can only have 1, 2 or 3 arguments"
6768 end
6869 else
6970 attribute = column_definition . attribute
0 commit comments