Class: Aitch::Location
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.
7 8 9 10 |
# File 'lib/aitch/location.rb', line 7 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.
5 6 7 |
# File 'lib/aitch/location.rb', line 5 def current_url @current_url end |
#redirect_stack ⇒ Object (readonly)
Returns the value of attribute redirect_stack.
5 6 7 |
# File 'lib/aitch/location.rb', line 5 def redirect_stack @redirect_stack end |
Instance Method Details
#find_uri_with_host ⇒ Object
22 23 24 25 26 |
# File 'lib/aitch/location.rb', line 22 def find_uri_with_host redirect_stack.reverse .map {|url| ::URI.parse(url) } .find(&:scheme) end |
#location ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/aitch/location.rb', line 12 def location return current_url unless current_url.match(%r{\A/}) 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 |