glia-errors 0.11.10 → 0.12.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: 182a479821307d1d9b7fd5b1ba47ee4bbeb5cb8c69c6e58963d387b8b383b92b
4
- data.tar.gz: 988265708f5ed2a46d14a05c39ec2b526f27ef540959f5d234a749cb7290c8b5
3
+ metadata.gz: 2a2c74c904931658ed3873ae51474edddcb93b0110129cfa7e70bb4c4894ffc8
4
+ data.tar.gz: 377d265f4e0772363bfbbac4fc4be97ba925d99afe78ba458ef72f1329e79fad
5
5
  SHA512:
6
- metadata.gz: c83b5503cd6904ac367f1afbebcdf9e45a380bdaacb28d0ff10a414ef68cffd2d7ea8dbf227b1577427108c5ced9a636c5cf4fe71500adbfe20a2981e5fccf5b
7
- data.tar.gz: 594b6ab2e41d8219cfe587db80e5c04684b780f7c9eb74dcc90289c84ccd2ecfcf49a942ba74ce64d042b5039895a7c9831397682933131284496d030c281e33
6
+ metadata.gz: c3d8c4ad7aaf500b3d3cc056d7166b0f41ec184a452a11d1f89c28f1d518bbdfe79386ec1c796d5254486b968f81336a638343f913c6c313a872a72f31da1f80
7
+ data.tar.gz: 67833dced10d66343315259b86de96565e583295295352caac505e488555d101d1a1daa82c95476b6158bcf80972f3a8edf9ac537e4d7992190ec19dd89c1178
data/.prettierrc CHANGED
@@ -1 +1 @@
1
- printWidth: 100
1
+ printWidth: 120
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
6
 
7
+ gem 'dry-validation', '~> 1.8'
7
8
  gem 'prettier', '~> 0.22'
8
9
  gem 'rake', '~> 13.0'
9
10
  gem 'rspec', '~> 3.10'
@@ -11,9 +12,3 @@ gem 'rubocop', '~> 1.5'
11
12
  gem 'rubocop-rake', '~> 0.5'
12
13
  gem 'rubocop-rspec', '~> 2.0'
13
14
  gem 'super_diff'
14
-
15
- group :test do
16
- gem 'appraisal'
17
- end
18
-
19
- gem 'dry-validation', '~> 1.8'
data/Gemfile.lock CHANGED
@@ -6,10 +6,6 @@ PATH
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- appraisal (2.3.0)
10
- bundler
11
- rake
12
- thor (>= 0.14.0)
13
9
  ast (2.4.2)
14
10
  attr_extras (6.2.5)
15
11
  concurrent-ruby (1.1.10)
@@ -90,7 +86,6 @@ GEM
90
86
  attr_extras (>= 6.2.4)
91
87
  diff-lcs
92
88
  patience_diff
93
- thor (1.0.1)
94
89
  unicode-display_width (2.1.0)
95
90
 
96
91
  PLATFORMS
@@ -98,7 +93,6 @@ PLATFORMS
98
93
  x86_64-darwin-19
99
94
 
100
95
  DEPENDENCIES
101
- appraisal
102
96
  dry-validation (~> 1.8)
103
97
  glia-errors!
104
98
  prettier (~> 0.22)
data/README.md CHANGED
@@ -31,9 +31,7 @@ glia_error = Glia::Errors::ResourceNotFoundError.new(resource: :engagement)
31
31
 
32
32
  #### Create Glia error from `dry-validation` result
33
33
 
34
- Currently 2 `dry-validation` versions are supported:
35
- * `v0` up to `0.13`
36
- * `v1` up to `1.8`
34
+ Supports `dry-validation` from `1.6.x` to `1.8.x`
37
35
 
38
36
  ```ruby
39
37
  schema = Dry::Validation.Schema do
@@ -106,31 +104,19 @@ else
106
104
  end
107
105
  ```
108
106
 
109
- ## Contributing
107
+ ## Releasing a new version
110
108
 
