Class: Rivendell::Import::Notifier::Base
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Rivendell::Import::Notifier::Base
- Defined in:
- lib/rivendell/import/notifier/base.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #delay ⇒ Object
- #logger ⇒ Object
- #notify ⇒ Object
- #parameters ⇒ Object
- #parameters=(parameters) ⇒ Object
- #parameters_hash ⇒ Object
- #raw_parameters ⇒ Object
- #read_parameters ⇒ Object
- #write_parameters ⇒ Object
Class Method Details
.notify(target, options = {}) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/rivendell/import/notifier/base.rb', line 78 def self.notify(target, = {}) new_notifier = case .delete(:by) when :email Mail.new .merge(:to => target) end key = new_notifier.parameters_hash if existing_notifier = where(:type => new_notifier.type, :key => key).first existing_notifier else new_notifier.save! new_notifier end end |
Instance Method Details
#delay ⇒ Object
25 26 27 |
# File 'lib/rivendell/import/notifier/base.rb', line 25 def delay tasks.pending.empty? ? 0 : 60 end |
#logger ⇒ Object
43 44 45 |
# File 'lib/rivendell/import/notifier/base.rb', line 43 def logger Rivendell::Import.logger end |
#notify ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rivendell/import/notifier/base.rb', line 29 def notify to_sent_notifications = notifications.to_sent.includes(:task) if delay > 0 to_sent_notifications = to_sent_notifications.waiting_for_more_than(delay) end if to_sent_notifications.present? logger.debug "Notify #{to_sent_notifications.size} tasks with #{self.inspect}" notify! to_sent_notifications.map(&:task) to_sent_notifications.update_all(:sent_at => Time.now) end end |
#parameters ⇒ Object
10 11 12 |
# File 'lib/rivendell/import/notifier/base.rb', line 10 def parameters {} end |
#parameters=(parameters) ⇒ Object
47 48 49 |
# File 'lib/rivendell/import/notifier/base.rb', line 47 def parameters=(parameters) parameters.each { |k,v| send "#{k}=", v } end |
#parameters_hash ⇒ Object
61 62 63 64 |
# File 'lib/rivendell/import/notifier/base.rb', line 61 def parameters_hash parameters_as_string = parameters.sort_by { |p| p.first.to_s }.flatten.join('-') Digest::SHA256.hexdigest parameters_as_string end |
#raw_parameters ⇒ Object
51 52 53 |
# File 'lib/rivendell/import/notifier/base.rb', line 51 def raw_parameters read_attribute :parameters end |
#read_parameters ⇒ Object
55 56 57 |
# File 'lib/rivendell/import/notifier/base.rb', line 55 def read_parameters self.parameters = ActiveSupport::JSON.decode(raw_parameters) if raw_parameters.present? end |
#write_parameters ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/rivendell/import/notifier/base.rb', line 66 def write_parameters if parameters.present? write_attribute :parameters, parameters.to_json write_attribute :key, parameters_hash else write_attribute :parameters, nil write_attribute :key, nil end end |