Class: Hanami::Router::UrlHelpers Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/router/url_helpers.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0

Instance Method Summary collapse

Constructor Details

#initialize(base_url) ⇒ UrlHelpers

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of UrlHelpers.

Since:

  • 2.0.0



13
14
15
16
# File 'lib/hanami/router/url_helpers.rb', line 13

def initialize(base_url)
  @base_url = base_url
  @named = {}
end

Instance Method Details

#add(name, segment) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



20
21
22
# File 'lib/hanami/router/url_helpers.rb', line 20

def add(name, segment)
  @named[name] = segment
end

#path(name, variables = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



26
27
28
29
30
31
32
# File 'lib/hanami/router/url_helpers.rb', line 26

def path(name, variables = {})
  @named.fetch(name.to_sym) do
    raise MissingRouteError.new(name)
  end.expand(:append, variables)
rescue Mustermann::ExpandError => exception
  raise InvalidRouteExpansionError.new(name, exception.message)
end

#url(name, variables = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



36
37
38
# File 'lib/hanami/router/url_helpers.rb', line 36

def url(name, variables = {})
  @base_url + path(name, variables)
end