Class: Notification

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/notification.rb

Direct Known Subclasses

EmailNotification, UrlNotification

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_api(options = nil) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/models/notification.rb', line 7

def self.from_api(options = nil)
  return [] if options.blank?

  options.split(',').map do |value|
    value.strip!
    if value.include?('@')
      EmailNotification.new(value: value)
    else
      UrlNotification.new(value: value)
    end
  end
end

Instance Method Details

#initial_stateObject


35
36
37
# File 'app/models/notification.rb', line 35

def initial_state
  Job::Scheduled
end

#nameObject


31
32
33
# File 'app/models/notification.rb', line 31

def name
  self.class.to_s.gsub('Notification', '')
end

#notify!(*args) ⇒ Object


20
21
22
23
24
25
26
27
28
29
# File 'app/models/notification.rb', line 20

def notify!(*args)
  begin
    do_notify!(*args)
    update_attributes state: Job::Success
  rescue
    update_attributes state: Job::Failed
  end
  deliveries.create!(state: state, state_change: job.state_changes.last, notified_at: Time.current)
  self
end