Class: Camayoc::Handlers::Filter
- Inherits:
-
Object
- Object
- Camayoc::Handlers::Filter
- Defined in:
- lib/camayoc/handlers/filter.rb
Instance Method Summary collapse
- #event(ev) ⇒ Object
-
#initialize(dest, options = {}, &block) ⇒ Filter
constructor
- 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
.
- Handler *
- Constructor - by default, returns true *
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,={},&block) @dest = dest if block_given? @filter = block elsif [:with] pattern = [:with] @filter = Proc.new {|event| event.ns_stat =~ pattern } elsif [:if] @filter = [:if] elsif [:unless] proc = [: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 |