salestation 4.4.2 → 4.6.1
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 +4 -4
- data/.github/workflows/publish.yml +22 -0
- data/README.md +1 -1
- data/lib/salestation/app/input_verification.rb +22 -6
- data/lib/salestation/web/extractors.rb +74 -0
- data/salestation.gemspec +2 -2
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1245b9d949f1d4f8cfb1ce04208f72cd4b0601e9bc798f65a86a83199deb1e1
|
4
|
+
data.tar.gz: d35c8d0364840fb99a3667d007e9cc2ae9c80111bdd86b245f159ab337a98932
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1fe8ec62ba1562d3ab7d24b96657c2eebc47c898e226f4a5af84050a3f839cdb850828e79da6caed07f958a3560881cf068690cff3f1c27fad55b12793c2c33
|
7
|
+
data.tar.gz: be76d4e7151eeb1dcd378fd65c0f12d1c519cceb652eb8cb702f6db3692a7491e8190aecd0434fea27671b04ef379765fa062d1bffe91bd5c0ebeec0c0a5795c
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: Publish Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v2
|
13
|
+
with:
|
14
|
+
fetch-depth: 2
|
15
|
+
|
16
|
+
|
17
|
+
- name: Release Gem
|
18
|
+
uses: discourse/publish-rubygems-action@b55d7b91b55e61752dc6cbc2972f8e16fe6c1a02
|
19
|
+
env:
|
20
|
+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
21
|
+
RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
|
22
|
+
RELEASE_COMMAND: rake release
|
data/README.md
CHANGED
@@ -210,7 +210,7 @@ See lib/salestation/rspec.rb for more examples.
|
|
210
210
|
|
211
211
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
212
212
|
|
213
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
213
|
+
To install this gem onto your local machine, run `bundle exec rake install`. A new version is created when a change is merged into the master branch that changes the version number in `salestation.gemspec`. A Github Action will create a tag for the version and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
214
214
|
|
215
215
|
## Contributing
|
216
216
|
|
@@ -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
|
@@ -21,6 +21,10 @@ module Salestation
|
|
21
21
|
def coerce(rules)
|
22
22
|
InputCoercer.new(self, rules)
|
23
23
|
end
|
24
|
+
|
25
|
+
def rename(rules)
|
26
|
+
InputRenamer.new(self, rules)
|
27
|
+
end
|
24
28
|
end
|
25
29
|
|
26
30
|
class CombinedInputExtractor
|
@@ -88,6 +92,76 @@ module Salestation
|
|
88
92
|
end
|
89
93
|
end
|
90
94
|
|
95
|
+
# Handles renaming input keys
|
96
|
+
#
|
97
|
+
# When renaming we want to ensure that the new key provided for the rename does not already
|
98
|
+
# exist in the input. When it does and it has a not nil value, then rename will not happen,
|
99
|
+
# unless `override: true` is also applied. When the new key exists with nil value,
|
100
|
+
# rename will happen.
|
101
|
+
# By default override is set to false: when input already has value set for the new key,
|
102
|
+
# the old key will be discarded instead of overwriting the value.
|
103
|
+
# For deprecating (renaming for deprecation purposes), one should extract both new and old key
|
104
|
+
# from the input before calling the rename function, to get expected result, as only then the
|
105
|
+
# values can be compared in rename.
|
106
|
+
#
|
107
|
+
# @example
|
108
|
+
# original_input = {
|
109
|
+
# x: 'a',
|
110
|
+
# y: 'b'
|
111
|
+
# }
|
112
|
+
#
|
113
|
+
# extractor = BodyParamExtractor[:x, :y]
|
114
|
+
# .rename(x: :z)
|
115
|
+
# input = {
|
116
|
+
# z: 'a',
|
117
|
+
# y: 'b'
|
118
|
+
# }
|
119
|
+
#
|
120
|
+
# extractor = BodyParamExtractor[:x, :y]
|
121
|
+
# .rename(x: :y)
|
122
|
+
# input = {
|
123
|
+
# y: 'b'
|
124
|
+
# }
|
125
|
+
# extractor = BodyParamExtractor[:x, :y]
|
126
|
+
# .rename(x: {new_key: :y, override: true})
|
127
|
+
# input = {
|
128
|
+
# y: 'a'
|
129
|
+
# }
|
130
|
+
class InputRenamer
|
131
|
+
def initialize(extractor, rules)
|
132
|
+
@extractor = extractor
|
133
|
+
@rules = map_rules(rules)
|
134
|
+
end
|
135
|
+
|
136
|
+
def call(rack_request)
|
137
|
+
@extractor
|
138
|
+
.call(rack_request)
|
139
|
+
.map(&method(:rename))
|
140
|
+
end
|
141
|
+
|
142
|
+
def rename(input)
|
143
|
+
@rules.each do |old_key, rule|
|
144
|
+
new_key = rule[:new_key]
|
145
|
+
override = rule[:override]
|
146
|
+
|
147
|
+
if input[new_key].nil? || override
|
148
|
+
input[new_key] = input[old_key]
|
149
|
+
end
|
150
|
+
|
151
|
+
input.delete(old_key)
|
152
|
+
end
|
153
|
+
Deterministic::Result::Success(input)
|
154
|
+
end
|
155
|
+
|
156
|
+
private
|
157
|
+
|
158
|
+
def map_rules(rules)
|
159
|
+
rules.map do |field, rule|
|
160
|
+
[field, rule.is_a?(Hash) ? rule : {new_key: rule, override: false}]
|
161
|
+
end.to_h
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
91
165
|
class HeadersExtractor
|
92
166
|
include Deterministic
|
93
167
|
|
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 = "4.
|
7
|
+
spec.version = "4.6.1"
|
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.
|
4
|
+
version: 4.6.1
|
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:
|
11
|
+
date: 2022-04-27 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
|
@@ -157,6 +157,7 @@ executables: []
|
|
157
157
|
extensions: []
|
158
158
|
extra_rdoc_files: []
|
159
159
|
files:
|
160
|
+
- ".github/workflows/publish.yml"
|
160
161
|
- ".github/workflows/ruby.yml"
|
161
162
|
- ".gitignore"
|
162
163
|
- ".rspec"
|
@@ -188,7 +189,7 @@ homepage: ''
|
|
188
189
|
licenses:
|
189
190
|
- MIT
|
190
191
|
metadata: {}
|
191
|
-
post_install_message:
|
192
|
+
post_install_message:
|
192
193
|
rdoc_options: []
|
193
194
|
require_paths:
|
194
195
|
- lib
|
@@ -203,8 +204,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
204
|
- !ruby/object:Gem::Version
|
204
205
|
version: '0'
|
205
206
|
requirements: []
|
206
|
-
rubygems_version: 3.1.
|
207
|
-
signing_key:
|
207
|
+
rubygems_version: 3.1.6
|
208
|
+
signing_key:
|
208
209
|
specification_version: 4
|
209
210
|
summary: ''
|
210
211
|
test_files: []
|