decanter 3.5.1 → 3.6.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: f191e5daf97acca13c721c2ddca506a38919433f2207d2cecb59433b463dbea7
4
- data.tar.gz: 579ec81e38550f980c0e1fe96e2db9bcf50d4c99b2a52d48ab875a8970bc2c07
3
+ metadata.gz: 697f969bd6cdcac1487d237135cd4f1860ff9aa79abece975305d7ca7f0d5504
4
+ data.tar.gz: 7ab9d647d3c90e9c5186f4f0b486115b3d17f3107990a7984827d87e2f4843f8
5
5
  SHA512:
6
- metadata.gz: b642637b676156b1e3f9783ceab09a5e9e8f6bf8ebf6c76e4c3ee292b95c59396bd62eb8ba6bf6ad296a5c5d116e3e25dc847a5c65da2ab7f2a443f482e6c3e5
7
- data.tar.gz: 628ea27143c5ac74c97d141c67fbecedd99c51ac68f565d2677e15e250098848bb99c986e7d2f92809f09bd5008c1b41991d7c7f73bc97edc64b772f54fc494e
6
+ metadata.gz: 286e79ac8ebdbd3b75cc667fadd77b2fc6966f54274f06e282fc9d94250cf3075eb2f6a9e31295f1d51efb50b1b5757507de98cc6816a23b9871af7c3e32ab2a
7
+ data.tar.gz: b4cfff1c6ba4acc7f3244674e6d2a741dfbee1d5e03cdf392365bcbe4ba684f4592e1921143e7041e28d600b67cc1814110ac973c809bbea5c076a872092c652
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- decanter (3.5.1)
4
+ decanter (3.6.0)
5
5
  actionpack (>= 4.2.10)
6
6
  activesupport
7
7
  rails-html-sanitizer (>= 1.0.4)
data/README.md CHANGED
@@ -280,11 +280,14 @@ TripDecanter.decant({ name: 'Vacation 2020' })
280
280
 
281
281
  You can generate a local copy of the default configuration with `rails generate decanter:install`. This will create an initializer where you can do global configuration:
282
282
 
283
+ Setting strict mode to :ignore will log out any unhandled keys. To avoid excessive logging, the global configuration can be set to `log_unhandled_keys = false`
284
+
283
285
  ```ruby
284
286
  # ./config/initializers/decanter.rb
285
287
 
286
288
  Decanter.config do |config|
287
289
  config.strict = false
290
+ config.log_unhandled_keys = false
288
291
  end
289
292
  ```
290
293
 
@@ -1,10 +1,11 @@
1
1
  module Decanter
2
2
  class Configuration
3
3
 
4
- attr_accessor :strict
4
+ attr_accessor :strict, :log_unhandled_keys
5
5
 
6
6
  def initialize
7
7
  @strict = true
8
+ @log_unhandled_keys = true
8
9
  end
9
10
  end
10
11
  end
data/lib/decanter/core.rb CHANGED
@@ -54,6 +54,11 @@ module Decanter
54
54
  @strict_mode = mode
55
55
  end
56
56
 
57
+ def log_unhandled_keys(mode)
58
+ raise(ArgumentError, "#{self.name}: Unknown log_unhandled_keys value #{mode}") unless [true, false].include? mode
59
+ @log_unhandled_keys_mode = mode
60
+ end
61
+
57
62
  def decant(args)
58
63
  return handle_empty_args if args.blank?
59
64
  return empty_required_input_error unless required_input_keys_present?(args)
@@ -125,7 +130,7 @@ module Decanter
125
130
 
126
131
  case strict_mode
127
132
  when :ignore
128
- p "#{self.name} ignoring unhandled keys: #{unhandled_keys.join(', ')}."
133
+ p "#{self.name} ignoring unhandled keys: #{unhandled_keys.join(', ')}." if log_unhandled_keys_mode
129
134
  {}
130
135
  when true
131
136
  raise(UnhandledKeysError, "#{self.name} received unhandled keys: #{unhandled_keys.join(', ')}.")
@@ -229,6 +234,11 @@ module Decanter
229
234
  @strict_mode.nil? ? Decanter.configuration.strict : @strict_mode
230
235
  end
231
236
 
237
+ def log_unhandled_keys_mode
238
+ return !!(Decanter.configuration.log_unhandled_keys) if @log_unhandled_keys_mode.nil?
239
+ !!@log_unhandled_keys_mode
240
+ end
241
+
232
242
  # Helpers
233
243
 
234
244
  private
@@ -1,3 +1,3 @@
1
1
  module Decanter
2
- VERSION = '3.5.1'.freeze
2
+ VERSION = '3.6.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.5.1
4
+ version: 3.6.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-04-13 00:00:00.000000000 Z
12
+ date: 2021-09-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack