# Change Log All notable changes to this project will be documented in this file. ## [0.5.0] - 2018-01-13 ### Added * after_save supports block with arity of 2 for access to raw attributes. [#68][] by [@macfanatic][]. ```ruby class Importer model Task column :assignee, to: ->(name) { User.active.find_by(name: name) } after_save do |task, attributes| if task.errors[:assignee].present? && attributes['Assignee'].present? task.errors.add(:assignee, "'#{ attributes['Assignee'] }' is not part of this project." end end end ``` * support Proc identifiers. [#69][] by [@danielweinmann][] ```ruby class Importer identifier ->(user) { user.email.present? ? :email : [:company_id, :employee_id] } end ``` ## [0.4.0] - 2017-08-10 ### Added * Rows are now aware of their line number. [#63][] by [@paulodeleo][] ```ruby import.report.invalid_rows.map { |row| [row.line_number, row.model.email, row.errors] } # => [ [2, "INVALID_EMAIL", { "email" => "is invalid" } ] ] ``` ## [0.3.2] - 2017-01-06 ### Fixed * `after_build` block is only called once ([#47][] by [@fxgallego][] and [#52][] [@pnomolos][]) * `after_build` and `after_save` blocks don't leak between runtime definitions ([#47][] by [@fxgallego][] and [#52][] [@pnomolos][]) ## [0.3.1] - 2016-05-09 ### Added * You can customize the encoding with the `encoding` option. Default is `UTF-8`. ([#38][] by [@egg-chicken][]) ## [0.3.0] - 2016-02-05 ### Added * Empty cells are now empty strings. You don't have to check for a nil value when applying a transformation anymore. ```ruby # Prior to 0.3, an empty cell turns into `nil` column :email, to: ->(email) { email.downcase unless email.nil? } # From 0.3, an empty cell turns into `""` column :email, to: ->(email) { email.downcase } ``` * You can now skip an import in the `after_build` callback: ```ruby UserImport.new(file: csv_file) do # Skip existing records after_build do |user| skip! if user.persisted? end end ``` ## [0.2.0] - 2015-07-24 ### Added * `after_save` callback. ```ruby progress_bar = ProgressBar.new UserImport.new(file: my_file) do after_save do |user| progress_bar.increment end end ``` * You can define a composite identifier made of multiple columns. ```ruby # Update records with matching company_id AND employee_id identifier :company_id, :employee_id ``` * You can set a custom `quote_char` at runtime. ([#26][] by [@shvetsovdm][]) ```ruby UserImport.new(file: csv_file, quote_char: "'") ``` ## [0.1.3] - 2015-06-19 ### Added * You can now change the configuration at runtime. Example: ```ruby UserImport.new(file: csv_file) do after_build do |user| user.import_by_user = current_user end end ``` * Add `after_build` hooks to perform arbitrary operations on a model before saving it. * `identifier` does not have to be a required attribute anymore. That enables you to use `id` as an identifier and import new entries without having to provide an `id` ## [0.1.2] - 2015-06-15 ### Fixed * `run!` was not *returning* a report object when the header was invalid. ## [0.1.1] - 2015-06-12 ### Changed * When calling `run!` on an import with invalid header we update the report object instead of raising an exception. ## [0.1.0] - 2015-06-11 * Initial Release [#26]: https://github.com/BrewhouseTeam/csv-importer/issues/26 [#38]: https://github.com/BrewhouseTeam/csv-importer/issues/38 [#47]: https://github.com/BrewhouseTeam/csv-importer/issues/47 [#52]: https://github.com/BrewhouseTeam/csv-importer/issues/52 [#63]: https://github.com/BrewhouseTeam/csv-importer/issues/63 [#68]: https://github.com/BrewhouseTeam/csv-importer/issues/68 [#69]: https://github.com/BrewhouseTeam/csv-importer/issues/69 [@danielweinmann]: https://github.com/danielweinmann [@egg-chicken]: https://github.com/egg-chicken [@fxgallego]: https://github.com/fxgallego [@macfanatic]: https://github.com/macfanatic [@paulodeleo]: https://github.com/paulodeleo [@pnomolos]: https://github.com/pnomolos [@shvetsovdm]: https://github.com/shvetsovdm