Sha256: 21154ce2982046014343491898d260903566a331798239a293ecbe164e686bd9

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

# v4.0.0 Migration Guide

_Note: this guide assumes you are upgrading from decanter v3 to v4._

This version contains the following breaking changes:

1. `FloatParser` and `IntegerParser` have been updated to address a bug where negative numbers were being parsed as positive. In the (unlikely) event that your project was relying on the previous behavior, you can pin the gem version to `v3.6.0` or include the legacy version(s) of the parsers as custom parsers in your project.

To add a custom parser, add the new parser class to your project:

```rb
# app/parsers/postive_float_parser.rb

class PositiveFloatParser < Decanter::Parser::ValueParser
  REGEX = /(\d|[.])/

  allow Float, Integer

  parser do |val, options|
    raise Decanter::ParseError.new 'Expects a single value' if val.is_a? Array
    next if (val.nil? || val === '')
    val.scan(REGEX).join.try(:to_f)
  end
end
```

Then, use the appropriate key to look up the parser in your decanter:

```rb
# app/decanters/product_decanter.rb

class ProductDecanter <  Decanter::Base
  input :price, :positive_float #=> PositiveFloatParser
end
```

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
decanter-4.0.4 migration-guides/v4.0.0.md
decanter-4.0.3 migration-guides/v4.0.0.md
decanter-4.0.2 migration-guides/v4.0.0.md
decanter-4.0.1 migration-guides/v4.0.0.md
decanter-4.0.0 migration-guides/v4.0.0.md