human_error 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/lib/human_error.rb +19 -1
  3. data/lib/human_error/configuration.rb +9 -1
  4. data/lib/human_error/error.rb +1 -1
  5. data/lib/human_error/error_code_directory.rb +1 -1
  6. data/lib/human_error/errors/authentication_error.rb +1 -1
  7. data/lib/human_error/errors/authentication_errors/duplicate_authentication_error.rb +1 -1
  8. data/lib/human_error/errors/authentication_errors/invalid_token_error.rb +1 -1
  9. data/lib/human_error/errors/authentication_errors/invalid_username_or_password_error.rb +1 -1
  10. data/lib/human_error/errors/crud_error.rb +1 -1
  11. data/lib/human_error/errors/crud_errors/resource_not_found_error.rb +1 -1
  12. data/lib/human_error/errors/crud_errors/resource_persistence_error.rb +1 -1
  13. data/lib/human_error/errors/request_error.rb +1 -1
  14. data/lib/human_error/knowledgebase_id_directory.rb +1 -1
  15. data/lib/human_error/utilities/string.rb +1 -1
  16. data/lib/human_error/version.rb +2 -2
  17. data/spec/lib/human_error/configuration_spec.rb +13 -1
  18. data/spec/lib/human_error/error_spec.rb +1 -1
  19. data/spec/lib/human_error/errors/authentication_errors/duplicate_authentication_error_spec.rb +1 -1
  20. data/spec/lib/human_error/errors/authentication_errors/invalid_token_error_spec.rb +1 -1
  21. data/spec/lib/human_error/errors/authentication_errors/invalid_username_or_password_error_spec.rb +1 -1
  22. data/spec/lib/human_error/errors/crud_errors/resource_not_found_error_spec.rb +1 -1
  23. data/spec/lib/human_error/errors/crud_errors/resource_persistence_error_spec.rb +1 -1
  24. data/spec/lib/human_error/errors/request_error_spec.rb +1 -1
  25. data/spec/lib/human_error_spec.rb +62 -0
  26. metadata +3 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b87c5a22db771619d2acebf4366be06025cf2fa
4
- data.tar.gz: 9264a39f94e6c6b054b608564ada1347418c907f
3
+ metadata.gz: 40266972f0c31dc4ec24f48df7d66a46f19a89a1
4
+ data.tar.gz: 08b74ad4f42e1ee8fa9fe53a51baf0dae31861b5
5
5
  SHA512:
6
- metadata.gz: d2cf3e74bda9aca504b2f17aef58a0533d29df07f91974ca94d43a81427b408fd255acbc88b6de1c71d26c470a6c8f0dd28a92130417975530b3eba8e1205315
7
- data.tar.gz: f14a129a5374268528578006185a1851168be6c7ef99c2d04da8337ffe83b1ff153ae3d8cca8964bf04bc1334b79e4b9076e858f0b32cb0b26de2b53976bdb7b
6
+ metadata.gz: c64dc30c85833c395b3b2b2a943ca972ad1c94ceb68a1a2f71a2a68e5020f0d1f22794ae4bca3f87e1bdd31318c6c5424892260c37f0ef251614277406d3d5fa
7
+ data.tar.gz: a6b564f1d96f02b53e7ffb01aaa0864035b20465125267d5fc3eefb266465b1d89e14eda573145238084f0afd70aeaf6474aac63c77016c3f668a50d665d361c
data/lib/human_error.rb CHANGED
@@ -2,5 +2,23 @@ require 'human_error/version'
2
2
  require 'human_error/error'
3
3
  require 'human_error/errors'
4
4
 
5
- module HumanError
5
+ class HumanError
6
+ attr_accessor :configuration
7
+
8
+ def initialize
9
+ self.configuration = Configuration.new
10
+
11
+ yield configuration if block_given?
12
+ end
13
+
14
+ def fetch(error_type, **args)
15
+ Object.const_get("HumanError::Errors::#{error_type}").
16
+ new(configuration.to_h.merge(**args))
17
+ end
18
+
19
+ def raise(error_type, **args)
20
+ error = fetch(error_type, **args)
21
+
22
+ Kernel.raise error
23
+ end
6
24
  end
@@ -1,8 +1,16 @@
1
- module HumanError
1
+ class HumanError
2
2
  class Configuration
3
3
  attr_accessor :api_version,
4
4
  :api_error_documentation_url,
5
5
  :knowledgebase_url
6
+
7
+ def to_h
8
+ {
9
+ knowledgebase_url: knowledgebase_url,
10
+ api_error_documentation_url: api_error_documentation_url,
11
+ api_version: api_version,
12
+ }
13
+ end
6
14
  end
7
15
 
8
16
  def self.configure
@@ -3,7 +3,7 @@ require 'human_error/configuration'
3
3
  require 'human_error/error_code_directory'
4
4
  require 'human_error/knowledgebase_id_directory'
