Class: Spree::UserLastUrlStorer

Inherits:
Object
  • Object
show all
Defined in:
core/app/models/spree/user_last_url_storer.rb,
core/app/models/spree/user_last_url_storer/rules/authentication_rule.rb

Overview

This service object is responsible for storing the current path into into `session` for redirects after successful user/admin authentication.

Defined Under Namespace

Modules: Rules

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ UserLastUrlStorer

Returns a new instance of UserLastUrlStorer

Parameters:

  • controller (ApplicationController)

    an instance of ApplicationController or its subclasses. The controller will be passed to each rule for matching.



27
28
29
# File 'core/app/models/spree/user_last_url_storer.rb', line 27

def initialize(controller)
  @controller = controller
end

Class Method Details

.rulesSpree::Core::ClassConstantizer::Set

Lists all the rules that will be evaluated before storing the current path value into the session.

Examples:

This method can be used also to add more rules

Spree::UserLastUrlStorer.rules << 'CustomRule'

it can be used also for removing unwanted rules

Spree::UserLastUrlStorer.rules.delete('CustomRule')

Returns:

  • (Spree::Core::ClassConstantizer::Set)

    a set of rules that, when matched, will prevent session to be set



21
22
23
# File 'core/app/models/spree/user_last_url_storer.rb', line 21

def self.rules
  Spree::Config.user_last_url_storer_rules
end

Instance Method Details

#store_locationObject

Stores into session the request full path for future redirects (to be used after successful authentication). When there is a rule match then the request full path is not stored.



34
35
36
37
38
# File 'core/app/models/spree/user_last_url_storer.rb', line 34

def store_location
  return if self.class.rules.any? { |rule| rule.match? controller }

  session[:spree_user_return_to] = request.fullpath.gsub('//', '/')
end