Class: EventStream::Subscriber
- Inherits:
-
Struct
- Object
- Struct
- EventStream::Subscriber
- Defined in:
- lib/event_stream/subscriber.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#filter ⇒ Object
Returns the value of attribute filter.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action
2 3 4 |
# File 'lib/event_stream/subscriber.rb', line 2 def action @action end |
#filter ⇒ Object
Returns the value of attribute filter
2 3 4 |
# File 'lib/event_stream/subscriber.rb', line 2 def filter @filter end |
Class Method Details
.create(filter = nil, &action) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/event_stream/subscriber.rb', line 3 def self.create(filter = nil, &action) filter ||= lambda { |e| true } filter_predicate = case filter when Symbol, String then lambda { |e| e.name.to_s == filter.to_s } when Regexp then lambda { |e| e.name =~ filter } when Hash then lambda { |e| filter.all? { |k,v| e[k] === v } } else filter end new(filter_predicate, action) end |
Instance Method Details
#consume(event) ⇒ Object
14 15 16 |
# File 'lib/event_stream/subscriber.rb', line 14 def consume(event) action.call(event) if filter.call(event) end |