ocean-rails 1.15.1 → 1.15.2

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: 19c67f131eebfdd7b791385da29ad67e15566d4c
4
- data.tar.gz: 3cc8700d6debe7d91b4147dc51218e19b9d3e109
3
+ metadata.gz: eb83c996f5ed1355575bfef824fd57198d217b0c
4
+ data.tar.gz: 47068ec2c58bfae1caae10623905a61a3fc4d5cb
5
5
  SHA512:
6
- metadata.gz: ba8d33698a52ead461f73dd811b928b17e6bbf203fd2daf70153ab05372ec546d9d8e3b45295d2b98342609e55a381727e05cb8adf0769f01992bec9f2ce69b8
7
- data.tar.gz: 2c87f83ef4bbf11636fae72a91f379335cdcefa93043b7c3b747cb2d2e288d6af8234d71a3b2b5ef17a6ccb10bb4f59679a3390e9f93606e012dc26c8dec42a0
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
- def render_validation_errors(r)
125
- render json: r.errors, :status => 422
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, "#{controller_name.singularize.camelize} already exists"
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
- # two keyword parameters:
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: [:lock_version, :name, :description],
56
- extra_actions: {}
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
 
@@ -1,3 +1,3 @@
1
1
  module Ocean
2
- VERSION = "1.15.1"
2
+ VERSION = "1.15.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocean-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.15.1
4
+ version: 1.15.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Bengtson