Module: Roda::RodaPlugins::SharedVars::InstanceMethods
- Defined in:
- lib/roda/plugins/shared_vars.rb
Instance Method Summary collapse
-
#shared(vars = nil) ⇒ Object
Returns the current shared vars for the request.
Instance Method Details
#shared(vars = nil) ⇒ Object
Returns the current shared vars for the request. These are stored in the request's environment, so they will be implicitly shared with other apps using this plugin.
If the vars argument is given, it should be a hash that will be
merged into the current shared vars.
If a block is given, a vars argument must be provided, and it will
only make the changes to the shared vars for the duration of the
block, restoring the previous shared vars before the block returns.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/roda/plugins/shared_vars.rb', line 61 def shared(vars=nil) h = env['roda.shared'] ||= {} if defined?(yield) if vars begin env['roda.shared'] = h.merge(vars) yield ensure env['roda.shared'] = h end else raise RodaError, "must pass a vars hash when calling shared with a block" end elsif vars h.merge!(vars) end h end |