Sha256: 266079e9e73e5cf9c90ff665aa81dbb747eb02c69e516d14d4a4fe69244e5d66

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

module NotificationPusher
    module NotificationLibrary

        extend ActiveSupport::Concern

        included do
            attr_accessor :push
            attr_accessor :push_options

            after_create_commit :initialize_pusher

            include NotificationPusher::NotificationLibrary::InstanceMethods
        end

        module InstanceMethods

            def push name, options = {}
                self.push = class_name
                self.push_options = options
                self.initialize_pusher
            end

            private

            def initialize_pusher
                unless self.push.nil?
                    if self.push.kind_of(Array)
                        self.push.each do |class_name|
                            pusher = NotificationPusher::Pusher.find_by_name(class_name).last
                            if defined?(NotificationPusher.const_get(pusher.name))
                                options = pusher.options.merge! self.push_options[class_name.to_sym]
                                pusher.instances << NotificationPusher.const_get(pusher.name).new self, options
                            end
                        end
                    else
                        pusher = NotificationPusher::Pusher.find_by_name(self.push).last
                        if defined?(NotificationPusher.const_get(pusher.name))
                            options = pusher.options.merge! self.push_options
                            pusher.instances << NotificationPusher.const_get(pusher.name).new self, options
                        end
                    end
                end
            end

        end

    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
notification-pusher-1.0.0.beta9 lib/notification_pusher/notification_library.rb