decanter 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -1
- data/README.md +31 -15
- data/lib/decanter/parser/json_parser.rb +20 -0
- data/lib/decanter/version.rb +1 -1
- metadata +4 -4
- data/.tool-versions +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49997457ba8e215aaed0c30203ce4e120efbbad618c78af45c095dfc3522d369
|
4
|
+
data.tar.gz: 37ae0979906a2f10ddcd61d2c5986433cca6ec4e216cf96b54b06897819580d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5f89c5abe40751486808de512df6c651989e0f1bdf07b409a8f7ccbe86e58661411c07e388785a5774cc60309228b57b6273495335462c0e6b835b290a134e8
|
7
|
+
data.tar.gz: d632094761e6f33db6a5c8e46b58da77c14cb538f6eaf14d00461102104453b26793bb4c268403290d1fb39d60257c87da0630cd43ac5a3c6d96677f1e7ba646
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
decanter (5.
|
4
|
+
decanter (5.1.0)
|
5
5
|
actionpack (>= 7.1.3.2)
|
6
6
|
activesupport
|
7
7
|
rails (>= 7.1.3.2)
|
@@ -213,6 +213,7 @@ GEM
|
|
213
213
|
PLATFORMS
|
214
214
|
arm64-darwin-22
|
215
215
|
arm64-darwin-23
|
216
|
+
arm64-darwin-24
|
216
217
|
x86_64-linux
|
217
218
|
|
218
219
|
DEPENDENCIES
|
data/README.md
CHANGED
@@ -12,21 +12,31 @@ gem 'decanter', '~> 5.0'
|
|
12
12
|
|
13
13
|
## Contents
|
14
14
|
|
15
|
-
- [
|
16
|
-
- [
|
17
|
-
- [
|
18
|
-
- [
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
- [
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
- [
|
15
|
+
- [Decanter](#decanter)
|
16
|
+
- [Migration Guides](#migration-guides)
|
17
|
+
- [Contents](#contents)
|
18
|
+
- [Basic Usage](#basic-usage)
|
19
|
+
- [Decanters](#decanters)
|
20
|
+
- [Generators](#generators)
|
21
|
+
- [Decanters](#decanters-1)
|
22
|
+
- [Parsers](#parsers)
|
23
|
+
- [Resources](#resources)
|
24
|
+
- [Decanting Collections](#decanting-collections)
|
25
|
+
- [Control Over Decanting Collections](#control-over-decanting-collections)
|
26
|
+
- [Nested resources](#nested-resources)
|
27
|
+
- [Default parsers](#default-parsers)
|
28
|
+
- [Parser options](#parser-options)
|
29
|
+
- [Exceptions](#exceptions)
|
30
|
+
- [Advanced Usage](#advanced-usage)
|
31
|
+
- [Custom Parsers](#custom-parsers)
|
32
|
+
- [Custom parser methods](#custom-parser-methods)
|
33
|
+
- [Custom parser base classes](#custom-parser-base-classes)
|
34
|
+
- [Squashing inputs](#squashing-inputs)
|
35
|
+
- [Chaining parsers](#chaining-parsers)
|
36
|
+
- [Requiring params](#requiring-params)
|
37
|
+
- [Default values](#default-values)
|
38
|
+
- [Global configuration](#global-configuration)
|
39
|
+
- [Contributing](#contributing)
|
30
40
|
|
31
41
|
## Basic Usage
|
32
42
|
|
@@ -163,6 +173,7 @@ Decanter comes with the following parsers out of the box:
|
|
163
173
|
- `:phone`
|
164
174
|
- `:string`
|
165
175
|
- `:array`
|
176
|
+
- `:json`
|
166
177
|
|
167
178
|
Note: these parsers are designed to operate on a single value, except for `:array`. This parser expects an array, and will use the `parse_each` option to call a given parser on each of its elements:
|
168
179
|
|
@@ -170,6 +181,11 @@ Note: these parsers are designed to operate on a single value, except for `:arra
|
|
170
181
|
input :ids, :array, parse_each: :integer
|
171
182
|
```
|
172
183
|
|
184
|
+
The `:json` parser may also accept an array, but the array must be provided as a single JSON-encoded string value:
|
185
|
+
```
|
186
|
+
'["abc", "def"]'
|
187
|
+
```
|
188
|
+
|
173
189
|
### Parser options
|
174
190
|
|
175
191
|
Some parsers can receive options that modify their behavior. These options are passed in as named arguments to `input`:
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Decanter
|
2
|
+
module Parser
|
3
|
+
class JsonParser < ValueParser
|
4
|
+
|
5
|
+
parser do |val, options|
|
6
|
+
next if val.nil? || val === ''
|
7
|
+
raise Decanter::ParseError.new 'Expects a JSON string' unless val.is_a?(String)
|
8
|
+
parse_json(val)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.parse_json(val)
|
12
|
+
begin
|
13
|
+
JSON.parse(val)
|
14
|
+
rescue
|
15
|
+
raise Decanter::ParseError.new 'Invalid JSON string'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/decanter/version.rb
CHANGED
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: 5.
|
4
|
+
version: 5.1.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: 2025-
|
12
|
+
date: 2025-08-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -154,7 +154,6 @@ files:
|
|
154
154
|
- ".gitignore"
|
155
155
|
- ".rspec"
|
156
156
|
- ".ruby-version"
|
157
|
-
- ".tool-versions"
|
158
157
|
- ".travis.yml"
|
159
158
|
- CODE_OF_CONDUCT.md
|
160
159
|
- CONTRIBUTING.md
|
@@ -184,6 +183,7 @@ files:
|
|
184
183
|
- lib/decanter/parser/float_parser.rb
|
185
184
|
- lib/decanter/parser/hash_parser.rb
|
186
185
|
- lib/decanter/parser/integer_parser.rb
|
186
|
+
- lib/decanter/parser/json_parser.rb
|
187
187
|
- lib/decanter/parser/pass_parser.rb
|
188
188
|
- lib/decanter/parser/phone_parser.rb
|
189
189
|
- lib/decanter/parser/string_parser.rb
|
@@ -221,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: '0'
|
223
223
|
requirements: []
|
224
|
-
rubygems_version: 3.5.
|
224
|
+
rubygems_version: 3.5.3
|
225
225
|
signing_key:
|
226
226
|
specification_version: 4
|
227
227
|
summary: Form Parser for Rails
|
data/.tool-versions
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby 3.3.5
|