class EventStream::Subscriber

Public Class Methods

create(filter = nil, &action) click to toggle source
# 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

Public Instance Methods

consume(event) click to toggle source
# File lib/event_stream/subscriber.rb, line 14
def consume(event)
  action.call(event) if filter.call(event)
end