Class: Notifiable::App
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Notifiable::App
- Defined in:
- lib/notifiable/app.rb
Class Method Summary collapse
Instance Method Summary collapse
- #configuration ⇒ Object
- #configure(provider, notifier) ⇒ Object
- #default_configuration ⇒ Object
- #save_notification_statuses ⇒ Object
- #save_notification_statuses=(save_notification_statuses) ⇒ Object
Class Method Details
.define_configuration_accessors(notifiers) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/notifiable/app.rb', line 40 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] ||= {}; configuration[provider][attribute] = v } define_method("#{provider}_#{attribute}") { configuration[provider] ? configuration[provider][attribute] : nil } end end end |
Instance Method Details
#configuration ⇒ Object
21 22 23 24 25 26 |
# File 'lib/notifiable/app.rb', line 21 def configuration unless read_attribute(:configuration) write_attribute(:configuration, default_configuration) end read_attribute(:configuration) end |
#configure(provider, notifier) ⇒ Object
15 16 17 18 19 |
# File 'lib/notifiable/app.rb', line 15 def configure(provider, notifier) return unless configuration && configuration[provider] configuration[provider].each_pair { |key, value| notifier.instance_variable_set("@#{key}", value) if notifier.class.notifier_attributes.include?(key) } end |
#default_configuration ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/notifiable/app.rb', line 28 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 |
#save_notification_statuses ⇒ Object
51 52 53 |
# File 'lib/notifiable/app.rb', line 51 def save_notification_statuses configuration[:save_notification_statuses] == true || configuration[:save_notification_statuses].eql?('1') end |
#save_notification_statuses=(save_notification_statuses) ⇒ Object
55 56 57 |
# File 'lib/notifiable/app.rb', line 55 def save_notification_statuses=(save_notification_statuses) configuration[:save_notification_statuses] = save_notification_statuses end |