decanter 3.6.0 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 697f969bd6cdcac1487d237135cd4f1860ff9aa79abece975305d7ca7f0d5504
4
- data.tar.gz: 7ab9d647d3c90e9c5186f4f0b486115b3d17f3107990a7984827d87e2f4843f8
3
+ metadata.gz: 2a55957ce81334f115e619cd8e91ac413f40a79cf9e97eafebdd7ab3ac2d509a
4
+ data.tar.gz: 5521342e2df4c17bdcaabf85857242a9e6325015c95277f08ae86f9cf03bb480
5
5
  SHA512:
6
- metadata.gz: 286e79ac8ebdbd3b75cc667fadd77b2fc6966f54274f06e282fc9d94250cf3075eb2f6a9e31295f1d51efb50b1b5757507de98cc6816a23b9871af7c3e32ab2a
7
- data.tar.gz: b4cfff1c6ba4acc7f3244674e6d2a741dfbee1d5e03cdf392365bcbe4ba684f4592e1921143e7041e28d600b67cc1814110ac973c809bbea5c076a872092c652
6
+ metadata.gz: 70428d492aec632b0dac3d69892a202226d014c2ad35f301726d6181002d86e2d45723faf9d43cfd12690fbec6bed8b9e8577a2e0c4fe432fe1dddd3ce18020a
7
+ data.tar.gz: 7dbd303fd548964ed61e48ddd27cb8b9f3578eb3abc87beef83bae231917c613c9619e92e2085c962821651daf57e47e3c7dfef39f60c7519204546a0fbc25ff
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- decanter (3.6.0)
4
+ decanter (4.0.1)
5
5
  actionpack (>= 4.2.10)
6
6
  activesupport
7
7
  rails-html-sanitizer (>= 1.0.4)
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Decanter is a Ruby gem that makes it easy to transform incoming data before it hits the model. You can think of Decanter as the opposite of Active Model Serializers (AMS). While AMS transforms your outbound data into a format that your frontend consumes, Decanter transforms your incoming data into a format that your backend consumes.
4
4
 
5
5
  ```ruby
6
- gem 'decanter', '~> 3.0'
6
+ gem 'decanter', '~> 4.0'
7
7
  ```
8
8
 
9
9
  ## Migration Guides
@@ -7,7 +7,7 @@ module Decanter
7
7
  parser do |val, options|
8
8
  raise Decanter::ParseError.new 'Expects a single value' if val.is_a? Array
9
9
  next if (val.nil? || val === '')
10
- [1, '1'].include?(val) || !!/true/i.match(val.to_s)
10
+ [1, '1'].include?(val) || !!/^true$/i.match?(val.to_s)
11
11
  end
12
12
  end
13
13
  end
@@ -1,7 +1,7 @@
1
1
  module Decanter
2
2
  module Parser
3
3
  class FloatParser < ValueParser
4
- REGEX = /(\d|[.])/
4
+ REGEX = /(\d|[.]|[-])/
5
5
 
6
6
  allow Float, Integer
7
7
 
@@ -1,7 +1,7 @@
1
1
  module Decanter
2
2
  module Parser
3
3
  class IntegerParser < ValueParser
4
- REGEX = /(\d|[.])/
4
+ REGEX = /(\d|[.]|[-])/
5
5
 
6
6
  allow Integer
7
7
 
@@ -1,3 +1,3 @@
1
1
  module Decanter
2
- VERSION = '3.6.0'.freeze
2
+ VERSION = '4.0.1'.freeze
3
3
  end
@@ -0,0 +1,35 @@
1
+ # v4.0.0 Migration Guide
2
+
3
+ _Note: this guide assumes you are upgrading from decanter v3 to v4._
4
+
5
+ This version contains the following breaking changes:
6
+
7
+ 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.
8
+
9
+ To add a custom parser, add the new parser class to your project:
10
+
11
+ ```rb
12
+ # app/parsers/postive_float_parser.rb
13
+
14
+ class PositiveFloatParser < Decanter::Parser::ValueParser
15
+ REGEX = /(\d|[.])/
16
+
17
+ allow Float, Integer
18
+
19
+ parser do |val, options|
20
+ raise Decanter::ParseError.new 'Expects a single value' if val.is_a? Array
21
+ next if (val.nil? || val === '')
22
+ val.scan(REGEX).join.try(:to_f)
23
+ end
24
+ end
25
+ ```
26
+
27
+ Then, use the appropriate key to look up the parser in your decanter:
28
+
29
+ ```rb
30
+ # app/decanters/product_decanter.rb
31
+
32
+ class ProductDecanter < Decanter::Base
33
+ input :price, :positive_float #=> PositiveFloatParser
34
+ end
35
+ ```
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decanter
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Francis
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-09-03 00:00:00.000000000 Z
12
+ date: 2023-03-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -183,6 +183,7 @@ files:
183
183
  - lib/generators/rails/templates/decanter.rb.erb
184
184
  - lib/generators/rails/templates/parser.rb.erb
185
185
  - migration-guides/v3.0.0.md
186
+ - migration-guides/v4.0.0.md
186
187
  homepage: https://github.com/launchpadlab/decanter
187
188
  licenses:
188
189
  - MIT