Class: JumpBack::PathFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/jump_back/path_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, path, options) ⇒ PathFinder

Returns a new instance of PathFinder.



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

def initialize(request, path, options)
  @uri = Urls.uri(request.env["HTTP_REFERER"])
  @path = determine_path(request, path, options)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/jump_back/path_finder.rb', line 4

def path
  @path
end

Instance Method Details

#has_referer?(request) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/jump_back/path_finder.rb', line 15

def has_referer?(request)
  !request.env["HTTP_REFERER"].blank? and request.env["HTTP_REFERER"] != request.env["REQUEST_URI"]
end

#is_local?(request, options) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/jump_back/path_finder.rb', line 19

def is_local?(request, options)
  return true if options[:offsite]
  !(host && host != request.host)
end

#redirect_back?(request, options) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/jump_back/path_finder.rb', line 11

def redirect_back?(request, options)
  has_referer?(request) ? is_local?(request, options) ? true : false : false
end