Class: Carter::ControllerResource

Inherits:
Object
  • Object
show all
Defined in:
lib/carter/controller_resource.rb

Overview

Handle the load cart controller logic so we don’t clutter up all controllers with non-interface methods. This class is used internally, so you do not need to call methods directly on it.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, *args) ⇒ ControllerResource

Returns a new instance of ControllerResource.



14
15
16
17
18
19
20
# File 'lib/carter/controller_resource.rb', line 14

def initialize(controller, *args)
  @controller = controller
  @params = controller.params
  @session = controller.session
  @options = args.extract_options!
  @name = args.first
end

Class Method Details

.add_before_filter(controller_class, method, *args) ⇒ Object

:nodoc:



6
7
8
9
10
11
12
# File 'lib/carter/controller_resource.rb', line 6

def self.add_before_filter(controller_class, method, *args)
  options = args.extract_options!
  resource_name = args.first
  controller_class.before_filter(options.slice(:only, :except)) do |controller|
    ControllerResource.new(controller, resource_name, options.except(:only, :except)).send(method)
  end
end

Instance Method Details

#load_cartObject



22
23
24
25
26
# File 'lib/carter/controller_resource.rb', line 22

def load_cart
  store_shopping_location if @controller.shopping? && !@controller.checking_out?
  @controller.instance_variable_set("@cart", load_cart_instance)
  @controller.instance_variable_set("@shopper", current_shopper)
end

#load_cart_for_checkoutObject



28
29
30
31
# File 'lib/carter/controller_resource.rb', line 28

def load_cart_for_checkout
  @controller.instance_variable_set("@cart", load_cart_instance)
  @controller.instance_variable_set("@shopper", current_shopper)
end