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

- (Responder) initialize(controller, resources, options = {})

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

- (Object) on_failure

Returns the value of attribute on_failure



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

def on_failure
  @on_failure
end

- (Object) on_success

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

- (Object) to_format



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

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

- (Object) to_html



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

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