module Roda::RodaPlugins::SharedVars::InstanceMethods

  1. lib/roda/plugins/shared_vars.rb

Methods

Public Instance

  1. shared

Public Instance methods

shared(vars=nil)

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.

[show source]
   # File lib/roda/plugins/shared_vars.rb
61 def shared(vars=nil)
62   h = env['roda.shared'] ||= {}
63 
64   if defined?(yield)
65     if vars
66       begin
67         env['roda.shared'] = h.merge(vars)
68         yield
69       ensure
70         env['roda.shared'] = h
71       end
72     else
73       raise RodaError, "must pass a vars hash when calling shared with a block"
74     end
75   elsif vars
76     h.merge!(vars)
77   end
78 
79   h
80 end