Sha256: 507333f296db4cc6ad0f14403cddaa203ce5f0da43b35c1dcecbafa30ea876f7

Contents?: true

Size: 1.3 KB

Versions: 9

Compression:

Stored size: 1.3 KB

Contents

require 'notification-handler'
require 'active_support'

module NotificationPusher
    module NotificationLibrary

        extend ActiveSupport::Concern

        included do
            attr_accessor :pusher
            attr_accessor :pusher_options

            after_create_commit :initialize_pusher

            include NotificationPusher::NotificationLibrary::InstanceMethods
        end

        module InstanceMethods

            def push name, options = {}
                self.pusher = name
                self.pusher_options = options
                self.initialize_pusher
            end

            protected

            def initialize_pusher
                unless self.pusher.nil?
                    if self.pusher.kind_of?(Array)
                        self.pusher.each do |class_name|
                            pusher = NotificationPusher::Pusher.find_by_name(class_name).first
                            pusher.push(self, self.pusher_options[class_name.to_sym])
                        end
                    else
                        pusher = NotificationPusher::Pusher.find_by_name(self.pusher).first
                        pusher.push(self, self.pusher_options)
                    end
                end
            end

        end

    end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
notification-pusher-1.2.4 lib/notification_pusher/notification_library.rb
notification-pusher-1.2.3 lib/notification_pusher/notification_library.rb
notification-pusher-1.2.2 lib/notification_pusher/notification_library.rb
notification-pusher-1.2.1 lib/notification_pusher/notification_library.rb
notification-pusher-1.2.0 lib/notification_pusher/notification_library.rb
notification-pusher-1.1.2 lib/notification_pusher/notification_library.rb
notification-pusher-1.1.1 lib/notification_pusher/notification_library.rb
notification-pusher-1.1.0 lib/notification_pusher/notification_library.rb
notification-pusher-1.0.0 lib/notification_pusher/notification_library.rb