erratum 3.2.0 → 3.3.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: c76bbf3115824bc2de64891f8c012453a46f119ceb4498ef4c722b51e948d932
4
- data.tar.gz: d443492c0e710868e19488c7768ad39ea20a4cc269d39c36673b562c419e6cbb
3
+ metadata.gz: e3e6c5faf31997ee03d768c4550dbb14d18e7aaa603071bc4cb49f2224fc42e7
4
+ data.tar.gz: bd9de11bb451c959ae4de0717f4ad29691bb72a092111180bda53b78e138d3fc
5
5
  SHA512:
6
- metadata.gz: 6054c25f3897dea55d85fd6a6b3f088ea9ea3f49f954bee46a5d0df3137a60990f0787995b1c142a754b967391b2b1b9eb9a94a81dc1aec4ca4ac0ca536ead56
7
- data.tar.gz: fa36be44436bf1bbf22bc24915a05ef1ad0b2e00c1f3daec504a0d346fdbdf0306d366fce847b3c37143dccf3717cb8cadd385a1a28bac73394079dced7694ac
6
+ metadata.gz: f7073c9d975cb2de901082f0b2d64f1d2068ba19d2c9e1a9505ba07ae348e7057848e0964d50ded7c1d55bb8fb3ff6447de567a347e6541c63cd57fb77bdf4ab
7
+ data.tar.gz: 5a18d081d56259c87a948a207c29d4952f82426f2dd615deca753900dc077ff19726b8cddbe2fc453d4502f6ceadbac841aba94f5ed6853c4008da7022fe0f15
checksums.yaml.gz.sig CHANGED
Binary file
@@ -13,13 +13,12 @@ module Erratum
13
13
  'ActiveRecord::RecordInvalid' => '::Erratum::Errors::ResourcePersistence',
14
14
  'ActiveRecord::RecordNotFound' => '::Erratum::Errors::ResourceNotFound',
15
15
  'ActiveRecord::RecordNotSaved' => '::Erratum::Errors::ResourcePersistence',
16
+ 'ActiveRecord::RecordNotUnique' => '::Erratum::Errors::ResourceNotUnique',
17
+ 'ActiveRecord::ValueTooLong' => '::Erratum::Errors::AttributeLength',
16
18
  }.freeze
17
19
 
18
- attr_writer :url_mappings
19
-
20
- def developer_documentation_urls
21
- url_mappings['developer_documentation_urls']
22
- end
20
+ attr_writer :developer_documentation_urls,
21
+ :external_documentation_urls
23
22
 
24
23
  def error_mappings
25
24
  @error_mappings ||= DEFAULT_ERROR_MAPPINGS.dup
@@ -29,8 +28,12 @@ module Erratum
29
28
  @error_mappings = DEFAULT_ERROR_MAPPINGS.merge(other)
30
29
  end
31
30
 
31
+ def developer_documentation_urls
32
+ @developer_documentation_urls ||= {}
33
+ end
34
+
32
35
  def external_documentation_urls
33
- url_mappings['external_documentation_urls']
36
+ @external_documentation_urls ||= {}
34
37
  end
35
38
 
36
39
  def to_h
@@ -39,13 +42,6 @@ module Erratum
39
42
  'developer_documentation_urls' => developer_documentation_urls,
40
43
  }
41
44
  end
42
-
43
- def url_mappings
44
- @url_mappings ||= {
45
- 'external_documentation_urls' => {},
46
- 'developer_documentation_urls' => {},
47
- }
48
- end
49
45
  end
50
46
 
51
47
  def self.configure
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'apple_core/refinements/string'
4
+ require 'erratum/error'
5
+ require 'erratum/errors/crud'
6
+
7
+ module Erratum
8
+ module Errors
9
+ class AttributeLength < RuntimeError
10
+ using ::AppleCore::Refinements::String
11
+
12
+ include Error
13
+ include Errors::Crud
14
+
15
+ attr_accessor :pointer,
16
+ :attribute,
17
+ :length
18
+
19
+ def self.convert(original_error, overrides = {})
20
+ case original_error.class.name
21
+ when 'ActiveRecord::ValueTooLong'
22
+ message_info_pattern = /ERROR: value too long for type character varying\((\d+)\)/
23
+ message_info = original_error
24
+ .message
25
+ .match(message_info_pattern)
26
+ .captures
27
+
28
+ initialization_parameters = {
29
+ attribute: nil,
30
+ pointer: nil,
31
+ length: message_info[0],
32
+ }
33
+
34
+ new(initialization_parameters.merge(overrides))
35
+ end
36
+ end
37
+
38
+ def http_status
39
+ 422
40
+ end
41
+
42
+ def title
43
+ 'Value Too Long'
44
+ end
45
+
46
+ def detail
47
+ @detail || <<~HEREDOC.chomp.tr("\n", ' ')
48
+ One or more of the attributes you've attempted to set is longer than the
49
+ maximum length of #{length} characters allowed.
50
+ HEREDOC
51
+ end
52
+
53
+ def source
54
+ {
55
+ 'pointer' => pointer,
56
+ 'parameter' => attribute,
57
+ 'length' => length,
58
+ }
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'apple_core/refinements/string'
4
+ require 'erratum/error'
5
+ require 'erratum/errors/crud'
6
+
7
+ module Erratum
8
+ module Errors
9
+ class ResourceNotUnique < RuntimeError
10
+ using ::AppleCore::Refinements::String
11
+
12
+ include Error
13
+ include Errors::Crud
14
+
15
+ attr_accessor :pointer,
16
+ :attribute,
17
+ :value
18
+
19
+ def self.convert(original_error, overrides = {})
20
+ case original_error.class.name
21
+ when 'ActiveRecord::RecordNotUnique'
22
+ message_info_pattern = /DETAIL: Key \((.+)\)=\((.+)\) already exists\./
23
+ message_info = original_error
24
+ .message
25
+ .match(message_info_pattern)
26
+ .captures
27
+
28
+ initialization_parameters = {
29
+ attribute: message_info[0],
30
+ pointer: "/data/attributes/#{message_info[0]}",
31
+ value: message_info[1],
32
+ }
33
+
34
+ new(initialization_parameters.merge(overrides))
35
+ end
36
+ end
37
+
38
+ def http_status
39
+ 422
40
+ end
41
+
42
+ def title
43
+ 'Resource Not Unique'
44
+ end
45
+
46
+ def detail
47
+ @detail || <<~HEREDOC.chomp.tr("\n", ' ')
48
+ #{attribute.to_s.humanize} has already been used.
49
+ HEREDOC
50
+ end
51
+
52
+ def source
53
+ {
54
+ 'pointer' => pointer,
55
+ 'parameter' => attribute,
56
+ 'value' => value,
57
+ }
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'apple_core/refinements/string'
3
4
  require 'erratum/error'
