Class: SourceRoute::TraceFilter
- Defined in:
- lib/source_route/trace_filter.rb
Instance Attribute Summary collapse
-
#cond ⇒ Object
Returns the value of attribute cond.
Instance Method Summary collapse
-
#block_it?(tp) ⇒ Boolean
to improve performance, we didnt assign tp as instance variable.
-
#initialize(condition) ⇒ TraceFilter
constructor
A new instance of TraceFilter.
- #negative_check(tp) ⇒ Object
- #positives_check(tp) ⇒ Object
Constructor Details
#initialize(condition) ⇒ TraceFilter
Returns a new instance of TraceFilter.
5 6 7 |
# File 'lib/source_route/trace_filter.rb', line 5 def initialize(condition) @cond = condition end |
Instance Attribute Details
#cond ⇒ Object
Returns the value of attribute cond.
4 5 6 |
# File 'lib/source_route/trace_filter.rb', line 4 def cond @cond end |
Instance Method Details
#block_it?(tp) ⇒ Boolean
to improve performance, we didnt assign tp as instance variable
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/source_route/trace_filter.rb', line 10 def block_it?(tp) if @cond.track_params return true if negative_check(tp) if positives_check(tp) return !tp.binding.eval('local_variables').any? do |v| tp.binding.local_variable_get(v).object_id == @cond.track_params end end else return true if negative_check(tp) return false if positives_check(tp) end true # default is blocked the tp end |
#negative_check(tp) ⇒ Object
25 26 27 28 29 |
# File 'lib/source_route/trace_filter.rb', line 25 def negative_check(tp) cond.negatives.any? do |method_key, value| tp.send(method_key).to_s =~ Regexp.new(value) end end |
#positives_check(tp) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/source_route/trace_filter.rb', line 31 def positives_check(tp) return true if cond.positives == {} cond.positives.any? do |method_key, value| if method_key.to_sym == :defined_class tp.send(method_key).name =~ Regexp.new(value) else tp.send(method_key).to_s =~ Regexp.new(value) end end end |