Sha256: f0abc5c0b2b556c76f70998e6cc113d07a937c3665138f0f0351aa3d48813da9

Contents?: true

Size: 1.92 KB

Versions: 13

Compression:

Stored size: 1.92 KB

Contents

module Notifiable
  class App < ActiveRecord::Base
    has_many :device_tokens, :class_name => 'Notifiable::DeviceToken', :dependent => :destroy
    has_many :notifications, :class_name => 'Notifiable::Notification', :dependent => :destroy
    
    serialize :configuration
    
    validates :name, presence: true, allow_blank: false
    
    def configure(provider, notifier)
      return unless self.configuration && self.configuration[provider]

      self.configuration[provider].each_pair {|key, value| notifier.instance_variable_set("@#{key}", value) if notifier.class.notifier_attributes.include?(key) } 
    end
    
    def configuration
      unless read_attribute(:configuration)
        write_attribute(:configuration, default_configuration)
      end
      read_attribute(:configuration)
    end
    
    def default_configuration
      configuration = {}
      Notifiable.notifier_classes.each_pair do |provider,clazz|
        configuration[provider] = {}
        next unless clazz.notifier_attributes
        clazz.notifier_attributes.each do |notifier_attribute|
          configuration[provider][notifier_attribute] = nil
        end
      end
      configuration
    end
    
    def self.define_configuration_accessors(notifiers)
      notifiers.each_pair do |provider, clazz|
        next unless clazz.notifier_attributes
        
        clazz.notifier_attributes.each do |attribute|
          define_method("#{provider}_#{attribute}="){ |v| configuration[provider][attribute] = v }
          define_method("#{provider}_#{attribute}"){ configuration[provider][attribute] }
        end
      end
    end
    
    def save_notification_statuses
      self.configuration[:save_notification_statuses] == true || self.configuration[:save_notification_statuses].eql?("1")
    end
    
    def save_notification_statuses=(save_notification_statuses)
      self.configuration[:save_notification_statuses] = save_notification_statuses
    end
    
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
notifiable-rails-0.30.4 lib/notifiable/app.rb
notifiable-rails-0.30.3 lib/notifiable/app.rb
notifiable-rails-0.30.2 lib/notifiable/app.rb
notifiable-rails-0.30.1 lib/notifiable/app.rb
notifiable-rails-0.30.0 lib/notifiable/app.rb
notifiable-rails-0.29.0 lib/notifiable/app.rb
notifiable-rails-0.28.1 lib/notifiable/app.rb
notifiable-rails-0.28.0 lib/notifiable/app.rb
notifiable-rails-0.27.1 lib/notifiable/app.rb
notifiable-rails-0.27.0 lib/notifiable/app.rb
notifiable-rails-0.26.3 lib/notifiable/app.rb
notifiable-rails-0.26.1 lib/notifiable/app.rb
notifiable-rails-0.26.0 lib/notifiable/app.rb