Sha256: b1e4a9488acd923b2c1bea2c544e73b8cde65d8708b803335940c041d98390d5

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

module NotificationPusher
    module NotificationLibrary

        attr_accessor :push
        attr_accessor :push_options

        after_create_commit :initialize_pusher

        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 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

Version data entries

2 entries across 2 versions & 1 rubygems

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