Module: JumpBack::Urls

Defined in:
lib/jump_back/urls.rb

Class Method Summary collapse

Class Method Details

.is_path?(string) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/jump_back/urls.rb', line 22

def self.is_path?(string)
  !!(Rails.application.routes.recognize_path string)
  rescue ActionController::RoutingError
  false
end

.is_uri?(string) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
# File 'lib/jump_back/urls.rb', line 13

def self.is_uri?(string)
  uri = URI.parse string
  %w( http https ).include? uri.scheme
  rescue URI::BadURIError
  false
  rescue URI::InvalidURIError
  false
end

.is_url?(string) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/jump_back/urls.rb', line 5

def self.is_url?(string)
  is_uri?(string) || is_path?(string)
end

.uri(string) ⇒ Object



9
10
11
# File 'lib/jump_back/urls.rb', line 9

def self.uri(string)
  URI.parse string if is_uri? string
end