Class: Tracing::Filter::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/filters/executor/filter_exec.rb

Overview

enable execution of filters

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Executor

Returns a new instance of Executor.



7
8
9
10
11
12
13
# File 'lib/filters/executor/filter_exec.rb', line 7

def initialize(options)
  @final_yield_action = options[:final_yield_action] || :exclude
  @filters ||= []
  _filters = options.filters
  # puts "filters exec: #{_filters.inspect}"
  @filters.add(_filters)
end

Instance Attribute Details

#filtersObject

Returns the value of attribute filters.



5
6
7
# File 'lib/filters/executor/filter_exec.rb', line 5

def filters
  @filters
end

#final_yield_actionObject

Returns the value of attribute final_yield_action.



5
6
7
# File 'lib/filters/executor/filter_exec.rb', line 5

def final_yield_action
  @final_yield_action
end

Instance Method Details

#filters_allow?(msg, context) ⇒ Boolean

determine if message and context should pass through filter chain return:

  • true to allow

  • false to disallow

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/filters/executor/filter_exec.rb', line 19

def filters_allow?(msg, context)
  # puts "method: filters_allow?"
                  
  # default allow return value
  allow = (final_yield_action == :exclude ? false : true)               
  
  puts "default allow: #{allow}"
  # puts "filters: #{@filters}"  
  
  return allow if @filters.blank?        
  
  puts "iterate filters"
  @filters.each do |_filter|
    puts "filter:" + _filter.inspect
    # apply filter
    if _filter 
      res = _filter.allow_action(msg, context)
      puts "res: #{res}"  

      if (res == :include_and_yield)
        allow = true
      end

      if (res == :exclude_and_yield)
        allow = false
      end

      if (res == :include)
        # puts "included - break"
        allow = true
        break
      end
      
      if (res == :exclude) 
        # puts "excluded - break"              
        allow = false
        break
      end
      # puts "yielding..."
    else
      puts "filter is null"
    end
  end
  # puts "filters_allow?: #{allow}"
  return allow
end