decanter 0.8.1 → 0.8.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 131816782f1a7b858d71bbf5f1a4d53b97172522
4
- data.tar.gz: 2931a7585f5d4765878c7d122c24479b48dd2ee7
3
+ metadata.gz: 99d5bfae4e2f4ed374e9851fd07d53d524963349
4
+ data.tar.gz: ad634273515df9853b3566948a1dcf61884d5b80
5
5
  SHA512:
6
- metadata.gz: 3967922ec16bfaf59298e80970b3f0319fc39115a05776b8f6f9d6c99f824420acc2cfd72d2768bec0483597ac1913dcf9929ae946bf5f4381abc442ff9cc9e0
7
- data.tar.gz: 58810234000908bf2ac966e20c1ec41f90bb85753a7d0c86a7cccab52faf72f41547ee16d2ca6caff520546df50cf21b14778d573adfb69cc36dc6d59b5301df
6
+ metadata.gz: 09420cff51f63c0971a7dc1651b27078d209588f65373608c3be654dbea9bfad1d4ef0727b7170c8aa9bf65d271220c396e7d0f0ed01c028ccb64d2e3e1ec9b0
7
+ data.tar.gz: 03dd595cc9e0f01ca5963d8fdb88763300990a018ec639c7d093bd6098d1fb18c6e7ffde8a07c663adc911d43ab7a54cddb1f5b66c371b0aaaf0fccaf97e00b1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- decanter (0.8.0)
4
+ decanter (0.8.1)
5
5
  activesupport
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -384,7 +384,7 @@ Chaining Parsers
384
384
  Parsers are composable! Suppose you want a parser that takes an incoming percentage like "50.3%" and converts it into a float for your database like .503. You could implement this with:
385
385
 
386
386
  ```ruby
387
- class PercentParser < ValueParser
387
+ class PercentParser < Decanter::Parser::ValueParser
388
388
  REGEX = /(\d|[.])/
389
389
 
390
390
  parser do |val, options|
@@ -397,7 +397,7 @@ end
397
397
  This works, but it duplicates logic that already exists in `FloatParser`. Instead, you can specify a parser that should always run before your parsing logic, then you can assume that your parser receives a float:
398
398
 
399
399
  ```ruby
400
- class SmartPercentParser < ValueParser
400
+ class SmartPercentParser < Decanter::Parser::ValueParser
401
401
 
402
402
  pre :float
403
403
 
data/lib/decanter/core.rb CHANGED
@@ -50,6 +50,7 @@ module Decanter
50
50
  end
51
51
 
52
52
  def decant(args)
53
+ return {} unless args.present?
53
54
  args = args.to_unsafe_h.with_indifferent_access if args.class.name == 'ActionController::Parameters'
54
55
  {}.merge( unhandled_keys(args) )
55
56
  .merge( handled_keys(args) )
@@ -11,7 +11,7 @@ module Decanter
11
11
  # Check if allowed, parse if not
12
12
  def parse(name, values, options={})
13
13
  case
14
- when allowed?(values)
14
+ when allowed?(values) || empty_values?(values)
15
15
  { name => values }
16
16
  else
17
17
  _parse(name, values, options)
@@ -44,6 +44,10 @@ module Decanter
44
44
  @allowed.any? { |allowed| value.is_a? allowed }
45
45
  end
46
46
  end
47
+
48
+ def empty_values?(values)
49
+ return true if Array.wrap(values).all? { |value| value.nil? || value == "" }
50
+ end
47
51
  end
48
52
  end
49
53
  end
@@ -1,3 +1,3 @@
1
1
  module Decanter
2
- VERSION = '0.8.1'
2
+ VERSION = '0.8.2'
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: 0.8.1
4
+ version: 0.8.2
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: 2016-06-23 00:00:00.000000000 Z
12
+ date: 2016-08-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport