salestation 4.5.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/salestation/app/input_verification.rb +22 -6
- data/lib/salestation/web/extractors.rb +23 -4
- data/salestation.gemspec +2 -2
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63f86b3537b2db5857f54ef439442a3ca0ef1a4f078d602989783814fd70b718
|
4
|
+
data.tar.gz: 2836da19672da049c461769c8482e4c9cab2e3ce6d6292293051639c0a0cb8e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc79ff3f36806274195543e4fc0e13f27d098d1239b3c0706cd6a7ed3f643a764a71b2b34426ccfbe19ebc9f29b0018a8c8619a1c2f9729c180df70a2b640906
|
7
|
+
data.tar.gz: 4b4d65d3e6158c9ff0025f2e5548b650dab2d0ca3bf4c5dca3f51b11943be552c44eadda05cb5830962157ef2d1200e8067b731eebbc74bb501d83e8a39d7753
|
@@ -5,13 +5,29 @@ module Salestation
|
|
5
5
|
module InputVerification
|
6
6
|
def verify_input(schema)
|
7
7
|
-> (request) do
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
input = request.input
|
9
|
+
result = schema.call(input)
|
10
|
+
|
11
|
+
dry_validation_version = Gem.loaded_specs['dry-validation'].version
|
12
|
+
if dry_validation_version < Gem::Version.new('1.0')
|
13
|
+
Mapper.from_dry_validation_result(result.output, result.errors, custom_error_map)
|
14
|
+
if result.success?
|
15
|
+
request.replace_input(result.output)
|
16
|
+
else
|
17
|
+
Deterministic::Result::Failure(
|
18
|
+
Errors::InvalidInput.new(errors: result.errors, hints: result.hints)
|
19
|
+
)
|
20
|
+
end
|
21
|
+
elsif dry_validation_version <= Gem::Version.new('1.8')
|
22
|
+
if result.success?
|
23
|
+
request.replace_input(input)
|
24
|
+
else
|
25
|
+
Deterministic::Result::Failure(
|
26
|
+
Errors::InvalidInput.new(errors: result.errors.to_h, hints: result.hints.to_h)
|
27
|
+
)
|
28
|
+
end
|
11
29
|
else
|
12
|
-
|
13
|
-
Errors::InvalidInput.new(errors: result.errors, hints: result.hints)
|
14
|
-
)
|
30
|
+
raise 'Unsupported dry-validation version'
|
15
31
|
end
|
16
32
|
end
|
17
33
|
end
|
@@ -197,12 +197,26 @@ module Salestation
|
|
197
197
|
when Symbol
|
198
198
|
stringified_key = filter.to_s
|
199
199
|
extracted_data[filter] = request_hash[stringified_key] if request_hash.key?(stringified_key)
|
200
|
+
if extracted_data[filter].is_a?(Array)
|
201
|
+
extracted_data[filter] = extracted_data[filter].map{ |hash|
|
202
|
+
if hash.is_a?(Hash)
|
203
|
+
hash.transform_keys(&:to_sym) if hash.is_a?(Hash)
|
204
|
+
else
|
205
|
+
hash
|
206
|
+
end
|
207
|
+
}
|
208
|
+
end
|
200
209
|
when Hash
|
201
210
|
filter.each do |key, nested_filters|
|
202
211
|
stringified_key = key.to_s
|
203
212
|
if request_hash.key?(stringified_key)
|
204
213
|
value = request_hash.fetch(stringified_key)
|
205
|
-
extracted_data[key] =
|
214
|
+
extracted_data[key] =
|
215
|
+
if !value.is_a?(Hash)
|
216
|
+
value
|
217
|
+
else
|
218
|
+
extract(nested_filters, value)
|
219
|
+
end
|
206
220
|
end
|
207
221
|
end
|
208
222
|
end
|
@@ -219,17 +233,22 @@ module Salestation
|
|
219
233
|
# Extracts and symbolizes params from request body
|
220
234
|
#
|
221
235
|
# @example
|
222
|
-
# extractor = BodyParamExtractor[:x, :y, {foo: [:bar, :baz]}]
|
236
|
+
# extractor = BodyParamExtractor[:x, :y, {foo: [:bar, :baz]}, :aaa]
|
223
237
|
# input = {
|
224
238
|
# 'x' => '1',
|
225
239
|
# 'y' => '2',
|
226
240
|
# 'z' => '3',
|
227
241
|
# 'foo' => {
|
228
242
|
# 'bar' => 'qq'
|
229
|
-
# }
|
243
|
+
# },
|
244
|
+
# 'aaa' => [
|
245
|
+
# {
|
246
|
+
# 'bb' => 'cc'
|
247
|
+
# }
|
248
|
+
# ]
|
230
249
|
# }
|
231
250
|
# # rack_request is Rack::Request with 'rack.request.form_hash' set to input
|
232
|
-
# extractor.call(rack_request).value #=> {x: 1, y: 2, foo: {bar: 'qq}}
|
251
|
+
# extractor.call(rack_request).value #=> {x: 1, y: 2, foo: {bar: 'qq'}, aaa: [{bb: 'cc'}]}
|
233
252
|
#
|
234
253
|
class BodyParamExtractor
|
235
254
|
def self.[](*filters)
|
data/salestation.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "salestation"
|
7
|
-
spec.version = "
|
7
|
+
spec.version = "5.0.0"
|
8
8
|
spec.authors = ["Glia TechMovers"]
|
9
9
|
spec.email = ["techmovers@glia.com"]
|
10
10
|
|
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "rspec", "~> 3.0"
|
25
25
|
spec.add_development_dependency "pry", "~> 0.10.4"
|
26
26
|
spec.add_development_dependency "glia-errors", "~> 0.11.4"
|
27
|
-
spec.add_development_dependency "dry-validation", "~> 1.
|
27
|
+
spec.add_development_dependency "dry-validation", "~> 1.7.0"
|
28
28
|
|
29
29
|
spec.add_dependency 'deterministic'
|
30
30
|
spec.add_dependency 'dry-struct'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: salestation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Glia TechMovers
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 1.
|
89
|
+
version: 1.7.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 1.
|
96
|
+
version: 1.7.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: deterministic
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -189,7 +189,7 @@ homepage: ''
|
|
189
189
|
licenses:
|
190
190
|
- MIT
|
191
191
|
metadata: {}
|
192
|
-
post_install_message:
|
192
|
+
post_install_message:
|
193
193
|
rdoc_options: []
|
194
194
|
require_paths:
|
195
195
|
- lib
|
@@ -204,8 +204,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
204
|
- !ruby/object:Gem::Version
|
205
205
|
version: '0'
|
206
206
|
requirements: []
|
207
|
-
rubygems_version: 3.
|
208
|
-
signing_key:
|
207
|
+
rubygems_version: 3.1.6
|
208
|
+
signing_key:
|
209
209
|
specification_version: 4
|
210
210
|
summary: ''
|
211
211
|
test_files: []
|