simple_params 1.6.5 → 1.6.8

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YWNlZDM0YjZkNWQxNjhhOGRjZDJjMWJiMzBiMTU1NGQ3ZjljNTZmMQ==
4
+ ZTgwM2FiZTg2YTJlYjdhY2VlM2UwZjk1YzMwOWIyODE1NTEzNzQ2Yg==
5
5
  data.tar.gz: !binary |-
6
- MTExMDdjMmE1MWJkOWEzNWJkOWEyOTg5MThmMWQ5ZTNhNjRiY2U5YQ==
6
+ NDE5Y2Y2YTIxODA5ODAyNmZlNjY2ZmFiODcxMDZhM2E4ODM5ODY1NQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YmY4ZDg1NjFjNDYxNTBjZGRhNDhkMTBjNGI3Y2RmOTEyZWExYWVjZmQ0OWQz
10
- YTBiNzBhMjY4N2NlYzgyNmQwNTg0MjQxZGNkMmU5ZDNkOWI5MDhiY2VhZTg3
11
- ZmE5MTYxMThjNWU1OTBiZTk2MGVkNTJiZjBlNzNiYWIyM2YxN2Y=
9
+ NmYwNjU4YmNlZWI0NjMzNjQ3YWY2OWI1MDE1Zjg1ZjU4ZjFjMGFjNWM1OTQ3
10
+ ZjljZjgyNDEwMGE4MzQ1NmUxYzU1NGJlYjc0NTRhY2ViZjQ5YTc4ODVjMWYw
11
+ MThkZmQ3ZTk2ZDEzZjViYWU4OGMxNjhkZjk4ODJkMGU5M2E1ZTA=
12
12
  data.tar.gz: !binary |-
13
- ZjVkZTVmNWRlZWJmNzVhOWI3ZWE5NDllMDg2NGZlZWQzYWJlMmFiZTlkOTc1
14
- NWJhZTdjNGE2MTQ4NDk5YjdhZTFiYjlhOTc4OWYyZTg2Y2EzNjg2Y2U5ZDFm
15
- ZDJiZmFkNGVlZmU3OGU4MzU0NTczYjZmNjg0NjU5YTEwYTA1OWQ=
13
+ NDkzZWZmN2Y2MTYzNWM0ZWJmMWZiNTdjN2E0NjI3MTdlOGI2ZDI1ODgzM2Yz
14
+ NGNkNTkyYWY0ZDdkMWZlYTBhOTYxOThkMGQ1ZTQwMzExNzcxNGNlZDUyY2E0
15
+ ZmQ4YmQzNTRlZTEwMmNiZGMxZjA2ZWEzODMyNDgyOTMyNDcyZmI=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_params (1.6.4)
4
+ simple_params (1.6.7)
5
5
  activemodel (>= 3.0, < 5.0)
6
6
  shoulda-matchers (~> 2.8)
7
7
  virtus (>= 1.0.0)
@@ -9,10 +9,10 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activemodel (4.2.1)
13
- activesupport (= 4.2.1)
12
+ activemodel (4.2.6)
13
+ activesupport (= 4.2.6)
14
14
  builder (~> 3.1)
15
- activesupport (4.2.1)
15
+ activesupport (4.2.6)
16
16
  i18n (~> 0.7)
17
17
  json (~> 1.7, >= 1.7.7)
18
18
  minitest (~> 5.1)
@@ -31,10 +31,10 @@ GEM
31
31
  diff-lcs (1.2.5)
32
32
  equalizer (0.0.11)
33
33
  i18n (0.7.0)
34
- ice_nine (0.11.1)
35
- json (1.8.2)
34
+ ice_nine (0.11.2)
35
+ json (1.8.3)
36
36
  method_source (0.8.2)
37
- minitest (5.6.0)
37
+ minitest (5.9.0)
38
38
  pry (0.10.1)
39
39
  coderay (~> 1.1.0)
40
40
  method_source (~> 0.8.1)
@@ -69,3 +69,6 @@ DEPENDENCIES
69
69
  rake (~> 10.1)
70
70
  rspec (~> 2.6)
71
71
  simple_params!
72
+
73
+ BUNDLED WITH
74
+ 1.12.5
@@ -30,6 +30,14 @@ module SimpleParams
30
30
  end
31
31
 
32
32
  def add_validations(name, opts = {})
33
+
34
+ conditional_validation = opts.fetch(:validations, {}).fetch(:if, nil)
35
+
36
+ if conditional_validation
37
+ opts[:optional] = false
38
+ opts[:validations].delete(:if)
39
+ end
40
+
33
41
  validations = ValidationBuilder.new(opts).build
34
42
  validates name, validations unless validations.empty?
35
43
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleParams
2
- VERSION = "1.6.5"
2
+ VERSION = "1.6.8"
3
3
  end
@@ -9,7 +9,7 @@ class DummyParams < SimpleParams::Params
9
9
  nested_hash :address do
10
10
  string_param :street
11
11
  string_param :city, validations: { length: { in: 4..40 } }
12
- string_param :zip_code, optional: true, validations: { length: { in: 5..9 } }
12
+ string_param :zip_code, optional: true, validations: { length: { in: 5..9 }, if: true }
13
13
  param :state, default: "North Carolina", formatter: :transform_state_code
14
14
 
15
15
  def transform_state_code(val)
data/spec/params_spec.rb CHANGED
@@ -443,7 +443,7 @@ describe SimpleParams::Params do
443
443
  param :address, Hash, desc: '', required: true do
444
444
  param :street, String, desc: '', required: true
445
445
  param :city, String, desc: '', required: true
446
- param :zip_code, String, desc: '', required: false
446
+ param :zip_code, String, desc: '', required: true
447
447
  param :state, String, desc: '', required: false
448
448
  end
449
449
  param :phone, Hash, desc: '', required: true do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_params
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.5
4
+ version: 1.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - brycesenz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-04 00:00:00.000000000 Z
11
+ date: 2016-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -204,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
204
  version: '0'
205
205
  requirements: []
206
206
  rubyforge_project:
207
- rubygems_version: 2.4.6
207
+ rubygems_version: 2.4.8
208
208
  signing_key:
209
209
  specification_version: 4
210
210
  summary: A DSL for specifying params, including type coercion and validation