simple_params 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile.lock +1 -1
- data/lib/simple_params.rb +1 -0
- data/lib/simple_params/params.rb +8 -1
- data/lib/simple_params/validation_matchers/nested_array_matcher.rb +36 -0
- data/lib/simple_params/version.rb +1 -1
- data/spec/acceptance_spec.rb +19 -2
- data/spec/validation_matchers/nested_array_matcher_spec.rb +17 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDJjYTQ5MTFmNzEyZmRlYjViMjQyZDY5YzlmNDQ2ZmJiYzU4ZjQyNg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjYwZTM3OWE3ZjczODI3NzM5YzhhODFiYzU3ZDA5NTRjYTdkZWU4Mg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjVlNjMxNDlkZTkwOTdiYTllZTg4MGRmYTZhYTE1OWIzN2Y5NjMzNmE0NzUy
|
10
|
+
YzQ2YjM4NGM2ZDc2OTAxNjc2NmU3MjA5YTQzMGI5ZWUyYzU4MDQ0NDhiMDcw
|
11
|
+
MmI2Mjg0ZWI3ZDEzOTY1ZGJmMWQyYzI3ZTA1OWJmYzc1Mzk1N2Q=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NWQxMzE3ZjRlNDM3MmQ0NzU3MmY5NzRjN2Y4Zjk4YzYzZTQxNTc0MWM2ZDgx
|
14
|
+
NTliYjIyYTkxMDY4MzE2MGVkZTdmYThmMmQwYmEwMTUwMjIyYThkMzdlZGU4
|
15
|
+
ZWZiMzBmYjQyOGRhYWNhNTIwYzAwMjM0NzQ3MzhhY2Y5NmZmMTI=
|
data/Gemfile.lock
CHANGED
data/lib/simple_params.rb
CHANGED
@@ -14,6 +14,7 @@ require 'simple_params/api_pie_doc/nested_attribute'
|
|
14
14
|
require 'simple_params/validation_matchers/validation_matcher'
|
15
15
|
require 'simple_params/validation_matchers/coercion_matcher'
|
16
16
|
require 'simple_params/validation_matchers/format_matcher'
|
17
|
+
require 'simple_params/validation_matchers/nested_array_matcher'
|
17
18
|
require 'simple_params/validation_matchers/nested_parameter_matcher'
|
18
19
|
require 'simple_params/validation_matchers/required_parameter_matcher'
|
19
20
|
require 'simple_params/validation_matchers/optional_parameter_matcher'
|
data/lib/simple_params/params.rb
CHANGED
@@ -169,8 +169,15 @@ module SimpleParams
|
|
169
169
|
def to_hash
|
170
170
|
hash = {}
|
171
171
|
attributes.each do |attribute|
|
172
|
-
|
172
|
+
raw_attribute = send(attribute)
|
173
|
+
if raw_attribute.is_a?(SimpleParams::Params)
|
173
174
|
hash[attribute] = send(attribute).to_hash
|
175
|
+
elsif raw_attribute.is_a?(Array)
|
176
|
+
attribute_array = []
|
177
|
+
raw_attribute.each do |r_attr|
|
178
|
+
attribute_array << r_attr.to_hash
|
179
|
+
end
|
180
|
+
hash[attribute] = attribute_array
|
174
181
|
else
|
175
182
|
hash[attribute] = send(attribute)
|
176
183
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module SimpleParams
|
2
|
+
module ValidationMatchers
|
3
|
+
def have_nested_array(attr)
|
4
|
+
NestedArrayMatcher.new(attr)
|
5
|
+
end
|
6
|
+
|
7
|
+
class NestedArrayMatcher < ValidationMatcher
|
8
|
+
attr_accessor :attribute
|
9
|
+
|
10
|
+
def initialize(attribute)
|
11
|
+
super(attribute)
|
12
|
+
@attribute = attribute
|
13
|
+
end
|
14
|
+
|
15
|
+
def matches?(subject)
|
16
|
+
super(subject)
|
17
|
+
subject.send(:nested_arrays).has_key?(@attribute)
|
18
|
+
end
|
19
|
+
|
20
|
+
def description
|
21
|
+
"Should have nested array #{@attribute}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def failure_message_for_should
|
25
|
+
"Should have nested array #{@attribute}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def failure_message_for_should_not
|
29
|
+
"Should not have nested array #{@attribute}"
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/acceptance_spec.rb
CHANGED
@@ -59,7 +59,19 @@ describe SimpleParams::Params do
|
|
59
59
|
|
60
60
|
describe "to_hash", to_hash: true do
|
61
61
|
it "returns params hash" do
|
62
|
-
params = AcceptanceParams.new(
|
62
|
+
params = AcceptanceParams.new(
|
63
|
+
name: "Tom",
|
64
|
+
address: {
|
65
|
+
"street" => "1 Main St."
|
66
|
+
},
|
67
|
+
dogs: [
|
68
|
+
{
|
69
|
+
name: "Spot",
|
70
|
+
age: 8
|
71
|
+
}
|
72
|
+
]
|
73
|
+
)
|
74
|
+
|
63
75
|
params.to_hash.should eq({
|
64
76
|
reference: nil,
|
65
77
|
name: "Tom",
|
@@ -73,7 +85,12 @@ describe SimpleParams::Params do
|
|
73
85
|
state: "North Carolina",
|
74
86
|
company: nil
|
75
87
|
},
|
76
|
-
dogs: [
|
88
|
+
dogs: [
|
89
|
+
{
|
90
|
+
name: "Spot",
|
91
|
+
age: 8
|
92
|
+
}
|
93
|
+
]
|
77
94
|
})
|
78
95
|
end
|
79
96
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SimpleParams::ValidationMatchers::NestedArrayMatcher do
|
4
|
+
class NestedArrayMatcherTestClass < SimpleParams::Params
|
5
|
+
param :name
|
6
|
+
param :age, optional: true, default: 37
|
7
|
+
nested_array :dogs do
|
8
|
+
param :name
|
9
|
+
param :age, type: :integer
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
subject { NestedArrayMatcherTestClass.new }
|
14
|
+
|
15
|
+
it { should have_nested_array(:dogs) }
|
16
|
+
it { should_not have_nested_array(:broken) }
|
17
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- brycesenz
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- lib/simple_params/type_mappings.rb
|
142
142
|
- lib/simple_params/validation_matchers/coercion_matcher.rb
|
143
143
|
- lib/simple_params/validation_matchers/format_matcher.rb
|
144
|
+
- lib/simple_params/validation_matchers/nested_array_matcher.rb
|
144
145
|
- lib/simple_params/validation_matchers/nested_parameter_matcher.rb
|
145
146
|
- lib/simple_params/validation_matchers/optional_parameter_matcher.rb
|
146
147
|
- lib/simple_params/validation_matchers/required_parameter_matcher.rb
|
@@ -163,6 +164,7 @@ files:
|
|
163
164
|
- spec/support/shared_examples/base_attribute.rb
|
164
165
|
- spec/validation_matchers/coercion_matcher_spec.rb
|
165
166
|
- spec/validation_matchers/format_matcher_spec.rb
|
167
|
+
- spec/validation_matchers/nested_array_matcher_spec.rb
|
166
168
|
- spec/validation_matchers/nested_parameter_matcher_spec.rb
|
167
169
|
- spec/validation_matchers/optional_parameter_matcher_spec.rb
|
168
170
|
- spec/validation_matchers/required_parameter_matcher_spec.rb
|
@@ -206,6 +208,7 @@ test_files:
|
|
206
208
|
- spec/support/shared_examples/base_attribute.rb
|
207
209
|
- spec/validation_matchers/coercion_matcher_spec.rb
|
208
210
|
- spec/validation_matchers/format_matcher_spec.rb
|
211
|
+
- spec/validation_matchers/nested_array_matcher_spec.rb
|
209
212
|
- spec/validation_matchers/nested_parameter_matcher_spec.rb
|
210
213
|
- spec/validation_matchers/optional_parameter_matcher_spec.rb
|
211
214
|
- spec/validation_matchers/required_parameter_matcher_spec.rb
|