Class: Hanami::Router::UrlHelpers Private
- Inherits:
-
Object
- Object
- Hanami::Router::UrlHelpers
- 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.
Instance Method Summary collapse
- #add(name, segment) ⇒ Object private
-
#initialize(base_url) ⇒ UrlHelpers
constructor
private
A new instance of UrlHelpers.
- #path(name, variables = {}) ⇒ Object private
- #url(name, variables = {}) ⇒ Object private
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.
14 15 16 17 18 19 20 |
# File 'lib/hanami/router/url_helpers.rb', line 14 def initialize(base_url) @base_url = URI(base_url) @named = {} prefix = @base_url.path prefix = DEFAULT_PREFIX if prefix.empty? @prefix = Prefix.new(prefix) 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.
24 25 26 |
# File 'lib/hanami/router/url_helpers.rb', line 24 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.
30 31 32 33 34 35 36 |
# File 'lib/hanami/router/url_helpers.rb', line 30 def path(name, variables = {}) @named.fetch(name.to_sym) do raise MissingRouteError.new(name) end.(:append, variables) rescue Mustermann::ExpandError => exception raise InvalidRouteExpansionError.new(name, exception.) 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.
40 41 42 |
# File 'lib/hanami/router/url_helpers.rb', line 40 def url(name, variables = {}) @base_url + @prefix.join(path(name, variables)).to_s end |