-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update float/integer regex to handle negative values * bump version to 3.6.1 * spec * update hash syntax in specs * change to major version 3.7.0 * use eq * actual bump to major version v4 * update gem version in readme * v3->v4 migration guide * add sample custom parser * Add comment syntax highlighting Co-authored-by: Conor Hawes <[email protected]>
- Loading branch information
1 parent
d4b7851
commit 45a54d5
Showing
8 changed files
with
64 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Decanter | ||
VERSION = '3.6.0'.freeze | ||
VERSION = '4.0.0'.freeze | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# 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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters