Module: Settei::Extensions::HostUrl

Defined in:
lib/settei/extensions/host_url.rb

Overview

For computing the a string for host settings. There can be multiple host settings such as asset host.

Instance Method Summary collapse

Instance Method Details

#host(server = :default, params = {}) ⇒ String

Returns host domain.

Parameters:

  • server (String, Symbol) (defaults to: :default)

    name of host

  • params (Hash) (defaults to: {})

    segment key-values to override default. A false value can hide that segment.

Options Hash (params):

  • :protocol (String, false)
  • :subdomain (String, false)
  • :domain (String, false)
  • :port (Integer, false)

Returns:

  • (String)

    host domain


12
13
14
15
16
17
18
19
20
21
22
# File 'lib/settei/extensions/host_url.rb', line 12

def host(server = :default, params = {})
  default_params = dig(:hosts, server)
  params = default_params.merge(params)

  url = ''
  url << params[:protocol].clone << '://' if params[:protocol]
  url << params[:subdomain].clone << '.' if params[:subdomain]
  url << params[:domain]
  url << ':' << params[:port].to_s if params[:port]
  url
end