111
- ### Testing
109
+ A new version is created when a change is merged into the master branch that changes the version number in `glia-errors.gemspec`.
110
+ A Github Action will push the `.gem` file to [rubygems.org](https://rubygems.org)
112
111
 
113
- Glia errors support multiple versions of `dry-validation` and tests are run against each supported major version.
114
- Under the hood we use `Appraisal` gem which generals additional gemfiles for each of the versions.
112
+ ## Contributing
115
113
 
116
- To run all tests use:
114
+ ### Testing
117
115
 
118
116
  ```
119
117
  bundle exec rake test
120
118
  ```
121
119
 
122
- To run tests only for `dry-validation` v1:
123
-
124
- ```
125
- bundle exec rake test_dry_validation_v1
126
- ```
127
-
128
- To run tests only for `dry-validation` v0:
129
-
130
- ```
131
- bundle exec rake test_dry_validation_v0
132
- ```
133
-
134
120
  ### Formatting
135
121
 
136
122
  ```
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ RuboCop::RakeTask.new do |task|
11
11
  task.requires << 'rubocop-rspec'
12
12
  end
13
13
 
14
- task default: %i[lint test]
14
+ task default: %i[lint spec]
15
15
 
16
16
  task :lint do
17
17
  sh "rubocop && rbprettier --check '**/*.rb'"
@@ -20,26 +20,3 @@ end
20
20
  task :format do
21
21
  sh "rbprettier --write '**/*.rb'"
22
22
  end
23
-
24
- task :install_test_deps do
25
- sh 'bundle exec appraisal install'
26
- end
27
-
28
- ruby_major_version = RUBY_VERSION.split('.').first.to_i
29
-
30
- # dry-validation 0.x won't load in Ruby 3
31
- if ruby_major_version < 3
32
- task test: %i[test_dry_validation_v1 test_dry_validation_v0]
33
- else
34
- task test: :test_dry_validation_v1
35
- end
36
-
37
- task test_dry_validation_v1: :install_test_deps do
38
- sh 'bundle exec appraisal dry_validation_v1 rspec'
39
- end
40
-
41
- if ruby_major_version < 3
42
- task test_dry_validation_v0: :install_test_deps do
43
- sh 'bundle exec appraisal dry_validation_v0 rspec --tag dry_validation_v0'
44
- end
45
- end
data/glia-errors.gemspec CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'glia-errors'
8
- spec.version = '0.11.10'
8
+ spec.version = '0.12.0'
9
9
  spec.authors = ['Glia TechMovers']
10
10
  spec.email = ['techmovers@glia.com']
11
11
 
@@ -62,11 +62,7 @@ module Glia
62
62
 
63
63
  def initialize(field:, format: nil, message: nil)
64
64
  default_message =
65
- if format
66
- "has invalid format, required format is #{humanize_format(format)}"
67
- else
68
- 'has invalid format'
69
- end
65
+ format ? "has invalid format, required format is #{humanize_format(format)}" : 'has invalid format'
70
66
  super(
71
67
  type: INVALID_FORMAT_ERROR,
72
68
  ref: create_ref(INVALID_FORMAT_ERROR),
@@ -261,9 +257,7 @@ module Glia
261
257
  class RouteNotFoundError < Error
262
258
  def initialize(message: nil)
263
259
  super(
264
- type: ROUTE_NOT_FOUND_ERROR,
265
- ref: create_ref(ROUTE_NOT_FOUND_ERROR),
266
- message: message || 'Route not found'
260
+ type: ROUTE_NOT_FOUND_ERROR, ref: create_ref(ROUTE_NOT_FOUND_ERROR), message: message || 'Route not found'
267
261
  )
268
262
  end
269
263
  end
@@ -281,9 +275,7 @@ module Glia
281
275
  class CarrierError < Error
282
276
  def initialize(message: nil)
283
277
  super(
284
- type: CARRIER_ERROR,
285
- ref: create_ref(CARRIER_ERROR),
286
- message: message || 'Downstream carrier issue occurred'
278
+ type: CARRIER_ERROR, ref: create_ref(CARRIER_ERROR), message: message || 'Downstream carrier issue occurred'
287
279
  )
288
280
  end
289
281
  end
@@ -417,6 +409,25 @@ module Glia
417
409
  end
418
410
  end
419
411
 
412
+ class ItemsOverlapError < Error
413
+ def initialize(overlapping_item_indexes:, message: nil)
414
+ raise ArgumentError, 'overlapping_item_indexes value must be list' unless overlapping_item_indexes.is_a?(Array)
415
+
416
+ raise ArgumentError, 'at least 2 overlapping item indexes are required' if overlapping_item_indexes.size < 2
417
+
418
+ overlapping_item_indexes.each do |value|
419
+ raise ArgumentError, 'overlapping_item_indexes values must be integers' unless value.is_a?(Integer)
420
+ end
421
+
422
+ super(
423
+ type: ITEMS_OVERLAP_ERROR,
424
+ ref: create_ref(ITEMS_OVERLAP_ERROR),
425
+ message: message || 'Items must not overlap each other',
426
+ error_details: { overlapping_item_indexes: overlapping_item_indexes }
427
+ )
428
+ end
429
+ end
430
+
420
431
  # rubocop:enable Style/Documentation
421
432
  end
422
433
  end
@@ -16,9 +16,7 @@ module Glia
16
16
  end
17
17
 
18
18
  def to_h
19
- {
20
- type: type, ref: ref, message: message, error_details: error_details_to_h(@error_details)
21
- }.compact
19
+ { type: type, ref: ref, message: message, error_details: error_details_to_h(@error_details) }.compact
22
20
  end
23
21
 
24
22
  private
@@ -27,9 +25,7 @@ module Glia
27
25
  return details if primitive?(details)
28
26
 
29
27
  if details.is_a?(Hash)
30
- details.keys.each_with_object({}) do |field, hash|
31
- hash[field] = error_details_to_h(details[field])
32
- end
28
+ details.keys.each_with_object({}) { |field, hash| hash[field] = error_details_to_h(details[field]) }
33
29
  elsif details.is_a?(Array)
34
30
  details.map { |error| error_details_to_h(error) }
35
31
  elsif details.respond_to?(:to_h)
@@ -40,8 +36,7 @@ module Glia
40
36
  end
41
37
 
42
38
  def primitive?(details)
43
- details.nil? ||
44
- [TrueClass, FalseClass, String, Integer, Float, Symbol].include?(details.class)
39
+ details.nil? || [TrueClass, FalseClass, String, Integer, Float, Symbol].include?(details.class)
45
40
  end
46
41
 
47
42
  def create_ref(type)
@@ -34,8 +34,8 @@ module Glia
34
34
  FACEBOOK_ACCESS_TOKEN_NOT_PERMANENT_ERROR = 'facebook_access_token_not_permanent_error'
35
35
  OAUTH_CODE_EXPIRED_ERROR = 'oauth_code_expired_error'
36
36
  OAUTH_CODE_ALREADY_USED_ERROR = 'oauth_code_already_used_error'
37
- APPLE_BUSINESS_CHAT_BUSINESS_USED_BY_OTHER_SITE_ERROR =
38
- 'apple_business_chat_business_used_by_other_site_error'
37
+ APPLE_BUSINESS_CHAT_BUSINESS_USED_BY_OTHER_SITE_ERROR = 'apple_business_chat_business_used_by_other_site_error'
38
+ ITEMS_OVERLAP_ERROR = 'items_overlap_error'
39
39
 
40
40
  # Server errors
41
41
  INTERNAL_SERVER_ERROR = 'internal_server_error'
@@ -12,8 +12,7 @@ module Glia
12
12
  InvalidTypeError::Types::ARRAY
13
13
  when 'must be an integer', 'must be Integer'
14
14
  InvalidTypeError::Types::INTEGER
15
- when 'must be a number', 'must be a float', 'must be a decimal', 'must be Float',
16
- 'must be BigDecimal'
15
+ when 'must be a number', 'must be a float', 'must be a decimal', 'must be Float', 'must be BigDecimal'
17
16
  InvalidTypeError::Types::NUMBER
18
17
  when 'must be a hash', 'must be Hash'
19
18
  InvalidTypeError::Types::OBJECT
@@ -39,11 +38,7 @@ module Glia
39
38
  # so we are separating them ourselves
40
39
  INVALID_NUMBER_OR_VALUE_ERROR =
41
40
  lambda do |field, value, _message|
42
- if value.is_a?(String)
43
- InvalidValueError.new(field: field)
44
- else
45
- InvalidNumberError.new(field: field)
46
- end
41
+ value.is_a?(String) ? InvalidValueError.new(field: field) : InvalidNumberError.new(field: field)
47
42
  end
48
43
 
49
44
  INVALID_DATE_FORMAT =
@@ -125,8 +120,7 @@ module Glia
125
120
  'is missing' => MISSING_VALUE_ERROR,
126
121
  # Custom format errors
127
122
  'must be in E.164 format' => INVALID_FORMAT_ERROR,
128
- 'must be up to 25 symbol string that contains only 1-7 digits and commas' =>
129
- INVALID_FORMAT_ERROR,
123
+ 'must be up to 25 symbol string that contains only 1-7 digits and commas' => INVALID_FORMAT_ERROR,
130
124
  'must be a valid email' => INVALID_FORMAT_ERROR
131
125
  }.freeze
132
126
 
@@ -146,9 +140,7 @@ module Glia
146
140
  # This is not needed for the `else` case as dry-validation already provides an array.
147
141
  [from_dry_validation_result_rec(field_value, field_messages, error_map)]
148
142
  else
149
- field_messages.map do |message|
150
- from_dry_validation_error(field, field_value, message, error_map)
151
- end
143
+ field_messages.map { |message| from_dry_validation_error(field, field_value, message, error_map) }
152
144
  end
153
145
  end
154
146
  InputValidationError.new(error_details: error_details)
data/lib/glia/errors.rb CHANGED
@@ -11,13 +11,14 @@ module Glia
11
11
  module Errors
12
12
  def self.from_dry_validation_result(result, custom_error_map = {})
13
13
  dry_validation_version = Gem.loaded_specs['dry-validation'].version
14
- if dry_validation_version < Gem::Version.new('1.0')
15
- Mapper.from_dry_validation_result(result.output, result.errors, custom_error_map)
16
- elsif dry_validation_version <= Gem::Version.new('2.0')
17
- Mapper.from_dry_validation_result(result.to_h, result.errors.to_h, custom_error_map)
18
- else
14
+
15
+ # When updating supported version ensure that if new version contains new dry-validation new validations
16
+ # that they are correctly mapped to Glia errors in mapper.rb
17
+ unless dry_validation_version >= Gem::Version.new('1.0') && dry_validation_version < Gem::Version.new('1.9')
19
18
  raise 'Unsupported dry-validation version'
20
19
  end
20
+
21
+ Mapper.from_dry_validation_result(result.to_h, result.errors.to_h, custom_error_map)
21
22
  end
22
23
  end
23
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glia-errors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.10
4
+ version: 0.12.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-06-10 00:00:00.000000000 Z
11
+ date: 2022-10-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ''
14
14
  email:
@@ -24,13 +24,10 @@ files:
24
24
  - ".rubocop.yml"
25
25
  - ".ruby-version"
26
26
  - ".travis.yml"
27
- - Appraisals
28
27
  - Gemfile
29
28
  - Gemfile.lock
30
29
  - README.md
31
30
  - Rakefile
32
- - gemfiles/dry_validation_v0.gemfile
33
- - gemfiles/dry_validation_v1.gemfile
34
31
  - glia-errors.gemspec
35
32
  - lib/glia/errors.rb
36
33
  - lib/glia/errors/client_errors.rb
@@ -39,11 +36,11 @@ files:
39
36
  - lib/glia/errors/mapper.rb
40
37
  - lib/glia/errors/naming.rb
41
38
  - lib/glia/errors/server_errors.rb
42
- homepage:
39
+ homepage:
43
40
  licenses:
44
41
  - MIT
45
42
  metadata: {}
46
- post_install_message:
43
+ post_install_message:
47
44
  rdoc_options: []
48
45
  require_paths:
49
46
  - lib
@@ -61,8 +58,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
58
  - !ruby/object:Gem::Version
62
59
  version: '0'
63
60
  requirements: []
64
- rubygems_version: 3.3.7
65
- signing_key:
61
+ rubygems_version: 3.1.2
62
+ signing_key:
66
63
  specification_version: 4
67
64
  summary: Glia REST API errors
68
65
  test_files: []
data/Appraisals DELETED
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ruby_major_version = RUBY_VERSION.split('.').first.to_i
4
-
5
- if ruby_major_version < 3
6
- appraise 'dry_validation_v0' do
7
- gem 'dry-core', '~> 0.5.0'
8
- gem 'dry-validation', '~> 0.13.0'
9
- end
10
- end
11
-
12
- appraise 'dry_validation_v1' do
13
- gem 'dry-validation', '~> 1.8'
14
- end
@@ -1,19 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "prettier", "~> 0.22"
6
- gem "rake", "~> 13.0"
7
- gem "rspec", "~> 3.10"
8
- gem "rubocop", "~> 1.5"
9
- gem "rubocop-rake", "~> 0.5"
10
- gem "rubocop-rspec", "~> 2.0"
11
- gem "super_diff"
12
- gem "dry-validation", "~> 0.13.0"
13
- gem "dry-core", "~> 0.5.0"
14
-
15
- group :test do
16
- gem "appraisal"
17
- end
18
-
19
- gemspec path: "../"
@@ -1,18 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "prettier", "~> 0.22"
6
- gem "rake", "~> 13.0"
7
- gem "rspec", "~> 3.10"
8
- gem "rubocop", "~> 1.5"
9
- gem "rubocop-rake", "~> 0.5"
10
- gem "rubocop-rspec", "~> 2.0"
11
- gem "super_diff"
12
- gem "dry-validation", "~> 1.8"
13
-
14
- group :test do
15
- gem "appraisal"
16
- end
17
-
18
- gemspec path: "../"