Class: Spree::Responder

Inherits:
ActionController::Responder
  • Object
show all
Defined in:
lib/spree_core/spree_custom_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.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/spree_core/spree_custom_responder.rb', line 6

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 = (result.respond_to?(:call) ? result : result[:success])
    self.on_failure = (result.respond_to?(:call) ? result : result[:failure])
  end
end

Instance Attribute Details

#on_failureObject

Returns the value of attribute on_failure.



4
5
6
# File 'lib/spree_core/spree_custom_responder.rb', line 4

def on_failure
  @on_failure
end

#on_successObject

Returns the value of attribute on_success.



4
5
6
# File 'lib/spree_core/spree_custom_responder.rb', line 4

def on_success
  @on_success
end

Instance Method Details

#to_formatObject



23
24
25
26
# File 'lib/spree_core/spree_custom_responder.rb', line 23

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

#to_htmlObject



18
19
20
21
# File 'lib/spree_core/spree_custom_responder.rb', line 18

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