module Roda::RodaPlugins::SharedVars::InstanceMethods

def shared(vars=nil)

block, restoring the previous shared vars before the block returns.
only make the changes to the shared vars for the duration of the
If a block is given, a +vars+ argument must be provided, and it will

merged into the current shared vars.
If the +vars+ argument is given, it should be a hash that will be

shared with other apps using this plugin.
stored in the request's environment, so they will be implicitly
Returns the current shared vars for the request. These are
def shared(vars=nil)
  h = env[KEY] ||= {}
  if block_given?
    if vars
      begin
        env[KEY] = Hash[h].merge!(vars)
        yield
      ensure
        env[KEY] = 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