Module: ContextFilters::LocalContext

Included in:
Context
Defined in:
lib/context-filters/local_context.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/local_context.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 temporarly includes filter_block



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

def local_filter(filter_block, &block)
  local_filters.push(filter_block)
  block.call
ensure
  local_filters.pop
  nil
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



14
15
16
# File 'lib/context-filters/local_context.rb', line 14

def local_filters
  @local_filters ||= []
end