human_error 2.0.0beta2 → 2.0.0beta3
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.
- checksums.yaml +4 -4
- data/lib/human_error/verifiable_model.rb +29 -0
- data/lib/human_error/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65f5bfdecabf2182e2a8426a80945ce3ac481475
|
4
|
+
data.tar.gz: c4c02e35713cb342dd9547e66873af66ebfcf647
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ddb6597d4e73eb78553a4f855336aea5cb8a3af441d2d5563de05c292100bacbdbef3047297a3a4792606802bbe90c62e52656f1e480dca5822a6cbc29fb49b
|
7
|
+
data.tar.gz: 17471de34359dbe7ebc2e261658cf0037af8924c721ed701667bded4d77ef9e38ab3087a22b5fc1914b1983d475ada4c244a52e36df1970c18c0d1a97e8d4707
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'human_error/errors/resource_not_found_error'
|
2
|
+
|
3
|
+
module HumanError
|
4
|
+
module VerifiableModel
|
5
|
+
module ClassMethods
|
6
|
+
def verify_model_exists(model_name = nil, options = {})
|
7
|
+
exceptions = options[:except] || %i{create index}
|
8
|
+
model_name ||= name[/::(\w+)Controller\z/, 1].
|
9
|
+
singularize.
|
10
|
+
downcase
|
11
|
+
|
12
|
+
before_action except: exceptions do
|
13
|
+
model = public_send(model_name)
|
14
|
+
|
15
|
+
resource_not_found_error = Errors::ResourceNotFoundError.new(
|
16
|
+
resource_name: model_name,
|
17
|
+
resource_id: params[:id],
|
18
|
+
)
|
19
|
+
|
20
|
+
fail resource_not_found_error unless model.persisted?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.included(base)
|
26
|
+
base.extend ClassMethods
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/human_error/version.rb
CHANGED
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.
|
4
|
+
version: 2.0.0beta3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jfelchner
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- lib/human_error/knowledgebase_id_directory.rb
|
79
79
|
- lib/human_error/rescuable_resource.rb
|
80
80
|
- lib/human_error/utilities/string.rb
|
81
|
+
- lib/human_error/verifiable_model.rb
|
81
82
|
- lib/human_error/version.rb
|
82
83
|
- spec/lib/human_error/configuration_spec.rb
|
83
84
|
- spec/lib/human_error/error_spec.rb
|