salestation 4.4.2 → 4.5.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: 8de4efec567a218753f1b529394006e24294cba52a8f63c68c3a3a311cc04e87
4
- data.tar.gz: 8a906d43283751e9e173a6f99ca8a36a2ab64f663d04470158272d8f7c153b1c
3
+ metadata.gz: 50948c2e3f36bfe0779cb2458cf42cc6d7dd8e9b38b77a00e7bf0e975f7f2140
4
+ data.tar.gz: 490a6207820bdc32b745e1d3d6c9cbbdb33e547783f557aa14ff89791b351173
5
5
  SHA512:
6
- metadata.gz: dccaa52c41c6aceaca03284c9a185920e2b297449ce5a04696458df7d76a3828a1cf6b650d7a73b749d509d4a0833e1469da14f4954f625fa0ebf9ef917660ee
7
- data.tar.gz: 3b3bc59d4f1e4bc221bbb30b83e74a74aee0ac00c2cd47e69e660ebaf003f16838e050ab8f49ebdc278e1ed82a6389adce2621d4f7092045262a3fce8be3205f
6
+ metadata.gz: d99f0b753951b98f0905d2084d432071d33d2a2370ae07726225db8d90f8dc8d5bdb6acc453ff2654a2bc81dc23ba27f125202eb1bbc8adceb09faca73638755
7
+ data.tar.gz: 2d41a2673bc8a59fb78e97ecff19b4c58ed11c01e66111a538ee3e8c1d5c18b9ad504437368a5a5538e7cfb879efe94b6ef19678c8977348c5dbecc62b8b9489
@@ -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
 
@@ -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.4.2"
7
+ spec.version = "4.5.0"
8
8
  spec.authors = ["Glia TechMovers"]
9
9
  spec.email = ["techmovers@glia.com"]
10
10
 
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.2
4
+ version: 4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glia TechMovers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-15 00:00:00.000000000 Z
11
+ date: 2022-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -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"
@@ -203,7 +204,7 @@ 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.2
207
+ rubygems_version: 3.0.6
207
208
  signing_key:
208
209
  specification_version: 4
209
210
  summary: ''