Module: Glib::UrlsHelper

Defined in:
app/helpers/glib/urls_helper.rb

Instance Method Summary collapse

Instance Method Details

#glib_url_build(protocol, host, port, path, params = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/glib/urls_helper.rb', line 12

def glib_url_build(protocol, host, port, path, params = {})
  case (protocol = protocol.chomp('://'))
  when 'http'
    request_builder = URI::HTTP
  when 'https'
    request_builder = URI::HTTPS
  else
    Rollbar.warn("Unsupported protocol: #{protocol}")
  end

  request_builder.build(
    host: host,
    port: port,
    path: path,
    # Prevent trailing `?` when there is no params
    query: params.empty? ? nil : params.to_query
  )
end

#glib_url_current(replacement_params: params.to_unsafe_h, extra_params: {}) ⇒ Object



3
4
5
# File 'app/helpers/glib/urls_helper.rb', line 3

def glib_url_current(replacement_params: params.to_unsafe_h, extra_params: {})
  url_for(replacement_params.merge(extra_params.merge(only_path: false)))
end

#glib_url_equals_current?(url) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
# File 'app/helpers/glib/urls_helper.rb', line 7

def glib_url_equals_current?(url)
  route = Rails.application.routes.recognize_path(url)
  route[:controller] == controller_name && route[:action] == action_name
end