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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c49220d0b25ab5f09d58aded4f247e71793d1f98129efebe336651c1e58303dd
4
- data.tar.gz: b28b971df1dba14570abfcb9cb6116e13512afcb3412656be1c169af1ecef69a
3
+ metadata.gz: 47761a57539196c1be8d4de3b4f18a78a0e133bdace720e4363dfc2a4ab5776c
4
+ data.tar.gz: caccc39b0926d5f39a29673a912fab356079fb67357b868cc4f803b325988890
5
5
  SHA512:
6
- metadata.gz: 911b7de4eaf39749fbb1029016e00da3d72a7b0f46d828d6c1d9f9f49f945c51ab91bbefc4ef2fd45b1e69e2d488ec07b09358c29a5009d7222122047cf24785
7
- data.tar.gz: 6acdf1923faec6984bb42884c47afb0574f94b65a12c1275953eb583c61a77b860074b3ef7b03bd157f3fa37e10fea8abf6bd358872fdce3dc614f3d16626323
6
+ metadata.gz: d7ee0004606f84e64e0b94697d1ff035f54b96ceb3dddc1f0a77c716ad17c566b9b959f78a67cfa6c40598c337db4464c62c26d2d394a749183bec915cad3d44
7
+ data.tar.gz: 6aecb9eb64b1bd282de2d29a3828fe131fa01227c50b8b5ff69049cb08184497435d9f67ab95f71dacf8120e072ff813b00dac497e81772396f249b0e8a74327
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- decanter (3.4.2)
4
+ decanter (3.5.0)
5
5
  actionpack (>= 4.2.10)
6
6
  activesupport
7
7
  rails-html-sanitizer (>= 1.0.4)
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 disable strict mode:
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
@@ -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(default_result)
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
- raise(UnhandledKeysError, "#{self.name} received unhandled keys: #{unhandled_keys.join(', ')}.") if strict_mode
125
- args.select { |key| unhandled_keys.include? key.to_sym }
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? }
@@ -1,3 +1,3 @@
1
1
  module Decanter
2
- VERSION = '3.4.2'.freeze
2
+ VERSION = '3.5.0'.freeze
3
3
  end
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.2
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-05 00:00:00.000000000 Z
12
+ date: 2021-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack