Module: ContextFilters::Context::GlobalContext

Included in:
Global
Defined in:
lib/context-filters/context/global_context.rb

Overview

temporarily stack context and yield code

Instance Method Summary collapse

Instance Method Details

#context(options, &block) {|use| ... } ⇒ Object

starts new context

Parameters:

  • options (Object)

    options to start new context

  • block (Proc)

    code block that will enable filtering for the given options

Yields:

  • a block in which context_stack temporarily includes filter_block

Yield Parameters:

  • use (self)

    it optionally to give a new name to the code evaluated in new context



26
27
28
29
30
31
# File 'lib/context-filters/context/global_context.rb', line 26

def context(options, &block)
  context_stack.push(options)
  yield(self)
ensure
  context_stack.pop
end

#context_stackArray

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 the context stack.

Returns:

  • (Array)

    the context stack



16
17
18
# File 'lib/context-filters/context/global_context.rb', line 16

def context_stack
  @context_stack ||= [nil]
end