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.



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

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



16
17
18
19
# File 'lib/noticed/base.rb', line 16

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



22
23
24
25
26
# File 'lib/noticed/base.rb', line 22

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

.param(name) ⇒ Object



32
33
34
# File 'lib/noticed/base.rb', line 32

def param(name)
  param_names.push(name)
end

.with(params) ⇒ Object



28
29
30
# File 'lib/noticed/base.rb', line 28

def with(params)
  new(params)
end

Instance Method Details

#deliver(recipients) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/noticed/base.rb', line 41

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



51
52
53
54
55
56
57
58
59
# File 'lib/noticed/base.rb', line 51

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



61
62
63
# File 'lib/noticed/base.rb', line 61

def params
  @params || {}
end