salestation 4.4.1 → 4.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 533d617c2c637187cc4cb8e9f1131d5dd54fb046c08a279724c99135268b2ad9
4
- data.tar.gz: 61ff5a8e9d6a93c11dcf2333c4a88e145a8b13a5d2b62bc99a25e665f16a814f
3
+ metadata.gz: 0a374933b6b6c2191a57c6cceeb4dfed40263dee8378587f47b15a9b036f9867
4
+ data.tar.gz: d66178d5ac10fdf0a4ffc317cf28521912629d09105aa03feeaa191ef8183060
5
5
  SHA512:
6
- metadata.gz: 41deda5681c52b1fe10f40f4a68606ddc42accd68f816e5ce4cdeef0797400eb73fc65462338d218481c018554095af5b907005af0dc7cb1d89bbc7ff0ff4e9e
7
- data.tar.gz: 66a543f73b6373b3ba6f40e664f385c651605fcdc0ce637af685341d3238abb852283144c40be6c1aaa8b3ff7252f65f6141f761e086273dcd20a4763da7b54a
6
+ metadata.gz: 69ef7cb09a68ee274d797079f3f4fe241cc28aab7ece3d8f18a59b9b478a276444c4e058029967e02d716d743b6ecf33a8f50ca09cc0ca271ff42c7f42f50e81
7
+ data.tar.gz: 9bef5feb7d0cf02e11639c26115846770e69ba1233db20a2090fba46e93a17259fc6eca1cabc71693a1efcd192b4edc53ad357082405e06743d2b35f859253cd
@@ -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`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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
 
@@ -6,12 +6,27 @@ module Salestation
6
6
  def verify_input(schema)
7
7
  -> (request) do
8
8
  result = schema.call(request.input)
9
- if result.success?
10
- request.replace_input(result.output)
9
+
10
+ dry_validation_version = Gem.loaded_specs['dry-validation'].version
11
+ if dry_validation_version < Gem::Version.new('1.0')
12
+ Mapper.from_dry_validation_result(result.output, result.errors, custom_error_map)
13
+ if result.success?
14
+ request.replace_input(result.output)
15
+ else
16
+ Deterministic::Result::Failure(
17
+ Errors::InvalidInput.new(errors: result.errors, hints: result.hints)
18
+ )
19
+ end
20
+ elsif dry_validation_version <= Gem::Version.new('1.8')
21
+ if result.success?
22
+ request.replace_input(result.to_h)
23
+ else
24
+ Deterministic::Result::Failure(
25
+ Errors::InvalidInput.new(errors: result.errors.to_h, hints: result.hints.to_h)
26
+ )
27
+ end
11
28
  else
12
- Deterministic::Result::Failure(
13
- Errors::InvalidInput.new(errors: result.errors, hints: result.hints)
14
- )
29
+ raise 'Unsupported dry-validation version'
15
30
  end
16
31
  end
17
32
  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
 
@@ -6,7 +6,7 @@ module Salestation
6
6
  include Deterministic::Prelude
7
7
 
8
8
  def self.[](**validations)
9
- new(validations)
9
+ new(**validations)
10
10
  end
11
11
 
12
12
  def initialize(**validations)
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.4.1"
7
+ spec.version = "4.6.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"
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.1
4
+ version: 4.6.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: 2021-09-07 00:00:00.000000000 Z
11
+ date: 2022-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: dry-validation
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
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: '0'
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.0.3
207
- signing_key:
207
+ rubygems_version: 3.1.6
208
+ signing_key:
208
209
  specification_version: 4
209
210
  summary: ''
210
211
  test_files: []