Class: Aitch::Location
Constant Summary collapse
- MATCHER =
%r{\A/}
Instance Attribute Summary collapse
-
#current_url ⇒ Object
readonly
Returns the value of attribute current_url.
-
#redirect_stack ⇒ Object
readonly
Returns the value of attribute redirect_stack.
Instance Method Summary collapse
- #find_uri_with_host ⇒ Object
-
#initialize(redirect_stack, current_url) ⇒ Location
constructor
A new instance of Location.
- #location ⇒ Object
Constructor Details
#initialize(redirect_stack, current_url) ⇒ Location
Returns a new instance of Location.
9 10 11 12 |
# File 'lib/aitch/location.rb', line 9 def initialize(redirect_stack, current_url) @redirect_stack = redirect_stack @current_url = current_url end |
Instance Attribute Details
#current_url ⇒ Object (readonly)
Returns the value of attribute current_url.
7 8 9 |
# File 'lib/aitch/location.rb', line 7 def current_url @current_url end |
#redirect_stack ⇒ Object (readonly)
Returns the value of attribute redirect_stack.
7 8 9 |
# File 'lib/aitch/location.rb', line 7 def redirect_stack @redirect_stack end |
Instance Method Details
#find_uri_with_host ⇒ Object
24 25 26 27 28 |
# File 'lib/aitch/location.rb', line 24 def find_uri_with_host redirect_stack.reverse .map {|url| ::URI.parse(url) } .find(&:scheme) end |
#location ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/aitch/location.rb', line 14 def location return current_url unless current_url.match?(MATCHER) uri = find_uri_with_host url = ["#{uri.scheme}://#{uri.hostname}"] url << ":#{uri.port}" unless [80, 443].include?(uri.port) url << current_url url.join end |