Module: ContextFilters::Context::Local

Included in:
ContextFilters::Context
Defined in:
lib/context-filters/context/local.rb

Overview

allow defining local filters and evaluating code in context of thems

Instance Method Summary collapse

Instance Method Details

#evaluate_local_filters(target, method) ⇒ Object

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.

iterates over local_filters and applies them to the given method

Parameters:

  • method (Proc)

    a method to call with each filter stored in local_filters



37
38
39
# File 'lib/context-filters/context/local.rb', line 37

def evaluate_local_filters(target, method)
  local_filters.each { |block| target.send(method, &block) }
end

#local_filter(filter_block) { ... } ⇒ Object

temporarly adds filter_block to the list of filters to run and yields given block of code

Parameters:

  • filter_block (Proc)

    a block of code to add to the list

Yields:

  • a block in which local_filters temporarily includes filter_block



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

def local_filter(filter_block, &block)
  local_filters.push(filter_block)
  block.call
ensure
  local_filters.pop
end

#local_filtersArray<Proc>

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 list of blocks to evaluate.

Returns:

  • (Array<Proc>)

    list of blocks to evaluate



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

def local_filters
  @local_filters ||= []
end