ocean-rails 1.15.1 → 1.15.2
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/ocean/ocean_application_controller.rb +10 -2
- data/lib/ocean/ocean_resource_controller.rb +22 -5
- data/lib/ocean/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb83c996f5ed1355575bfef824fd57198d217b0c
|
4
|
+
data.tar.gz: 47068ec2c58bfae1caae10623905a61a3fc4d5cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 255be647bf5dbdd373b83bcfae78a7132fb5cd6dd9702c92f7c8e890cebc8fc3c53b1d9b16fdeb17e763bbe046799de9c1a75b91a68ac23373c3c1a120ea3290
|
7
|
+
data.tar.gz: b7b01f48ee1741343532974100b1aede44f03ca00b880fee645dd87d8043e847565c2a98c57b26726a6a393007a3cfe233279a8bc243b9274de22937191f1f06
|
@@ -121,8 +121,16 @@ module OceanApplicationController
|
|
121
121
|
#
|
122
122
|
# The messages are intended for presentation to an end user.
|
123
123
|
#
|
124
|
-
|
125
|
-
|
124
|
+
# The keyword argument +except+, if present, must be a string, symbol or an
|
125
|
+
# array of strings or symbols and will suppress error information for the
|
126
|
+
# enumerated attributes of the same names. This is sometimes useful when internal
|
127
|
+
# attributes which never appear in external resource representations depend on
|
128
|
+
# user-provided data, such as password hashes and salts.
|
129
|
+
#
|
130
|
+
def render_validation_errors(r, except: [])
|
131
|
+
except = [except] unless except.is_a?(Array)
|
132
|
+
except = except.collect(&:to_sym)
|
133
|
+
render json: r.errors.messages.except(except), :status => 422
|
126
134
|
end
|
127
135
|
|
128
136
|
#
|
@@ -4,6 +4,15 @@
|
|
4
4
|
#
|
5
5
|
|
6
6
|
module Ocean
|
7
|
+
|
8
|
+
#
|
9
|
+
# This module is included in ActionController::Base. The most notable effect
|
10
|
+
# is that the class method +ocean_resource_controller+ becomes available, and that
|
11
|
+
# rescue_from handlers are added to handle exceptions for non-unique, stale, and
|
12
|
+
# invalid records. These all terminate the current action and return standard
|
13
|
+
# JSON API errors and validation errors. This allows +POST+ and +PUT+ actions
|
14
|
+
# to be written in a very terse, clear and understandable manner.
|
15
|
+
#
|
7
16
|
module OceanResourceController
|
8
17
|
|
9
18
|
extend ActiveSupport::Concern
|
@@ -12,7 +21,7 @@ module Ocean
|
|
12
21
|
if defined? ActiveRecord
|
13
22
|
rescue_from ActiveRecord::RecordNotUnique,
|
14
23
|
ActiveRecord::StatementInvalid do |x|
|
15
|
-
render_api_error 422, "
|
24
|
+
render_api_error 422, "Resource not unique"
|
16
25
|
end
|
17
26
|
|
18
27
|
rescue_from ActiveRecord::StaleObjectError do |x|
|
@@ -20,7 +29,7 @@ module Ocean
|
|
20
29
|
end
|
21
30
|
|
22
31
|
rescue_from ActiveRecord::RecordInvalid do |x|
|
23
|
-
render_validation_errors x.record
|
32
|
+
render_validation_errors x.record, except: ocean_resource_controller_no_validation_errors_on
|
24
33
|
end
|
25
34
|
end
|
26
35
|
end
|
@@ -30,7 +39,7 @@ module Ocean
|
|
30
39
|
#
|
31
40
|
# The presence of +ocean_resource_controller+ in a Rails controller declares
|
32
41
|
# that the controller is an Ocean controller handling an Ocean resource. It takes
|
33
|
-
#
|
42
|
+
# three optional keyword parameters:
|
34
43
|
#
|
35
44
|
# +required_attributes+: a list of keywords naming model attributes which must be
|
36
45
|
# present in every update operation. If an API consumer submits data where any
|
@@ -38,6 +47,11 @@ module Ocean
|
|
38
47
|
#
|
39
48
|
# ocean_resource_controller required_attributes: [:lock_version, :title]
|
40
49
|
#
|
50
|
+
# +no_validation_errors_on+: a symbol, string, or an array of symbols and strings. Error
|
51
|
+
# descriptions in 422 responses will not include the enumerated attributes. This
|
52
|
+
# is sometimes useful for purely internal attributes which should never appear
|
53
|
+
# in error descriptions.
|
54
|
+
#
|
41
55
|
# +extra_actions+: a hash containing information about extra controller actions
|
42
56
|
# apart from the standard Rails ones of +index+, +show+, +create+, +update+, and
|
43
57
|
# +destroy+. One entry per extra action is required in order to process authentication
|
@@ -52,13 +66,16 @@ module Ocean
|
|
52
66
|
# that +comment_create+ will be called as the result of a +POST+ to the same hyperlink.
|
53
67
|
# Thus, +extra_actions+ maps actions to hyperlink names and HTTP methods.
|
54
68
|
#
|
55
|
-
def ocean_resource_controller(required_attributes:
|
56
|
-
|
69
|
+
def ocean_resource_controller(required_attributes: [:lock_version, :name, :description],
|
70
|
+
no_validation_errors_on: [],
|
71
|
+
extra_actions: {}
|
57
72
|
)
|
58
73
|
cattr_accessor :ocean_resource_controller_extra_actions
|
59
74
|
cattr_accessor :ocean_resource_controller_required_attributes
|
75
|
+
cattr_accessor :ocean_resource_controller_no_validation_errors_on
|
60
76
|
self.ocean_resource_controller_extra_actions = extra_actions
|
61
77
|
self.ocean_resource_controller_required_attributes = required_attributes
|
78
|
+
self.ocean_resource_controller_no_validation_errors_on = no_validation_errors_on
|
62
79
|
end
|
63
80
|
end
|
64
81
|
|
data/lib/ocean/version.rb
CHANGED