Class: Spree::Responder

Inherits:
ActionController::Responder
  • Object
show all
Defined in:
lib/spree/responder.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, resources, options = {}) ⇒ Responder

Returns a new instance of Responder.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/spree/responder.rb', line 5

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(:[], format.to_sym)
    self.on_success = handler(controller, result, :success)
    self.on_failure = handler(controller, result, :failure)
  end
end

Instance Attribute Details

#on_failureObject

Returns the value of attribute on_failure.



3
4
5
# File 'lib/spree/responder.rb', line 3

def on_failure
  @on_failure
end

#on_successObject

Returns the value of attribute on_success.



3
4
5
# File 'lib/spree/responder.rb', line 3

def on_success
  @on_success
end

Instance Method Details

#to_formatObject



22
23
24
25
# File 'lib/spree/responder.rb', line 22

def to_format
  super && return unless on_success || on_failure
  has_errors? ? controller.instance_exec(&on_failure) : controller.instance_exec(&on_success)
end

#to_htmlObject



17
18
19
20
# File 'lib/spree/responder.rb', line 17

def to_html
  super && return unless on_success || on_failure
  has_errors? ? controller.instance_exec(&on_failure) : controller.instance_exec(&on_success)
end