Class: Noticed::Base

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

Direct Known Subclasses

DeliveryMethods::Fcm, DeliveryMethods::Ios

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Translation

#class_scope, #i18n_scope, #scope_translation_key, #translate

Constructor Details

#initialize(params = {}) ⇒ Base

Returns a new instance of Base.



50
51
52
# File 'lib/noticed/base.rb', line 50

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

Instance Attribute Details

#recipientObject

Gives notifications access to the record and recipient during delivery



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

def recipient
  @recipient
end

#recordObject

Gives notifications access to the record and recipient during delivery



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

def record
  @record
end

Class Method Details

.deliver(recipients) ⇒ Object

Shortcut for delivering without params



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

def deliver(recipients)
  new.deliver(recipients)
end

.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

.deliver_later(recipients) ⇒ Object

Shortcut for delivering later without params



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

def deliver_later(recipients)
  new.deliver_later(recipients)
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



47
48
49
# File 'lib/noticed/base.rb', line 47

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

.params(*names) ⇒ Object



44
45
46
# File 'lib/noticed/base.rb', line 44

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

#clear_recipientObject



78
79
80
# File 'lib/noticed/base.rb', line 78

def clear_recipient
  self.recipient = nil
end

#deliver(recipients) ⇒ Object



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

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



64
65
66
67
68
69
70
71
72
# File 'lib/noticed/base.rb', line 64

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



74
75
76
# File 'lib/noticed/base.rb', line 74

def params
  @params || {}
end