module Shopper::CurrentOrder

Constants

KEY

Public Instance Methods

create_current_order() click to toggle source
# File lib/shopper/current_order.rb, line 17
def create_current_order
  @current_order = create_order
  set_id(@current_order.id)
  @current_order
end
current_order() click to toggle source
# File lib/shopper/current_order.rb, line 11
def current_order
  @current_order ||= Shopper::Order.find(get_id)
rescue ActiveRecord::RecordNotFound
  create_current_order
end

Private Instance Methods

create_order() click to toggle source
# File lib/shopper/current_order.rb, line 43
def create_order
  Shopper::Order.create
end
get_id() click to toggle source
# File lib/shopper/current_order.rb, line 30
def get_id
  use_signed ? cookies.signed[KEY] : cookies[KEY]
end
set_id(id) click to toggle source
# File lib/shopper/current_order.rb, line 34
def set_id(id)
  hash = { value: id, expires: Shopper.expires_after.from_now }
  if use_signed
    cookies.signed[KEY] = hash
  else
    cookies[KEY] = hash
  end
end
use_signed() click to toggle source

show_me_the_cookies can`t operate with signed cookies

# File lib/shopper/current_order.rb, line 26
def use_signed
  !Rails.env.test?
end