5
5
 
6
- module HumanError
6
+ class HumanError
7
7
  module Error
8
8
  attr_accessor :api_version,
9
9
  :api_error_documentation_url,
@@ -1,4 +1,4 @@
1
- module HumanError
1
+ class HumanError
2
2
  class ErrorCodeDirectory
3
3
  def self.lookup(error_class)
4
4
  directory[error_class]
@@ -1,4 +1,4 @@
1
- module HumanError
1
+ class HumanError
2
2
  module Errors
3
3
  module AuthenticationError
4
4
  end
@@ -1,7 +1,7 @@
1
1
  require 'human_error/errors/request_error'
2
2
  require 'human_error/errors/authentication_error'
3
3
 
4
- module HumanError
4
+ class HumanError
5
5
  module Errors
6
6
  class DuplicateAuthenticationError < RequestError
7
7
  include AuthenticationError
@@ -1,7 +1,7 @@
1
1
  require 'human_error/errors/request_error'
2
2
  require 'human_error/errors/authentication_error'
3
3
 
4
- module HumanError
4
+ class HumanError
5
5
  module Errors
6
6
  class InvalidTokenError < RequestError
7
7
  include AuthenticationError
@@ -1,7 +1,7 @@
1
1
  require 'human_error/errors/request_error'
2
2
  require 'human_error/errors/authentication_error'
3
3
 
4
- module HumanError
4
+ class HumanError
5
5
  module Errors
6
6
  class InvalidUsernameOrPasswordError < RequestError
7
7
  include AuthenticationError
@@ -1,4 +1,4 @@
1
- module HumanError
1
+ class HumanError
2
2
  module Errors
3
3
  module CrudError
4
4
  attr_accessor :resource_name,
@@ -1,7 +1,7 @@
1
1
  require 'human_error/errors/crud_error'
2
2
  require 'human_error/errors/request_error'
3
3
 
4
- module HumanError
4
+ class HumanError
5
5
  module Errors
6
6
  class ResourceNotFoundError < RequestError
7
7
  include CrudError
@@ -1,7 +1,7 @@
1
1
  require 'human_error/errors/crud_error'
2
2
  require 'human_error/errors/request_error'
3
3
 
4
- module HumanError
4
+ class HumanError
5
5
  module Errors
6
6
  class ResourcePersistenceError < RequestError
7
7
  include CrudError
@@ -1,7 +1,7 @@
1
1
  require 'human_error/error'
2
2
  require 'human_error/utilities/string'
3
3
 
4
- module HumanError
4
+ class HumanError
5
5
  module Errors
6
6
  class RequestError < RuntimeError
7
7
  include HumanError::Error
@@ -1,4 +1,4 @@
1
- module HumanError
1
+ class HumanError
2
2
  class KnowledgebaseIdDirectory
3
3
  def self.lookup(error_class)
4
4
  directory[error_class]
@@ -1,4 +1,4 @@
1
- module HumanError
1
+ class HumanError
2
2
  module Utilities
3
3
  class String
4
4
  def self.underscore(other)
@@ -1,3 +1,3 @@
1
- module HumanError
2
- VERSION = '1.3.0'
1
+ class HumanError
2
+ VERSION = '1.4.0'
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require 'rspectacular'
2
2
  require 'human_error/configuration'
3
3
 
4
- module HumanError
4
+ class HumanError
5
5
  describe Configuration do
6
6
  it 'can set the API version' do
7
7
  configuration = Configuration.new
@@ -23,5 +23,17 @@ describe Configuration do
23
23
 
24
24
  expect(configuration.knowledgebase_url).to eql 'whateeeeeever'
25
25
  end
26
+
27
+ it 'can convert itself into a hash' do
28
+ configuration = Configuration.new
29
+ configuration.knowledgebase_url = 'knowledgebase_url'
30
+ configuration.api_error_documentation_url = 'api_error_documentation_url'
31
+ configuration.api_version = 'api_version'
32
+
33
+ expect(configuration.to_h).to eql(
34
+ knowledgebase_url: 'knowledgebase_url',
35
+ api_error_documentation_url: 'api_error_documentation_url',
36
+ api_version: 'api_version',)
37
+ end
26
38
  end
27
39
  end
@@ -5,7 +5,7 @@ class CustomError < RuntimeError
5
5
  extend HumanError::Error
6
6
  end
7
7
 
8
- module HumanError
8
+ class HumanError
9
9
  describe Error do
10
10
  it 'can wrap an error with another error' do
11
11
  original_error = RuntimeError.new('My Runtime Error Message')
@@ -1,7 +1,7 @@
1
1
  require 'rspectacular'
2
2
  require 'human_error/errors/authentication_errors/duplicate_authentication_error'
3
3
 
4
- module HumanError
4
+ class HumanError
5
5
  module Errors
6
6
  describe DuplicateAuthenticationError do
