decanter 3.6.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/decanter/parser/float_parser.rb +1 -1
- data/lib/decanter/parser/integer_parser.rb +1 -1
- data/lib/decanter/version.rb +1 -1
- data/migration-guides/v4.0.0.md +35 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa10b029acfb863227bd9b42b915f32ce94d65dd0a82955bc13b530d3278fe87
|
4
|
+
data.tar.gz: c22c844568de79508809ceb5609e8166cc547bfc26fa4a293085baae56ce6ade
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1df6bc91a47bc1dbbf9a528b895407fed1d84cdf733121aff44440d03b4fe82a8871143d1b2d0bb87b6c9cfb1467c0a839cb394ac0bd813e5df7230faa00b9a4
|
7
|
+
data.tar.gz: 9e26fe9068e2f58d4ae8b1987a05fde413e9edac2bd0f123add82c7dfcb18f50a9d08629b71fb2c1d2d0387668f32ecfc53bda6a7e5a93d07289d96f8bbc5eaf
|
data/Gemfile.lock
CHANGED
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', '~>
|
6
|
+
gem 'decanter', '~> 4.0'
|
7
7
|
```
|
8
8
|
|
9
9
|
## Migration Guides
|
data/lib/decanter/version.rb
CHANGED
@@ -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:
|
4
|
+
version: 4.0.0
|
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-
|
12
|
+
date: 2021-11-23 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
|