Sha256: 6f47e9c92d113d57b05115fd34f071764fa4aa47a67c0b4fb6510f47a9397580

Contents?: true

Size: 874 Bytes

Versions: 5

Compression:

Stored size: 874 Bytes

Contents

module Massive
  module Notifications
    extend ActiveSupport::Concern

    included do
      notifier :base
    end

    def notify(message)
      if active_model_serializer
        notifier.notify(message) do
          active_model_serializer.new(reload)
        end
      end
    end

    def notifier
      @notifier ||= self.class.notifier_class.new(notifier_id, self.class.notifier_options)
    end

    def notifier_id
      "#{self.class.name.underscore.gsub('/', '-')}-#{id}"
    end

    module ClassMethods
      def notifier(name, options={})
        @notifier_class = name.is_a?(Class) ? name : "massive/notifiers/#{name}".camelize.constantize
        @notifier_options = options
      end

      def notifier_class
        @notifier_class || Massive::Notifiers::Base
      end

      def notifier_options
        @notifier_options
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
massive-0.4.0 lib/massive/notifications.rb
massive-0.3.0 lib/massive/notifications.rb
massive-0.2.0 lib/massive/notifications.rb
massive-0.1.1 lib/massive/notifications.rb
massive-0.1.0 lib/massive/notifications.rb