simple_params 1.1.2 → 1.2.0
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 +8 -8
- data/Gemfile.lock +1 -1
- data/lib/simple_params/api_pie_doc/nested_attribute.rb +8 -1
- data/lib/simple_params/api_pie_doc.rb +7 -22
- data/lib/simple_params/attribute.rb +2 -6
- data/lib/simple_params/concerns/date_time_helpers.rb +68 -0
- data/lib/simple_params/concerns/has_attributes.rb +68 -0
- data/lib/simple_params/concerns/has_typed_params.rb +30 -0
- data/lib/simple_params/concerns/hash_helpers.rb +27 -0
- data/lib/simple_params/concerns/rails_helpers.rb +33 -0
- data/lib/simple_params/concerns/strict_params.rb +68 -0
- data/lib/simple_params/concerns/validations.rb +41 -0
- data/lib/simple_params/errors.rb +57 -49
- data/lib/simple_params/nested_params.rb +73 -0
- data/lib/simple_params/params.rb +59 -277
- data/lib/simple_params/validation_matchers/nested_array_matcher.rb +2 -1
- data/lib/simple_params/validation_matchers/nested_parameter_matcher.rb +2 -1
- data/lib/simple_params/version.rb +1 -1
- data/lib/simple_params.rb +8 -2
- data/spec/api_pie_doc_spec.rb +7 -20
- data/spec/errors_spec.rb +33 -10
- data/spec/nested_params_spec.rb +193 -0
- data/spec/params_spec.rb +15 -0
- data/spec/rails_integration_spec.rb +70 -0
- metadata +14 -6
- data/lib/simple_params/api_pie_doc/nested_array.rb +0 -31
- data/lib/simple_params/validations.rb +0 -41
- data/spec/api_pie_doc/nested_array_spec.rb +0 -46
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.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- brycesenz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -131,11 +131,18 @@ files:
|
|
131
131
|
- lib/simple_params/api_pie_doc.rb
|
132
132
|
- lib/simple_params/api_pie_doc/attribute.rb
|
133
133
|
- lib/simple_params/api_pie_doc/attribute_base.rb
|
134
|
-
- lib/simple_params/api_pie_doc/nested_array.rb
|
135
134
|
- lib/simple_params/api_pie_doc/nested_attribute.rb
|
136
135
|
- lib/simple_params/attribute.rb
|
136
|
+
- lib/simple_params/concerns/date_time_helpers.rb
|
137
|
+
- lib/simple_params/concerns/has_attributes.rb
|
138
|
+
- lib/simple_params/concerns/has_typed_params.rb
|
139
|
+
- lib/simple_params/concerns/hash_helpers.rb
|
140
|
+
- lib/simple_params/concerns/rails_helpers.rb
|
141
|
+
- lib/simple_params/concerns/strict_params.rb
|
142
|
+
- lib/simple_params/concerns/validations.rb
|
137
143
|
- lib/simple_params/errors.rb
|
138
144
|
- lib/simple_params/formatter.rb
|
145
|
+
- lib/simple_params/nested_params.rb
|
139
146
|
- lib/simple_params/params.rb
|
140
147
|
- lib/simple_params/simple_params_error.rb
|
141
148
|
- lib/simple_params/type_mappings.rb
|
@@ -146,12 +153,10 @@ files:
|
|
146
153
|
- lib/simple_params/validation_matchers/optional_parameter_matcher.rb
|
147
154
|
- lib/simple_params/validation_matchers/required_parameter_matcher.rb
|
148
155
|
- lib/simple_params/validation_matchers/validation_matcher.rb
|
149
|
-
- lib/simple_params/validations.rb
|
150
156
|
- lib/simple_params/version.rb
|
151
157
|
- simple_params.gemspec
|
152
158
|
- spec/acceptance_spec.rb
|
153
159
|
- spec/api_pie_doc/attribute_spec.rb
|
154
|
-
- spec/api_pie_doc/nested_array_spec.rb
|
155
160
|
- spec/api_pie_doc/nested_attribute_spec.rb
|
156
161
|
- spec/api_pie_doc_spec.rb
|
157
162
|
- spec/attribute_spec.rb
|
@@ -160,7 +165,9 @@ files:
|
|
160
165
|
- spec/fixtures/validator_params.rb
|
161
166
|
- spec/formatter_spec.rb
|
162
167
|
- spec/multiple_classes_spec.rb
|
168
|
+
- spec/nested_params_spec.rb
|
163
169
|
- spec/params_spec.rb
|
170
|
+
- spec/rails_integration_spec.rb
|
164
171
|
- spec/spec_helper.rb
|
165
172
|
- spec/support/shared_examples/base_attribute.rb
|
166
173
|
- spec/validation_matchers/coercion_matcher_spec.rb
|
@@ -196,7 +203,6 @@ summary: A DSL for specifying params, including type coercion and validation
|
|
196
203
|
test_files:
|
197
204
|
- spec/acceptance_spec.rb
|
198
205
|
- spec/api_pie_doc/attribute_spec.rb
|
199
|
-
- spec/api_pie_doc/nested_array_spec.rb
|
200
206
|
- spec/api_pie_doc/nested_attribute_spec.rb
|
201
207
|
- spec/api_pie_doc_spec.rb
|
202
208
|
- spec/attribute_spec.rb
|
@@ -205,7 +211,9 @@ test_files:
|
|
205
211
|
- spec/fixtures/validator_params.rb
|
206
212
|
- spec/formatter_spec.rb
|
207
213
|
- spec/multiple_classes_spec.rb
|
214
|
+
- spec/nested_params_spec.rb
|
208
215
|
- spec/params_spec.rb
|
216
|
+
- spec/rails_integration_spec.rb
|
209
217
|
- spec/spec_helper.rb
|
210
218
|
- spec/support/shared_examples/base_attribute.rb
|
211
219
|
- spec/validation_matchers/coercion_matcher_spec.rb
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module SimpleParams
|
2
|
-
class ApiPieDoc::NestedArray < ApiPieDoc::AttributeBase
|
3
|
-
|
4
|
-
attr_accessor :attributes
|
5
|
-
|
6
|
-
def initialize(simple_params_array)
|
7
|
-
super
|
8
|
-
self.attributes = attribute.values[0].map { |attribute| ApiPieDoc::Attribute.new(attribute) }
|
9
|
-
self.options ||= attribute.delete(:options) || attribute[1]
|
10
|
-
end
|
11
|
-
|
12
|
-
def name
|
13
|
-
attribute.keys.first.to_s
|
14
|
-
end
|
15
|
-
|
16
|
-
def to_s
|
17
|
-
return nil if do_not_document?
|
18
|
-
nested_description
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def nested_description
|
24
|
-
start = "param :#{name}, Array, #{description}, #{requirement_description} do"
|
25
|
-
attribute_descriptors = []
|
26
|
-
attributes.each { |attribute| attribute_descriptors << attribute.to_s }
|
27
|
-
finish = "end"
|
28
|
-
[start, attribute_descriptors, finish].flatten.join("\n")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require "active_model"
|
2
|
-
|
3
|
-
module SimpleParams
|
4
|
-
module Validations
|
5
|
-
extend ActiveModel::Validations
|
6
|
-
|
7
|
-
# Overriding #valid? to provide recursive validating of
|
8
|
-
# nested params
|
9
|
-
def valid?(context = nil)
|
10
|
-
current_context, self.validation_context = validation_context, context
|
11
|
-
errors.clear
|
12
|
-
run_validations!
|
13
|
-
|
14
|
-
nested_hash_validations = []
|
15
|
-
nested_hashes.each do |key, value|
|
16
|
-
nested_class = send("#{key}")
|
17
|
-
nested_hash_validations << nested_class.valid?
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
nested_array_validations = []
|
22
|
-
nested_arrays.each do |key, array|
|
23
|
-
nested_array = send("#{key}")
|
24
|
-
nested_array_validations = nested_array.map { |a| a.valid? }
|
25
|
-
end
|
26
|
-
|
27
|
-
errors.empty? &&
|
28
|
-
nested_hash_validations.all? &&
|
29
|
-
nested_array_validations.flatten.all?
|
30
|
-
|
31
|
-
ensure
|
32
|
-
self.validation_context = current_context
|
33
|
-
end
|
34
|
-
|
35
|
-
def validate!
|
36
|
-
unless valid?
|
37
|
-
raise SimpleParamsError, self.errors.to_hash.to_s
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe SimpleParams::ApiPieDoc::NestedArray do
|
4
|
-
|
5
|
-
let(:simple_param_attribute) {
|
6
|
-
{:address=>
|
7
|
-
{:street=>{:type=>:string},
|
8
|
-
:city=>{:validations=>{:length=>{:in=>4..40}, :presence=>true}, :type=>:string},
|
9
|
-
:zip_code=>{:optional=>true, :type=>:string},
|
10
|
-
:state=>{:default=>"North Carolina", :type=>:string}
|
11
|
-
},
|
12
|
-
:options=>{desc: 'i like pie'}
|
13
|
-
}
|
14
|
-
}
|
15
|
-
let(:nested_attribute) { described_class.new(simple_param_attribute) }
|
16
|
-
|
17
|
-
it_behaves_like 'a base attribute'
|
18
|
-
|
19
|
-
describe '#initialize' do
|
20
|
-
specify 'should give instance an attribute' do
|
21
|
-
expect(nested_attribute.attribute).to eq simple_param_attribute
|
22
|
-
end
|
23
|
-
|
24
|
-
specify 'should give instance options' do
|
25
|
-
expect(nested_attribute.options).to eq({ desc: 'i like pie' })
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '#name' do
|
30
|
-
specify 'should set respond with the right name' do
|
31
|
-
expect(nested_attribute.name).to eq 'address'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe '#options' do
|
36
|
-
specify 'should return nested attribute options' do
|
37
|
-
expect(nested_attribute.options).to eq({desc: 'i like pie'})
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe '#to_s' do
|
42
|
-
specify 'should return properly formatted string' do
|
43
|
-
expect(nested_attribute.to_s).to eq("param :address, Array, desc: 'i like pie', required: true do\nparam :street, String, desc: '', required: true\nparam :city, String, desc: '', required: true\nparam :zip_code, String, desc: '', required: false\nparam :state, String, desc: '', required: false\nend")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|