Sha256: 6a5c918ca7e65b40d0d1e006f2032c61206c9cd6e83bb7d71ff8d4622d274d72

Contents?: true

Size: 575 Bytes

Versions: 5

Compression:

Stored size: 575 Bytes

Contents

require 'active_support/inflector'
require_relative './event_worker'

module Materialist
  class EventHandler

    def initialize(options={})
      @options = options
    end

    def on_events_received(batch)
      batch.each { |event| call(event) if topics.include?(event['topic'].to_s) }
    end

    def call(event)
      worker.perform_async(event)
    end

    private

    attr_reader :options

    def topics
      @_topics ||= options.fetch(:topics, []).map(&:to_s)
    end

    def worker
      Materialist::EventWorker.set(options.slice(:queue))
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
materialist-2.1.0 lib/materialist/event_handler.rb
materialist-2.0.0 lib/materialist/event_handler.rb
materialist-1.0.0 lib/materialist/event_handler.rb
materialist-0.1.0 lib/materialist/event_handler.rb
materialist-0.0.6 lib/materialist/event_handler.rb