Module: JumpBack

Defined in:
lib/jump_back.rb,
lib/jump_back/engine.rb,
lib/jump_back/version.rb,
lib/jump_back/redirect_back.rb,
lib/jump_back/return_to_referer.rb,
lib/jump_back/referer_interpreter.rb,
lib/jump_back/redirection_determiner.rb

Defined Under Namespace

Classes: Engine, RedirectionDeterminer, RefererInterpreter

Constant Summary collapse

VERSION =
"0.2.1"

Instance Method Summary collapse

Instance Method Details

#clear_refererObject



12
13
14
# File 'lib/jump_back/return_to_referer.rb', line 12

def clear_referer
  session.delete(:jump_back_stored_referer)
end

#parse_jump_back_arguments(path, options) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/jump_back/redirect_back.rb', line 11

def parse_jump_back_arguments(path, options)
  if path.is_a? Hash
    options = path
    path = root_path
  end
  
  jump_back_options = { offsite: options.delete(:offsite) }
  {
    redirect_options: options,
    jump_back_options: jump_back_options,
    path: path
  }
end

#redirect_back(path = root_path, options = {}) ⇒ Object



6
7
8
9
# File 'lib/jump_back/redirect_back.rb', line 6

def redirect_back(path=root_path, options={})
  parsed_args = parse_jump_back_arguments(path, options)
  redirect_to RedirectionDeterminer.new(request, parsed_args[:path], parsed_args[:jump_back_options]).path, parsed_args[:redirect_options]
end

#return_to_referer(path = root_path, options = {}) ⇒ Object



7
8
9
10
# File 'lib/jump_back/return_to_referer.rb', line 7

def return_to_referer(path=root_path, options={})
  parsed_args = parse_jump_back_arguments(path, options)
  session[:jump_back_stored_referer] ? redirect_to(clear_referer, parsed_args[:redirect_options]) : redirect_to(parsed_args[:path], parsed_args[:redirect_options])
end

#save_refererObject



3
4
5
# File 'lib/jump_back/return_to_referer.rb', line 3

def save_referer
  session[:jump_back_stored_referer] ||= request.referer
end