salestation 5.3.1 → 5.3.2

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: a6df52858cd7f5226e95ecf1336818ed60f021222f749e6f3a4969e6c05c309b
4
- data.tar.gz: 2221e592b6070e403ef763f94834ae142ec03ac7277674c9dc16668a54bbbecb
3
+ metadata.gz: 9f3204f1692dd5da39dba967c0bbad7e233cadbca2ad0290a079e2b109e9fd33
4
+ data.tar.gz: cf5aea80221f27504428b6f153dfd791e1e677c1816ca9fcdd602c863077b4cd
5
5
  SHA512:
6
- metadata.gz: c10039d2261c8bfdec7a434de314d2152b59f8b50a55b4d12d0f47e59b14417f40181332be990924673dbb13131e4453267f352f0a63daa94e3ab0ccc3a08f16
7
- data.tar.gz: e9691491f6c13690129f5297b411d49034eb8fd628869e7b6b71c0f07551e477c5ca288beea2d0c679ca2ae98b334ebb441d12412946e7f2f6e41e2161eb2371
6
+ metadata.gz: d0ca53279d7299ab5a29d3fe88bad408cab41ac2475acb9b5962bafc7b1623d6ac218372de87df0a394cc491c52507464eb13af544cb248b1400e03bb95d8f1b
7
+ data.tar.gz: 93d0075650b3e79f9b954e03d3846aacd82a6b330cb5e63fe6283c5d60d4a83217f5c293a858082359373d6c8db1faf243eeb372da0a2fe171c59b72348d20dd
@@ -15,8 +15,9 @@ jobs:
15
15
 
16
16
 
17
17
  - name: Release Gem
18
- uses: discourse/publish-rubygems-action@b55d7b91b55e61752dc6cbc2972f8e16fe6c1a02
18
+ uses: discourse/publish-rubygems-action@4bd305c65315cb691bad1e8de97a87aaf29a0a85
19
19
  env:
20
- GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
21
20
  RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
22
21
  RELEASE_COMMAND: rake release
22
+ GIT_EMAIL: support@salemove.com
23
+ GIT_NAME: sm-deployer
@@ -15,7 +15,7 @@ jobs:
15
15
  runs-on: ubuntu-latest
16
16
  strategy:
17
17
  matrix:
18
- ruby-version: ['2.6', '2.7', '3.0']
18
+ ruby-version: ['2.7', '3.0']
19
19
 
20
20
  steps:
21
21
  - uses: actions/checkout@v2
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --plugin yard-doctest
data/Rakefile CHANGED
@@ -1,6 +1,13 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'yard/doctest/rake'
3
6
 
4
7
  RSpec::Core::RakeTask.new(:spec)
8
+ YARD::Doctest::RakeTask.new
5
9
 
6
- task :default => :spec
10
+ task :default do
11
+ Rake::Task['spec'].invoke
12
+ Rake::Task['yard:doctest'].invoke
13
+ end
@@ -13,6 +13,7 @@ module Salestation
13
13
  @fields = []
14
14
  @field_error_types = {}
15
15
  @field_error_messages = {}
16
+ @expect_exact_match = false
16
17
  end
17
18
 
18
19
  def on(*nested_fields)
@@ -20,6 +21,11 @@ module Salestation
20
21
  self
21
22
  end
22
23
 
24
+ def exactly
25
+ @expect_exact_match = true
26
+ self
27
+ end
28
+
23
29
  def with_type(*types)
24
30
  @field_error_types[field_to_key(@fields.last)] = types
25
31
  self
@@ -31,15 +37,32 @@ module Salestation
31
37
  end
32
38
 
33
39
  def matches?(actual)
34
- @fields.all? do |field|
35
- check_field_exists(actual, *field) &&
36
- check_field_error_types(field, actual) &&
37
- check_field_error_messages(field, actual)
38
- end
40
+ check_exact_match(actual, self.class.path_list_to_trie(@fields)) &&
41
+ @fields.all? do |field|
42
+ check_field_exists(actual, *field) &&
43
+ check_field_error_types(field, actual) &&
44
+ check_field_error_messages(field, actual)
45
+ end
39
46
  end
