Module: Ocean::OceanResourceController::ClassMethods
- Defined in:
- lib/ocean/ocean_resource_controller.rb
Instance Method Summary collapse
-
#ocean_resource_controller(required_attributes: [:lock_version], permitted_attributes: [], no_validation_errors_on: [], extra_actions: {}) ⇒ Object
The presence of
ocean_resource_controller
in a Rails controller declares that the controller is an Ocean controller handling an Ocean resource.
Instance Method Details
#ocean_resource_controller(required_attributes: [:lock_version], permitted_attributes: [], no_validation_errors_on: [], extra_actions: {}) ⇒ Object
The presence of ocean_resource_controller
in a Rails controller declares that the controller is an Ocean controller handling an Ocean resource. It takes three optional keyword parameters:
required_attributes
: a list of keywords naming model attributes which must be present. If an API consumer submits data where any of these attributes isn’t present, an API error will be generated.
ocean_resource_controller required_attributes: [:lock_version, :title]
permitted_attributes
: a list of keywords naming model attributes which may be present. Attributes not in permitted_attributes
or required_attributes
will be filtered away.
no_validation_errors_on
: a symbol, string, or an array of symbols and strings. Error descriptions in 422 responses will not include the enumerated attributes. This is sometimes useful for purely internal attributes which should never appear in error descriptions.
ocean_resource_controller no_validation_errors_on: [:password_hash, :password_salt]
extra_actions
: a hash containing information about extra controller actions apart from the standard Rails ones of index
, show
, create
, update
, and destroy
. One entry per extra action is required in order to process authorisation requests. Here’s an example:
ocean_resource_controller extra_actions: {'comments' => ['comments', "GET"],
'comment_create' => ['comments', "POST"]}
The above example declares that the controller has two non-standard actions called comments
and comments_create
, respectively. Their respective values indicate that comments
will be called as the result of a GET
to the comments
hyperlink, and that comment_create
will be called as the result of a POST
to the same hyperlink. Thus, extra_actions
maps actions to hyperlink names and HTTP methods.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ocean/ocean_resource_controller.rb', line 89 def ocean_resource_controller(required_attributes: [:lock_version], permitted_attributes: [], no_validation_errors_on: [], extra_actions: {} ) cattr_accessor :ocean_resource_controller_extra_actions cattr_accessor :ocean_resource_controller_required_attributes cattr_accessor :ocean_resource_controller_permitted_attributes cattr_accessor :ocean_resource_controller_no_validation_errors_on self.ocean_resource_controller_extra_actions = extra_actions self.ocean_resource_controller_required_attributes = required_attributes self.ocean_resource_controller_permitted_attributes = permitted_attributes self.ocean_resource_controller_no_validation_errors_on = no_validation_errors_on end |