Class: Hanami::Slice::Router Private
- Defined in:
- lib/hanami/slice/router.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.
‘Hanami::Router` subclass with enhancements for use within Hanami apps.
This is loaded from Hanami apps and slices and made available as their router.
Instance Attribute Summary collapse
- #middleware_stack ⇒ Object readonly private
- #path_prefix ⇒ Object readonly private
Instance Method Summary collapse
- #freeze ⇒ Object private
-
#initialize(routes:, middleware_stack: Routing::Middleware::Stack.new, prefix: ::Hanami::Router::DEFAULT_PREFIX, **kwargs, &blk) ⇒ Router
constructor
private
A new instance of Router.
-
#slice(slice_name, at:, &blk) ⇒ Object
Yields a block for routes to resolve their action components from the given slice.
- #to_rack_app ⇒ Object private
- #use(*args, **kwargs, &blk) ⇒ Object private
Constructor Details
#initialize(routes:, middleware_stack: Routing::Middleware::Stack.new, prefix: ::Hanami::Router::DEFAULT_PREFIX, **kwargs, &blk) ⇒ Router
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 Router.
25 26 27 28 29 30 |
# File 'lib/hanami/slice/router.rb', line 25 def initialize(routes:, middleware_stack: Routing::Middleware::Stack.new, prefix: ::Hanami::Router::DEFAULT_PREFIX, **kwargs, &blk) @path_prefix = Hanami::Router::Prefix.new(prefix) @middleware_stack = middleware_stack instance_eval(&blk) super(**kwargs, &routes) end |
Instance Attribute Details
#middleware_stack ⇒ Object (readonly)
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.
17 18 19 |
# File 'lib/hanami/slice/router.rb', line 17 def middleware_stack @middleware_stack end |
#path_prefix ⇒ Object (readonly)
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.
21 22 23 |
# File 'lib/hanami/slice/router.rb', line 21 def path_prefix @path_prefix end |
Instance Method Details
#freeze ⇒ 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.
34 35 36 37 38 39 |
# File 'lib/hanami/slice/router.rb', line 34 def freeze return self if frozen? remove_instance_variable(:@middleware_stack) super end |
#slice(slice_name, at:, &blk) ⇒ Object
Yields a block for routes to resolve their action components from the given slice.
An optional URL prefix may be supplied with ‘at:`.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/hanami/slice/router.rb', line 68 def slice(slice_name, at:, &blk) blk ||= @resolver.find_slice(slice_name).routes prev_resolver = @resolver @resolver = @resolver.to_slice(slice_name) scope(at, &blk) ensure @resolver = prev_resolver end |
#to_rack_app ⇒ 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.
81 82 83 |
# File 'lib/hanami/slice/router.rb', line 81 def to_rack_app middleware_stack.to_rack_app(self) end |
#use(*args, **kwargs, &blk) ⇒ 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.
43 44 45 |
# File 'lib/hanami/slice/router.rb', line 43 def use(*args, **kwargs, &blk) middleware_stack.use(*args, **kwargs.merge(path_prefix: path_prefix.to_s), &blk) end |