Sha256: 8e6be4aa95b8eb32dc5b0be308cd66b5fd7af7833c5c3b12a401540443629d0e

Contents?: true

Size: 588 Bytes

Versions: 5

Compression:

Stored size: 588 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
      @_worker ||= Materialist::EventWorker.set(options.slice(:queue))
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
materialist-0.0.5 lib/materialist/event_handler.rb
materialist-0.0.4 lib/materialist/event_handler.rb
materialist-0.0.3 lib/materialist/event_handler.rb
materialist-0.0.2 lib/materialist/event_handler.rb
materialist-0.0.1 lib/materialist/event_handler.rb