40
47
 
41
48
  private
42
49
 
50
+ def check_exact_match(actual, field_trie)
51
+ return true unless @expect_exact_match
52
+
53
+ actual[:error_details].keys.all? do |key|
54
+ field_trie.any? do |field, nested_field_trie|
55
+ if nested_field_trie.empty?
56
+ field == key
57
+ else
58
+ actual[:error_details][field].all? do |nested_actual|
59
+ check_exact_match(nested_actual, nested_field_trie)
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+
43
66
  def check_field_exists(actual, field, *nested_fields)
44
67
  actual[:error_details].key?(field) &&
45
68
  (
@@ -80,6 +103,33 @@ module Salestation
80
103
  def field_to_key(fields)
81
104
  fields.join('->').to_sym
82
105
  end
106
+
107
+ class << self
108
+ # @example
109
+ # path_list_to_trie([[:a, :b, :c], [:a, :b, :d], [:a, :e]])
110
+ # #=> {a: {b: {c: {}, d: {}}, e: {}}}
111
+ def path_list_to_trie(paths)
112
+ paths.reduce({}) do |acc, path|
113
+ deep_merge(acc, path_to_trie(*path))
114
+ end
115
+ end
116
+
117
+ private
118
+
119
+ # @example
120
+ # path_to_trie(*[:a, :b, :c])
121
+ # #=> {a: {b: {c: {}}}}
122
+ def path_to_trie(element, *rest)
123
+ {element.to_sym => rest.empty? ? {} : path_to_trie(*rest)}
124
+ end
125
+
126
+ # @example
127
+ # deep_merge({a: {b: {c: {}}}}, {a: {b: {d: {}}, e: {}}})
128
+ # #=> {a: {b: {c: {}, d: {}}, e: {}}}
129
+ def deep_merge(a, b)
130
+ a.merge(b) { |_key, nested_a, nested_b| deep_merge(nested_a, nested_b) }
131
+ end
132
+ end
83
133
  end
84
134
  end
85
135
  end
@@ -61,14 +61,15 @@ module Salestation
61
61
  # Handles coercing input values
62
62
  #
63
63
  # @example
64
- # extractor = BodyParamExtractor[:x, :y]
64
+ # extractor = Salestation::Web::Extractors::BodyParamExtractor[:x, :y]
65
65
  # .coerce(x: ->(value) { "x_#{value}"})
66
66
  # input = {
67
67
  # 'x' => 'a',
68
68
  # 'y' => 'b',
69
69
  # }
70
70
  # # rack_request is Rack::Request with 'rack.request.form_hash' set to input
71
- # extractor.call(rack_request).value #=> {x: 'x_a', y: 'b'}
71
+ # extractor.call(rack_request(input)).value
72
+ # #=> {x: 'x_a', y: 'b'}
72
73
  class InputCoercer
73
74
  def initialize(extractor, rules)
74
75
  @extractor = extractor
@@ -106,28 +107,25 @@ module Salestation
106
107
  # values can be compared in rename.
107
108
  #
108
109
  # @example
109
- # original_input = {
110
- # x: 'a',
111
- # y: 'b'
110
+ # input = {
111
+ # 'x' => 'a',
112
+ # 'y' => 'b'
112
113
  # }
113
114
  #
114
- # extractor = BodyParamExtractor[:x, :y]
115
+ # extractor = Salestation::Web::Extractors::BodyParamExtractor[:x, :y]
115
116
  # .rename(x: :z)
116
- # input = {
117
- # z: 'a',
118
- # y: 'b'
119
- # }
117
+ # extractor.call(rack_request(input)).value
118
+ # #=> {z: 'a', y: 'b'}
120
119
  #
121
- # extractor = BodyParamExtractor[:x, :y]
120
+ # extractor = Salestation::Web::Extractors::BodyParamExtractor[:x, :y]
122
121
  # .rename(x: :y)
123
- # input = {
124
- # y: 'b'
125
- # }
126
- # extractor = BodyParamExtractor[:x, :y]
122
+ # extractor.call(rack_request(input)).value
123
+ # #=> {y: 'b'}
124
+ #
125
+ # extractor = Salestation::Web::Extractors::BodyParamExtractor[:x, :y]
127
126
  # .rename(x: {new_key: :y, override: true})
128
- # input = {
129
- # y: 'a'
130
- # }
127
+ # extractor.call(rack_request(input)).value
128
+ # #=> {y: 'a'}
131
129
  class InputRenamer
132
130
  def initialize(extractor, rules)
133
131
  @extractor = extractor
@@ -217,7 +215,7 @@ module Salestation
217
215
  # Extracts and symbolizes params from request body
218
216
  #
219
217
  # @example
220
- # extractor = BodyParamExtractor[:x, :y, {foo: [:bar, :baz]}, :aaa]
218
+ # extractor = Salestation::Web::Extractors::BodyParamExtractor[:x, :y, {foo: [:bar, :baz]}, :aaa]
221
219
  # input = {
222
220
  # 'x' => '1',
223
221
  # 'y' => '2',
@@ -232,7 +230,8 @@ module Salestation
232
230
  # ]
233
231
  # }
234
232
  # # rack_request is Rack::Request with 'rack.request.form_hash' set to input
235
- # extractor.call(rack_request).value #=> {x: 1, y: 2, foo: {bar: 'qq'}, aaa: [{bb: 'cc'}]}
233
+ # extractor.call(rack_request(input)).value
234
+ # #=> {x: '1', y: '2', foo: {bar: 'qq'}, aaa: [{bb: 'cc'}]}
236
235
  #
237
236
  class BodyParamExtractor
238
237
  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 = "5.3.1"
7
+ spec.version = "5.3.2"
8
8
  spec.authors = ["Glia TechMovers"]
9
9
  spec.email = ["techmovers@glia.com"]
10
10
 
@@ -22,9 +22,10 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "bundler", "~> 2.0"
23
23
  spec.add_development_dependency "rake", "~> 13.0"
24
24
  spec.add_development_dependency "rspec", "~> 3.0"
25
- spec.add_development_dependency "pry", "~> 0.10.4"
25
+ spec.add_development_dependency "pry", "~> 0.14.2"
26
26
  spec.add_development_dependency "glia-errors", "~> 0.11.4"
27
27
  spec.add_development_dependency "dry-validation", "~> 1.7"
28
+ spec.add_development_dependency "yard-doctest", "~> 0.1.17"
28
29
 
29
30
  spec.add_dependency 'deterministic'
30
31
  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: 5.3.1
4
+ version: 5.3.2
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: 2023-01-18 00:00:00.000000000 Z
11
+ date: 2023-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.10.4
61
+ version: 0.14.2
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.10.4
68
+ version: 0.14.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: glia-errors
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.7'
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard-doctest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.1.17
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.1.17
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: deterministic
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -175,6 +189,7 @@ files:
175
189
  - ".github/workflows/ruby.yml"
176
190
  - ".gitignore"
177
191
  - ".rspec"
192
+ - ".yardopts"
178
193
  - Gemfile
179
194
  - LICENSE.txt
180
195
  - README.md
@@ -204,7 +219,7 @@ homepage: ''
204
219
  licenses:
205
220
  - MIT
206
221
  metadata: {}
207
- post_install_message:
222
+ post_install_message:
208
223
  rdoc_options: []
209
224
  require_paths:
210
225
  - lib
@@ -219,8 +234,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
234
  - !ruby/object:Gem::Version
220
235
  version: '0'
221
236
  requirements: []
222
- rubygems_version: 3.1.6
223
- signing_key:
237
+ rubygems_version: 3.4.10
238
+ signing_key:
224
239
  specification_version: 4
225
240
  summary: ''
226
241
  test_files: []