Skip to content

Commit 22c391e

Browse files
authored
Document passing column object
Introduced in #73
1 parent f12fcdf commit 22c391e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ If you need to do more advanced stuff, you've got access to the model:
178178
column :email, as: [/e.?mail/i, "courriel"], to: ->(email, user) { user.email = email.downcase; model.super_user! if email[/@brewhouse.io\z/] }
179179
```
180180

181+
Like very advanced stuff? We grant you access to the [`column`](https://github.com/pcreux/csv-importer/blob/master/lib/csv_importer/column.rb) object itself which contains the column name – quite handy if you want to support arbitrary columns.
182+
183+
```ruby
184+
column :extra, as: [/extra/], to: ->(value, user, column) do
185+
attribute = column.name.sub(/^extra /, '')
186+
user[attribute] = value
187+
end
188+
```
189+
181190
Now, what if the user does not provide the email column? It's not worth
182191
running the import, we should just reject the CSV file right away.
183192
That's easy:

0 commit comments

Comments
 (0)