Sha256: a3ebb169a2cdd387f4d41e108288b9887cf9a509627fb4fef6bfd9ee6135dd44

Contents?: true

Size: 1000 Bytes

Versions: 3

Compression:

Stored size: 1000 Bytes

Contents

require 'active_support/core_ext/class/subclasses'

module Nexaas
  module Auditor
    class Subscriber

      def self.subscribe_all
        subscribers = []
        subclasses.each do |klass|
          subscribers << klass.subscribe()
        end
        subscribers
      end

      def self.subscribe(options={})
        subscriber = options.fetch(:subscriber) { ::ActiveSupport::Notifications }
        subscriber.subscribe(pattern, new)
      end

      def self.pattern
        raise "Not Implemented, override in subclass and provide a regex or string."
      end

      # Dispatcher that converts incoming events to method calls.
      def call(name, start, finish, event_id, payload)
        method_name = event_method_name(name)
        if respond_to?(method_name)
          send(method_name, name, start, finish, event_id, payload)
        end
      end

      private

      def event_method_name(name)
        raise "Not Implemented, override in subclass."
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nexaas-auditor-1.0.2 lib/nexaas/auditor/subscriber.rb
nexaas-auditor-1.0.1 lib/nexaas/auditor/subscriber.rb
nexaas-auditor-1.0.0 lib/nexaas/auditor/subscriber.rb