human_error 2.0.0beta5 → 2.0.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
  SHA1:
3
- metadata.gz: 33b97f5fc873078c76b8be169bf591567124bf3b
4
- data.tar.gz: 1a0f066015ef29e4cbcaa2b1187e7387dfc7ad7a
3
+ metadata.gz: 17aba5f28df14fa69f37785ddb08659985741d9b
4
+ data.tar.gz: a39be0f21794151eaebf056663e327b3499b3b91
5
5
  SHA512:
6
- metadata.gz: aeba38a51e63f37a7bca77b7323e43d646ed1680c79a84eeacde16e0b90a82c2ab17dd1f4063e8d83a6e79ad4670f94ef453cb4761f8ef344be1c1f22ab2b94d
7
- data.tar.gz: 948255600142d7f28b0660ae40e32257e78b2fb47112f8f962824b031d360e6efa2dc18f8f942aaaefe2ed41ff2e73d39c140c966b085bed0c0a64b096d33fc5
6
+ metadata.gz: 88747c7a2352b0cdd2d7b9867c481f033b987f353b1af78faa649ebfeb6c015dc23fdf2b0b550eb01e63e0710d397549da10857ab72d85395ea28a2ca97bd8ec
7
+ data.tar.gz: 1d4b15fbb41d93ed4eb13854d21d39535a7a402ecbbcb66b4fd4c9504ebcd656534efd3ba2081214539d0832bcf0cd5ed3eccfc1350d135a8c29e1ca70b75ce7
@@ -7,14 +7,14 @@ module RescuableResource
7
7
  module ClassMethods
8
8
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Style/GuardClause
9
9
  def rescue_resource(resource_name, from:, via:)
10
- resource_class_name = resource_name.classify
11
- lookup_library = via
10
+ nice_resource_name = resource_name.humanize.downcase
11
+ lookup_library = via
12
12
 
13
13
  if from.include? 'persistence'
14
14
  rescue_from 'ActiveRecord::RecordInvalid',
15
15
  'ActiveRecord::RecordNotSaved' do |exception|
16
16
  human_error = lookup_library.convert(exception,
17
- resource_name: resource_class_name,
17
+ resource_name: nice_resource_name,
18
18
  action: action_name)
19
19
 
20
20
  render json: human_error,
@@ -25,7 +25,7 @@ module RescuableResource
25
25
  if from.include? 'not_found'
26
26
  rescue_from 'ActiveRecord::RecordNotFound' do |exception|
27
27
  human_error = lookup_library.convert(exception,
28
- resource_name: resource_class_name,
28
+ resource_name: nice_resource_name,
29
29
  action: action_name)
30
30
 
31
31
  render json: human_error,
@@ -36,13 +36,18 @@ module RescuableResource
36
36
  if from.include? 'association'
37
37
  rescue_from 'ActiveRecord::InvalidForeignKey' do |exception|
38
38
  human_error = lookup_library.convert(exception,
39
- resource_name: resource_class_name,
39
+ resource_name: nice_resource_name,
40
40
  action: action_name)
41
41
 
42
42
  render json: human_error,
43
43
  status: human_error.http_status
44
44
  end
45
45
  end
46
+
47
+ rescue_from 'HumanError::Error' do |exception|
48
+ render json: exception,
49
+ status: exception.http_status
50
+ end
46
51
  end
47
52
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Style/GuardClause
48
53
  end
@@ -1,20 +1,21 @@
1
- require 'human_error/errors/resource_not_found_error'
2
-
3
- module HumanError
1
+ class HumanError
4
2
  module VerifiableModel
5
3
  module ClassMethods
6
- def verify_model_exists(model_name = nil, options = {})
7
- exceptions = options[:except] || %i{create index}
4
+ def verify_model_exists(model_name = nil, options = {}, via: HumanError.new)
5
+ exceptions = options[:except] || %i{create index}
6
+ lookup_library = via
8
7
  model_name ||= name[/::(\w+)Controller\z/, 1].
9
- singularize.
10
- downcase
8
+ singularize.
9
+ downcase
11
10
 
12
11
  before_action except: exceptions do
13
12
  model = public_send(model_name)
14
13
 
15
- resource_not_found_error = Errors::ResourceNotFoundError.new(
14
+ resource_not_found_error = lookup_library.build(
15
+ 'ResourceNotFoundError',
16
16
  resource_name: model_name,
17
- resource_id: params[:id],
17
+ resource_id: [params[:id]],
18
+ action: action_name,
18
19
  )
19
20
 
20
21
  fail resource_not_found_error unless model.persisted?
@@ -1,3 +1,3 @@
1
1
  class HumanError
2
- VERSION = '2.0.0beta5'
2
+ VERSION = '2.0.0'
3
3
  end
data/lib/human_error.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'human_error/version'
2
2
  require 'human_error/error'
3
3
  require 'human_error/errors'
4
+ require 'human_error/rescuable_resource'
5
+ require 'human_error/verifiable_model'
4
6
 
5
7
  class HumanError
6
8
  attr_accessor :configuration
@@ -36,8 +38,6 @@ class HumanError
36
38
  end
37
39
 
38
40
  def raise(error_type, **args)
39
- error = build(error_type, **args)
40
-
41
- Kernel.raise error
41
+ Kernel.raise build(error_type, **args)
42
42
  end
43
43
  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: 2.0.0beta5
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jfelchner
@@ -106,9 +106,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - ">"
109
+ - - ">="
110
110
  - !ruby/object:Gem::Version
111
- version: 1.3.1
111
+ version: '0'
112
112
  requirements: []
113
113
  rubyforge_project:
114
114
  rubygems_version: 2.4.6