Class: Camayoc::Handlers::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/camayoc/handlers/filter.rb

Instance Method Summary collapse

Constructor Details

#initialize(dest, options = {}, &block) ⇒ Filter

Constructor - by default, returns true

  • dest

    Handler

  • options[]

  • + :with+

    Regexp matching against event namespace

  • + :if+

    Proc taking type and event returning true

  • + :unless+

    Converse of if



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/camayoc/handlers/filter.rb', line 11

def initialize(dest,options={},&block)
  @dest = dest
  if block_given?
    @filter = block
  elsif options[:with]
    pattern = options[:with]
    @filter = Proc.new {|event| event.ns_stat =~ pattern }
  elsif options[:if]
    @filter = options[:if]
  elsif options[:unless]
    proc = options[:unless]
    @filter = Proc.new do |event|
      !proc.call(event)
    end
  else
    @filter = Proc.new { true }
  end
end

Instance Method Details

#event(ev) ⇒ Object



30
31
32
33
34
# File 'lib/camayoc/handlers/filter.rb', line 30

def event(ev)
  if @filter.call(ev)
    @dest.event(ev)
  end
end