rocket_pants 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rocket_pants/active_record.rb +2 -1
- data/lib/rocket_pants/errors.rb +11 -10
- data/lib/rocket_pants/locale/en.yml +2 -1
- metadata +2 -2
@@ -5,6 +5,7 @@ module RocketPants
|
|
5
5
|
|
6
6
|
included do
|
7
7
|
map_error! ActiveRecord::RecordNotFound, RocketPants::NotFound
|
8
|
+
map_error! ActiveRecord::RecordNotUnique, RocketPants::Conflict
|
8
9
|
map_error!(ActiveRecord::RecordNotSaved) { RocketPants::InvalidResource.new nil }
|
9
10
|
map_error! ActiveRecord::RecordInvalid do |exception|
|
10
11
|
RocketPants::InvalidResource.new exception.record.errors
|
@@ -16,4 +17,4 @@ module RocketPants
|
|
16
17
|
end
|
17
18
|
|
18
19
|
end
|
19
|
-
end
|
20
|
+
end
|
data/lib/rocket_pants/errors.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
module RocketPants
|
2
2
|
|
3
3
|
require 'rocket_pants/error'
|
4
|
-
|
4
|
+
|
5
5
|
# A simple map of data about errors that the rocket pants system can handle.
|
6
6
|
class Errors
|
7
|
-
|
7
|
+
|
8
8
|
@@errors = {}
|
9
|
-
|
9
|
+
|
10
10
|
# Returns a hash of all known errors, keyed by their error name.
|
11
11
|
# @return [Hash{Symbol => RocketPants::Error}] the hash of known errors.
|
12
12
|
def self.all
|
13
13
|
@@errors.dup
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
# Looks up a specific error from the given name, returning nil if none are found.
|
17
17
|
# @param [#to_sym] name the name of the error to look up.
|
18
18
|
# @return [Error, nil] the error class if found, otherwise nil.
|
19
19
|
def self.[](name)
|
20
20
|
@@errors[name.to_sym]
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
# Adds a given Error class in the list of all errors, making it suitable
|
24
24
|
# for lookup via [].
|
25
25
|
# @see Errors[]
|
@@ -27,7 +27,7 @@ module RocketPants
|
|
27
27
|
def self.add(error)
|
28
28
|
@@errors[error.error_name] = error
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
# Creates an error class to represent a given error state.
|
32
32
|
# @param [Symbol] name the name of the given error
|
33
33
|
# @param [Hash] options the options used to create the error class.
|
@@ -47,7 +47,7 @@ module RocketPants
|
|
47
47
|
add klass
|
48
48
|
klass
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
# The default set of exceptions.
|
52
52
|
register! :throttled, :http_status => :service_unavailable
|
53
53
|
register! :unauthenticated, :http_status => :unauthorized
|
@@ -55,7 +55,8 @@ module RocketPants
|
|
55
55
|
register! :not_implemented, :http_status => :service_unavailable
|
56
56
|
register! :not_found, :http_status => :not_found
|
57
57
|
register! :bad_request, :http_status => :bad_request
|
58
|
-
|
58
|
+
register! :conflict, :http_status => :conflict
|
59
|
+
|
59
60
|
end
|
60
61
|
|
61
62
|
class InvalidResource < RocketPants::Error
|
@@ -78,7 +79,7 @@ module RocketPants
|
|
78
79
|
end
|
79
80
|
|
80
81
|
Errors.add self
|
81
|
-
|
82
|
+
|
82
83
|
end
|
83
|
-
|
84
|
+
|
84
85
|
end
|
@@ -7,4 +7,5 @@ en:
|
|
7
7
|
not_implemented: "The feature you requested has not yet been implemented and hence is currently unavailable."
|
8
8
|
not_found: "The requested resource could not be found."
|
9
9
|
bad_request: "The data given to this server does not meet our criteria."
|
10
|
-
invalid_resource: "The current resource was deemed invalid."
|
10
|
+
invalid_resource: "The current resource was deemed invalid."
|
11
|
+
conflict: "The request conflicts with an existing resource."
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rocket_pants
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|