lib/action_controller/responder.rb in responders-2.4.1 vs lib/action_controller/responder.rb in responders-3.0.0
- old
+ new
@@ -1,7 +1,9 @@
-require 'active_support/json'
+# frozen_string_literal: true
+require "active_support/json"
+
module ActionController #:nodoc:
# Responsible for exposing a resource to different mime requests,
# usually depending on the HTTP verb. The responder is triggered when
# <code>respond_with</code> is called. The simplest case to study is a GET request:
#
@@ -119,16 +121,16 @@
# Using <code>respond_with</code> with a block follows the same syntax as <code>respond_to</code>.
class Responder
attr_reader :controller, :request, :format, :resource, :resources, :options
DEFAULT_ACTIONS_FOR_VERBS = {
- :post => :new,
- :patch => :edit,
- :put => :edit
+ post: :new,
+ patch: :edit,
+ put: :edit
}
- def initialize(controller, resources, options={})
+ def initialize(controller, resources, options = {})
@controller = controller
@request = @controller.request
@format = @controller.formats.first
@resource = resources.last
@resources = resources
@@ -140,12 +142,12 @@
location = options.delete(:location)
options[:location] = location.call unless has_errors?
end
end
- delegate :head, :render, :redirect_to, :to => :controller
- delegate :get?, :post?, :patch?, :put?, :delete?, :to => :request
+ delegate :head, :render, :redirect_to, to: :controller
+ delegate :get?, :post?, :patch?, :put?, :delete?, to: :request
# Undefine :to_json and :to_yaml since it's defined on Object
undef_method(:to_json) if method_defined?(:to_json)
undef_method(:to_yaml) if method_defined?(:to_yaml)
@@ -211,11 +213,11 @@
raise MissingRenderer.new(format) unless has_renderer?
if get?
display resource
elsif post?
- display resource, :status => :created, :location => api_location
+ display resource, status: :created, location: api_location
else
head :no_content
end
end
@@ -254,11 +256,11 @@
#
# Results in:
#
# render xml: @user, status: :created
#
- def display(resource, given_options={})
+ def display(resource, given_options = {})
controller.render given_options.merge!(options).merge!(format => resource)
end
def display_errors
controller.render format => resource_errors, :status => :unprocessable_entity
@@ -289,10 +291,10 @@
def resource_errors
respond_to?("#{format}_resource_errors", true) ? send("#{format}_resource_errors") : resource.errors
end
def json_resource_errors
- {:errors => resource.errors}
+ { errors: resource.errors }
end
def response_overridden?
@default_response.present?
end