Skip to content

Commit

Permalink
Use class_attribute to allow changing statuses per-responder
Browse files Browse the repository at this point in the history
If an app happens to have multiple responders on different controllers
(which is entirely possible), they may not want to share the same set of
statuses for responses. `cattr_accessor` would make that a global value
across all of the apps responders, while `class_attribute` can be
changed on each class individually if necessary (while still respecting
the inherited values if any is set), making it much more flexible.

Also disable instance writer and predicate methods, we only need access
to read those values from the instance.
  • Loading branch information
carlosantoniodasilva committed Jan 27, 2023
1 parent 9efc80b commit 447065c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/action_controller/responder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ module ActionController # :nodoc:
#
# Using <code>respond_with</code> with a block follows the same syntax as <code>respond_to</code>.
class Responder
cattr_accessor :error_status, default: :ok
cattr_accessor :redirect_status, default: :found
class_attribute :error_status, default: :ok, instance_writer: false, instance_predicate: false
class_attribute :redirect_status, default: :found, instance_writer: false, instance_predicate: false

attr_reader :controller, :request, :format, :resource, :resources, :options

DEFAULT_ACTIONS_FOR_VERBS = {
Expand Down

0 comments on commit 447065c

Please sign in to comment.