Module: Pancake::Mixins::RequestHelper
- Included in:
- Stacks::Short::Controller
- Defined in:
- lib/pancake/mixins/request_helper.rb
Overview
Some helpers for requests that come in handy for applications that are part of stacks
Constant Summary collapse
- VAULT_KEY =
'pancake.request.vault'
Instance Method Summary collapse
-
#base_url(opts = {}) ⇒ Object
Generate the base url for the router that got you to this point.
-
#env ⇒ Object
An accessor for the rack environment variable.
-
#env=(env) ⇒ Object
A setter for the rack environment.
-
#logger ⇒ Object
Provides access to the logger object in rack.logger.
-
#request ⇒ Object
A handy request method that gets hold of the current request object for the current rack request.
-
#url(name, opts = {}) ⇒ Object
Generate a url for the current stacks router.
-
#url_for(app_name, name_or_opts, opts = {}) ⇒ Object
Generate a url for any registered configuration with a router.
-
#vault ⇒ Object
(also: #v)
A data vault that allows you to carry data accross middlewares, controller / views etc.
Instance Method Details
#base_url(opts = {}) ⇒ Object
Generate the base url for the router that got you to this point.
end
@see Usher
@see Pancake::Router.base_url_for
@see Pancake::Router#base_url
@api public
@author Daniel Neighman
66 67 68 69 |
# File 'lib/pancake/mixins/request_helper.rb', line 66 def base_url(opts={}) konfig = request.env[Pancake::Router::CONFIGURATION_KEY] konfig.router.base_url(opts) end |
#env ⇒ Object
An accessor for the rack environment variable
101 102 103 |
# File 'lib/pancake/mixins/request_helper.rb', line 101 def env @env end |
#env=(env) ⇒ Object
A setter for the rack environment
95 96 97 |
# File 'lib/pancake/mixins/request_helper.rb', line 95 def env=(env) @env = env end |
#logger ⇒ Object
Provides access to the logger object in rack.logger
122 123 124 |
# File 'lib/pancake/mixins/request_helper.rb', line 122 def logger env[Pancake::Constants::ENV_LOGGER_KEY] end |
#request ⇒ Object
A handy request method that gets hold of the current request object for the current rack request. Any including class must provide an env
method that exposes the rack request environment
113 114 115 |
# File 'lib/pancake/mixins/request_helper.rb', line 113 def request @request ||= Rack::Request.new(env) end |
#url(name, opts = {}) ⇒ Object
Generate a url for the current stacks router.
41 42 43 44 |
# File 'lib/pancake/mixins/request_helper.rb', line 41 def url(name, opts = {}) konfig = request.env[Pancake::Router::CONFIGURATION_KEY] konfig.router.generate(name, opts) end |
#url_for(app_name, name_or_opts, opts = {}) ⇒ Object
Generate a url for any registered configuration with a router
:some_app)
url_for(:some_app, :my_named_route)
# An application with no name specified
url_for(MyApp, :my_named_route)
85 86 87 88 89 90 91 |
# File 'lib/pancake/mixins/request_helper.rb', line 85 def url_for(app_name, name_or_opts, opts = {}) if konfig = Pancake.configuration.configs[app_name] konfig.router.generate(name_or_opts, opts) else raise Pancake::Errors::UnknownConfiguration end end |