7
7
  let(:error) { DuplicateAuthenticationError.new(provider: 'flibbity',
@@ -1,7 +1,7 @@
1
1
  require 'rspectacular'
2
2
  require 'human_error/errors/authentication_errors/invalid_token_error'
3
3
 
4
- module HumanError
4
+ class HumanError
5
5
  module Errors
6
6
  describe InvalidTokenError do
7
7
  let(:error) { InvalidTokenError.new }
@@ -1,7 +1,7 @@
1
1
  require 'rspectacular'
2
2
  require 'human_error/errors/authentication_errors/invalid_username_or_password_error'
3
3
 
4
- module HumanError
4
+ class HumanError
5
5
  module Errors
6
6
  describe InvalidUsernameOrPasswordError do
7
7
  let(:error) { InvalidUsernameOrPasswordError.new }
@@ -1,7 +1,7 @@
1
1
  require 'rspectacular'
2
2
  require 'human_error/errors/crud_errors/resource_not_found_error'
3
3
 
4
- module HumanError
4
+ class HumanError
5
5
  module Errors
6
6
  describe ResourceNotFoundError do
7
7
  let(:error) { ResourceNotFoundError.new }
@@ -1,7 +1,7 @@
1
1
  require 'rspectacular'
2
2
  require 'human_error/errors/crud_errors/resource_persistence_error'
3
3
 
4
- module HumanError
4
+ class HumanError
5
5
  module Errors
6
6
  describe ResourcePersistenceError do
7
7
  let(:error) { ResourcePersistenceError.new }
@@ -1,7 +1,7 @@
1
1
  require 'rspectacular'
2
2
  require 'human_error/errors/request_error'
3
3
 
4
- module HumanError
4
+ class HumanError
5
5
  module Errors
6
6
  describe RequestError do
7
7
  it 'can generate error data' do
@@ -0,0 +1,62 @@
1
+ require 'rspectacular'
2
+ require 'human_error'
3
+
4
+ describe HumanError do
5
+ it 'can create an instance of HumanError' do
6
+ expect(HumanError.new).to be_a HumanError
7
+ end
8
+
9
+ it 'can configure each instance' do
10
+ human_error = HumanError.new do |config|
11
+ config.api_version = 'foo'
12
+ end
13
+
14
+ expect(human_error.configuration.api_version).to eql 'foo'
15
+ end
16
+
17
+ it 'can lookup errors' do
18
+ human_error = HumanError.new
19
+
20
+ expect(human_error.fetch('RequestError')).to be_a HumanError::Errors::RequestError
21
+ end
22
+
23
+ it 'can lookup errors based on the local configuration' do
24
+ human_error = HumanError.new do |config|
25
+ config.api_version = 'foo'
26
+ end
27
+
28
+ fetched_error = human_error.fetch('RequestError')
29
+
30
+ expect(fetched_error.api_version).to eql 'foo'
31
+ end
32
+
33
+ it 'can override values in the global configuration with values in the local configuration when looking up an error' do
34
+ HumanError.configure do |config|
35
+ config.api_version = 'bar'
36
+ end
37
+
38
+ human_error = HumanError.new do |config|
39
+ config.api_version = 'foo'
40
+ end
41
+
42
+ fetched_error = human_error.fetch('RequestError')
43
+
44
+ expect(fetched_error.api_version).to eql 'foo'
45
+ end
46
+
47
+ it 'can override values in the local configuration with explicit values passed when looking up an error' do
48
+ human_error = HumanError.new do |config|
49
+ config.api_version = 'foo'
50
+ end
51
+
52
+ fetched_error = human_error.fetch('RequestError', api_version: 'bar')
53
+
54
+ expect(fetched_error.api_version).to eql 'bar'
55
+ end
56
+
57
+ it 'can raise an error' do
58
+ human_error = HumanError.new
59
+
60
+ expect { human_error.raise('RequestError') }.to raise_error HumanError::Errors::RequestError
61
+ end
62
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: human_error
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jfelchner
@@ -85,6 +85,7 @@ files:
85
85
  - spec/lib/human_error/errors/crud_errors/resource_not_found_error_spec.rb
86
86
  - spec/lib/human_error/errors/crud_errors/resource_persistence_error_spec.rb
87
87
  - spec/lib/human_error/errors/request_error_spec.rb
88
+ - spec/lib/human_error_spec.rb
88
89
  homepage: https://github.com/thekompanee/human_error
89
90
  licenses: []
90
91
  metadata: {}
@@ -118,4 +119,5 @@ test_files:
118
119
  - spec/lib/human_error/errors/crud_errors/resource_not_found_error_spec.rb
119
120
  - spec/lib/human_error/errors/crud_errors/resource_persistence_error_spec.rb
120
121
  - spec/lib/human_error/errors/request_error_spec.rb
122
+ - spec/lib/human_error_spec.rb
121
123
  has_rdoc: