Class: Noticed::Base

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Callbacks
Includes:
Translation
Defined in:
lib/noticed/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Translation

#i18n_scope, #scope_translation_key, #translate

Constructor Details

#initialize(params = {}) ⇒ Base

Returns a new instance of Base.



40
41
42
# File 'lib/noticed/base.rb', line 40

def initialize(params = {})
  @params = params
end

Instance Attribute Details

#recipientObject

Gives notifications access to the record and recipient when formatting for delivery



13
14
15
# File 'lib/noticed/base.rb', line 13

def recipient
  @recipient
end

#recordObject

Gives notifications access to the record and recipient when formatting for delivery



13
14
15
# File 'lib/noticed/base.rb', line 13

def record
  @record
end

Class Method Details

.deliver_by(name, options = {}) ⇒ Object



18
19
20
21
# File 'lib/noticed/base.rb', line 18

def deliver_by(name, options = {})
  delivery_methods.push(name: name, options: options)
  define_model_callbacks(name)
end

.inherited(base) ⇒ Object

Copy delivery methods from parent



24
25
26
27
28
# File 'lib/noticed/base.rb', line 24

def inherited(base) #:nodoc:
  base.delivery_methods = delivery_methods.dup
  base.param_names = param_names.dup
  super
end

.paramObject



37
38
39
# File 'lib/noticed/base.rb', line 37

def params(*names)
  param_names.concat Array.wrap(names)
end

.params(*names) ⇒ Object



34
35
36
# File 'lib/noticed/base.rb', line 34

def params(*names)
  param_names.concat Array.wrap(names)
end

.with(params) ⇒ Object



30
31
32
# File 'lib/noticed/base.rb', line 30

def with(params)
  new(params)
end

Instance Method Details

#deliver(recipients) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/noticed/base.rb', line 44

def deliver(recipients)
  validate!

  run_callbacks :deliver do
    Array.wrap(recipients).uniq.each do |recipient|
      run_delivery(recipient, enqueue: false)
    end
  end
end

#deliver_later(recipients) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/noticed/base.rb', line 54

def deliver_later(recipients)
  validate!

  run_callbacks :deliver do
    Array.wrap(recipients).uniq.each do |recipient|
      run_delivery(recipient, enqueue: true)
    end
  end
end

#paramsObject



64
65
66
# File 'lib/noticed/base.rb', line 64

def params
  @params || {}
end