Module: ContextFilters::Context::Global

Includes:
GlobalContext, GlobalFilters
Included in:
ContextFilters::Context
Defined in:
lib/context-filters/context/global.rb

Overview

builds list of filters and provides dsl for building nested context and allows evaluating filters on methods in the current context

Instance Method Summary collapse

Methods included from GlobalFilters

#filter, #initialize_priority_filters, #priority_filters

Methods included from GlobalContext

#context, #context_stack

Instance Method Details

#evaluate_filters(target, method) { ... } ⇒ Object

evaluates all matching filters for given context_stack, allows to do extra work for priority.nil? or on the end of the priorities,

Parameters:

  • method (Proc)

    the method to evaluate with filters matching current context

Yields:

  • on first priority.nil? or on the end when none



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/context-filters/context/global.rb', line 24

def evaluate_filters(target, method)
  local_called = false

  priority_filters.each do |priority, filters|

    context_stack.each { |options| filters.apply(target, method, options) }

    if priority.nil? && block_given? && !local_called
      yield
      local_called = true
    end

  end

  yield if block_given? && !local_called
end