Sha256: 836c8c9f859b97c62b5fca66552d289093e4cb7dd6d70bd6b44a1e1981762b59

Contents?: true

Size: 563 Bytes

Versions: 2

Compression:

Stored size: 563 Bytes

Contents

module JumpBack
  
  module Urls
    
    def self.is_url?(string)
      is_uri?(string) || is_path?(string)
    end
    
    def self.uri(string)
      URI.parse string if is_uri? string
    end
    
    def self.is_uri?(string)
      uri = URI.parse string
      %w( http https ).include? uri.scheme
      rescue URI::BadURIError
      false
      rescue URI::InvalidURIError
      false
    end
    
    def self.is_path?(string)
      !!(Rails.application.routes.recognize_path string)
      rescue ActionController::RoutingError
      false
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jump_back-0.3.2 lib/jump_back/urls.rb
jump_back-0.3.1 lib/jump_back/urls.rb