decanter 3.4.2 → 3.5.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 +5 -1
- data/lib/decanter/core.rb +14 -6
- data/lib/decanter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47761a57539196c1be8d4de3b4f18a78a0e133bdace720e4363dfc2a4ab5776c
|
4
|
+
data.tar.gz: caccc39b0926d5f39a29673a912fab356079fb67357b868cc4f803b325988890
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7ee0004606f84e64e0b94697d1ff035f54b96ceb3dddc1f0a77c716ad17c566b9b959f78a67cfa6c40598c337db4464c62c26d2d394a749183bec915cad3d44
|
7
|
+
data.tar.gz: 6aecb9eb64b1bd282de2d29a3828fe131fa01227c50b8b5ff69049cb08184497435d9f67ab95f71dacf8120e072ff813b00dac497e81772396f249b0e8a74327
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -144,7 +144,11 @@ input :start_date, :date, parse_format: '%Y-%m-%d'
|
|
144
144
|
|
145
145
|
### Exceptions
|
146
146
|
|
147
|
-
By default, `Decanter#decant` will raise an exception when unexpected parameters are passed. To override this behavior, you can
|
147
|
+
By default, `Decanter#decant` will raise an exception when unexpected parameters are passed. To override this behavior, you can change the strict mode option to one of:
|
148
|
+
|
149
|
+
- `true` (default): unhandled keys will raise an unexpected parameters exception
|
150
|
+
- `false`: all parameter key-value pairs will be included in the result
|
151
|
+
- `:ignore`: unhandled keys will be excluded from the decanted result
|
148
152
|
|
149
153
|
```ruby
|
150
154
|
class TripDecanter < Decanter::Base
|
data/lib/decanter/core.rb
CHANGED
@@ -50,7 +50,7 @@ module Decanter
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def strict(mode)
|
53
|
-
raise(ArgumentError, "#{self.name}: Unknown strict value #{mode}") unless [true, false].include? mode
|
53
|
+
raise(ArgumentError, "#{self.name}: Unknown strict value #{mode}") unless [:ignore, true, false].include? mode
|
54
54
|
@strict_mode = mode
|
55
55
|
end
|
56
56
|
|
@@ -71,8 +71,9 @@ module Decanter
|
|
71
71
|
.map { |input| [input[:key], input[:options][DEFAULT_VALUE_KEY]] }
|
72
72
|
.to_h
|
73
73
|
|
74
|
-
# parse default values
|
75
|
-
handled_keys
|
74
|
+
# parse handled default values, including keys
|
75
|
+
# with defaults not already managed by handled_keys
|
76
|
+
default_result.merge(handled_keys(default_result))
|
76
77
|
end
|
77
78
|
|
78
79
|
def default_value_inputs
|
@@ -121,14 +122,21 @@ module Decanter
|
|
121
122
|
.map { |handler| "#{handler[:name]}_attributes".to_sym }
|
122
123
|
|
123
124
|
return {} unless unhandled_keys.any?
|
124
|
-
|
125
|
-
|
125
|
+
|
126
|
+
case strict_mode
|
127
|
+
when :ignore
|
128
|
+
p "#{self.name} ignoring unhandled keys: #{unhandled_keys.join(', ')}."
|
129
|
+
{}
|
130
|
+
when true
|
131
|
+
raise(UnhandledKeysError, "#{self.name} received unhandled keys: #{unhandled_keys.join(', ')}.")
|
132
|
+
else
|
133
|
+
args.select { |key| unhandled_keys.include? key.to_sym }
|
134
|
+
end
|
126
135
|
end
|
127
136
|
|
128
137
|
def handled_keys(args)
|
129
138
|
arg_keys = args.keys.map(&:to_sym)
|
130
139
|
inputs, assocs = handlers.values.partition { |handler| handler[:type] == :input }
|
131
|
-
|
132
140
|
{}.merge(
|
133
141
|
# Inputs
|
134
142
|
inputs.select { |handler| (arg_keys & handler[:name]).any? }
|
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: 3.
|
4
|
+
version: 3.5.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-01-
|
12
|
+
date: 2021-01-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|