apill 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64584404ef059886afa2b62c3f93cec935403b70
4
- data.tar.gz: 013020e5633701dad588d2ecfc560710e6c63052
3
+ metadata.gz: ff96f7974bef65a5d6314935d8bd50c88ea8bab0
4
+ data.tar.gz: b4b202271017a57ffcdc708ab66f39a6eb7ab6e9
5
5
  SHA512:
6
- metadata.gz: 1a221f3a0f1cf27bb149a08652107cfe1f0d4780d9fbcdae8dd357f4e54498822a7fb54b271e8d528ef1e888a8e6ad7710f770e78d5f750d3810d53093238344
7
- data.tar.gz: 9984076eef45d1ede48945647204bda066214edf7dda7196906c8f07a7ef88cb8acc81601978be65ff8f875961273e0bba879726f2d13666315c25eecbc462c0
6
+ metadata.gz: ddeb0420f3581463f812dc1e83aa6bf96ab9e7218ca584bb84de0c51a10dc3def92b8b79c240f4c1ae85af87bca057d103fe905477cdbc88a77947e6c7ca7908
7
+ data.tar.gz: aa39e6f3095ac102306e18bca65b6dccd51a84ef941b80bd488b65079c5a4cf9caf721dd3a513ad2401c32ddeabc07c8a4d6a5fcd83084e1f38b4510a1cf557d
@@ -0,0 +1,56 @@
1
+ require 'human_error'
2
+
3
+ module Apill
4
+ module RescuableResource
5
+ module ClassMethods
6
+ def rescue_resource(resource_name, from:, via:)
7
+ lookup_library = via
8
+
9
+ if from.include? 'persistence'
10
+ rescue_from HumanError::Errors::ResourcePersistenceError do |e|
11
+ error = lookup_library.fetch(
12
+ 'ResourcePersistenceError',
13
+ resource_name: e.resource_name,
14
+ attributes: e.attributes,
15
+ errors: e.errors,
16
+ action: action_name)
17
+
18
+ render json: error,
19
+ status: error.http_status
20
+ end
21
+ end
22
+
23
+ if from.include? 'not_found'
24
+ rescue_from HumanError::Errors::ResourceNotFoundError do |e|
25
+ error = lookup_library.fetch(
26
+ 'ResourceNotFoundError',
27
+ resource_name: e.resource_name,
28
+ resource_id: e.resource_id,
29
+ action: action_name)
30
+
31
+ render json: error,
32
+ status: error.http_status
33
+ end
34
+ end
35
+
36
+ if from.include? 'association'
37
+ rescue_from HumanError::Errors::AssociationError do |e|
38
+ error = lookup_library.fetch(
39
+ 'AssociationError',
40
+ resource_name: e.resource_name,
41
+ association_name: e.association_name,
42
+ association_id: e.association_id,
43
+ attributes: e.attributes)
44
+
45
+ render json: error,
46
+ status: error.http_status
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ def self.included(base)
53
+ base.extend ClassMethods
54
+ end
55
+ end
56
+ end
data/lib/apill/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Apill
2
- VERSION = '1.3.0'
2
+ VERSION = '1.4.0'
3
3
  end
@@ -0,0 +1,7 @@
1
+ require 'rspectacular'
2
+ require 'apill/rescuable_resource'
3
+
4
+ module Apill
5
+ describe RescuableResource do
6
+ end
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apill
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
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-29 00:00:00.000000000 Z
11
+ date: 2014-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: human_error
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.2'
19
+ version: '1.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.2'
26
+ version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 3.0beta
33
+ version: '3.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 3.0beta
40
+ version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspectacular
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.23'
47
+ version: '0.38'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.23'
54
+ version: '0.38'
55
55
  description: ''
56
56
  email: accounts+git@thekompanee.com
57
57
  executables: []
@@ -71,6 +71,7 @@ files:
71
71
  - lib/apill/matchers/invalid_api_request_matcher.rb
72
72
  - lib/apill/matchers/subdomain_matcher.rb
73
73
  - lib/apill/matchers/version_matcher.rb
74
+ - lib/apill/rescuable_resource.rb
74
75
  - lib/apill/responses/invalid_api_request_response.rb
75
76
  - lib/apill/version.rb
76
77
  - spec/lib/apill/accept_header_spec.rb
@@ -79,6 +80,7 @@ files:
79
80
  - spec/lib/apill/matchers/invalid_api_request_matcher_spec.rb
80
81
  - spec/lib/apill/matchers/subdomain_matcher_spec.rb
81
82
  - spec/lib/apill/matchers/version_matcher_spec.rb
83
+ - spec/lib/apill/rescuable_resource_spec.rb
82
84
  homepage: https://github.com/jfelchner/apill
83
85
  licenses: []
84
86
  metadata: {}
@@ -110,4 +112,4 @@ test_files:
110
112
  - spec/lib/apill/matchers/invalid_api_request_matcher_spec.rb
111
113
  - spec/lib/apill/matchers/subdomain_matcher_spec.rb
112
114
  - spec/lib/apill/matchers/version_matcher_spec.rb
113
- has_rdoc:
115
+ - spec/lib/apill/rescuable_resource_spec.rb