4
5
  require 'erratum/errors/crud'
5
6
 
6
7
  module Erratum
7
8
  module Errors
8
9
  class ResourcePersistence < RuntimeError
10
+ using ::AppleCore::Refinements::String
11
+
9
12
  include Error
10
13
  include Errors::Crud
11
14
 
@@ -10,7 +10,9 @@ module RescuableResource
10
10
  base.rescue_from 'ActiveRecord::RecordInvalid',
11
11
  'ActiveRecord::RecordNotSaved',
12
12
  'ActiveRecord::RecordNotFound',
13
+ 'ActiveRecord::RecordNotUnique',
13
14
  'ActiveRecord::InvalidForeignKey',
15
+ 'ActiveRecord::ValueTooLong',
14
16
  'ActionController::ParameterMissing',
15
17
  'ActionController::UnpermittedParameters' do |exception|
16
18
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Erratum
4
- VERSION = '3.2.0'
4
+ VERSION = '3.3.0'
5
5
  end
data/lib/erratum.rb CHANGED
@@ -11,8 +11,10 @@ require 'erratum/errors/authentication/invalid_username_or_password'
11
11
  require 'erratum/errors/authorization'
12
12
  require 'erratum/errors/authorization/forbidden'
13
13
  require 'erratum/errors/crud'
14
+ require 'erratum/errors/crud/attribute_length'
14
15
  require 'erratum/errors/crud/invalid_association'
15
16
  require 'erratum/errors/crud/resource_not_found'
17
+ require 'erratum/errors/crud/resource_not_unique'
16
18
  require 'erratum/errors/crud/resource_persistence'
17
19
  require 'erratum/errors/request/parameter_missing'
18
20
  require 'erratum/errors/request/unpermitted_parameters'
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erratum
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thegranddesign
@@ -31,12 +31,15 @@ cert_chain:
31
31
  Y2GAoHKstmfIVhc4XHOPpmTd2o/C29O9oaRgjrkfQEhF/KvJ/PhoV5hvokzsCyI5
32
32
  iUeXPfvrGD/itYIBCgk+fnzyQQ4QtE5hTQaWQ3o2
33
33
  -----END CERTIFICATE-----
34
- date: 2018-05-22 00:00:00.000000000 Z
34
+ date: 2018-05-26 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: apple_core
38
38
  requirement: !ruby/object:Gem::Requirement
39
39
  requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.3.1
40
43
  - - "~>"
41
44
  - !ruby/object:Gem::Version
42
45
  version: '1.0'
@@ -44,6 +47,9 @@ dependencies:
44
47
  prerelease: false
45
48
  version_requirements: !ruby/object:Gem::Requirement
46
49
  requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.3.1
47
53
  - - "~>"
48
54
  - !ruby/object:Gem::Version
49
55
  version: '1.0'
@@ -135,8 +141,10 @@ files:
135
141
  - lib/erratum/errors/authorization.rb
136
142
  - lib/erratum/errors/authorization/forbidden.rb
137
143
  - lib/erratum/errors/crud.rb
144
+ - lib/erratum/errors/crud/attribute_length.rb
138
145
  - lib/erratum/errors/crud/invalid_association.rb
139
146
  - lib/erratum/errors/crud/resource_not_found.rb
147
+ - lib/erratum/errors/crud/resource_not_unique.rb
140
148
  - lib/erratum/errors/crud/resource_persistence.rb
141
149
  - lib/erratum/errors/request/parameter_missing.rb
142
150
  - lib/erratum/errors/request/unpermitted_parameters.rb
metadata.gz.sig CHANGED
Binary file