Class: Federails::Utils::Host

Inherits:
Object
  • Object
show all
Defined in:
lib/federails/utils/host.rb

Constant Summary collapse

COMMON_PORTS =
[80, 443].freeze

Class Method Summary collapse

Class Method Details

.local_route(url) ⇒ ActionDispatch::Routing::RouteSet?

Gets the route on the current instance, or nil

Parameters:

  • url (String)

    URL to check

Returns:

  • (ActionDispatch::Routing::RouteSet, nil)

    nil when URL do not match a route



32
33
34
35
36
37
38
# File 'lib/federails/utils/host.rb', line 32

def local_route(url)
  return nil unless local_url? url

  Rails.application.routes.recognize_path(url)
rescue ActionController::RoutingError
  nil
end

.local_url?(url) ⇒ true, false

Checks if the given URL points somewhere on current instance

Parameters:

  • url (String)

    URL to check

Returns:

  • (true, false)


20
21
22
23
24
# File 'lib/federails/utils/host.rb', line 20

def local_url?(url)
  uri = URI.parse url
  host = host_and_port uri.host, uri.port
  localhost == host
end

.localhostString

Returns Host and port of the current instance.

Returns:

  • (String)

    Host and port of the current instance



9
10
11
12
# File 'lib/federails/utils/host.rb', line 9

def localhost
  uri = URI.parse Federails.configuration.site_host
  host_and_port (uri.host || 'localhost'), Federails.configuration.site_port
end