Skip to content

Commit

Permalink
Fix easy rubocop issues
Browse files Browse the repository at this point in the history
  • Loading branch information
luisramos0 committed Jul 6, 2020
1 parent 4f195bf commit cb2eb0f
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions lib/spree/responder.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
# frozen_string_literal: true

module Spree
class Responder < ::ActionController::Responder #:nodoc:

attr_accessor :on_success, :on_failure

def initialize(controller, resources, options={})
def initialize(controller, resources, options = {})
super

class_name = controller.class.name.to_sym
action_name = options.delete(:action_name)

if result = Spree::BaseController.spree_responders[class_name].try(:[], action_name).try(:[], self.format.to_sym)
self.on_success = handler(controller, result, :success)
self.on_failure = handler(controller, result, :failure)
end
result = Spree::BaseController.spree_responders[class_name].
try(:[], action_name).
try(:[], self.format.to_sym)
return unless result

self.on_success = handler(controller, result, :success)
self.on_failure = handler(controller, result, :failure)
end

def to_html
super and return if !(on_success || on_failure)
if !(on_success || on_failure)
super
return
end

has_errors? ? controller.instance_exec(&on_failure) : controller.instance_exec(&on_success)
end

def to_format
super and return if !(on_success || on_failure)
if !(on_success || on_failure)
super
return
end

has_errors? ? controller.instance_exec(&on_failure) : controller.instance_exec(&on_success)
end

Expand Down

0 comments on commit cb2eb0f

Please sign in to comment.