Class: Decidim::UrlOptionResolver

Inherits:
Object
  • Object
show all
Defined in:
decidim-core/lib/decidim/url_option_resolver.rb

Overview

A class for resolving the default URL options.

Instance Method Summary collapse

Instance Method Details

#default_port?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'decidim-core/lib/decidim/url_option_resolver.rb', line 46

def default_port?
  [443, 80].include?(port)
end

#hostObject



20
21
22
23
24
25
26
27
# File 'decidim-core/lib/decidim/url_option_resolver.rb', line 20

def host
  @host ||= begin
    default_host = nil
    default_host = "localhost" if Rails.env.development? || Rails.env.test?

    ENV.fetch("HOSTNAME", default_host)
  end
end

#optionsObject



6
7
8
9
10
11
12
# File 'decidim-core/lib/decidim/url_option_resolver.rb', line 6

def options
  {}.tap do |opts|
    opts[:host] = host if host
    opts[:port] = port unless default_port?
    opts[:protocol] = protocol if protocol == "https"
  end
end

#portObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'decidim-core/lib/decidim/url_option_resolver.rb', line 29

def port
  @port ||= begin
    default_port =
      if Rails.env.development?
        3000
      elsif Rails.env.test?
        Capybara.server_port
      elsif Rails.application.config.force_ssl
        443
      else
        80
      end

    ENV.fetch("HTTP_PORT", default_port).to_i
  end
end

#protocolObject



14
15
16
17
18
# File 'decidim-core/lib/decidim/url_option_resolver.rb', line 14

def protocol
  return "https" if Rails.application.config.force_ssl || port == 443

  "http"
end