Class: Dallal::Notification
- Inherits:
-
Object
- Object
- Dallal::Notification
- Defined in:
- lib/dallal/notification.rb
Instance Attribute Summary collapse
-
#_object ⇒ Object
Returns the value of attribute _object.
-
#event ⇒ Object
Returns the value of attribute event.
-
#model_class ⇒ Object
Returns the value of attribute model_class.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#template_name ⇒ Object
readonly
Returns the value of attribute template_name.
Instance Method Summary collapse
- #dispatch! ⇒ Object
-
#initialize(args = {}) ⇒ Notification
constructor
A new instance of Notification.
- #notify(target, &block) ⇒ Object
-
#payload(payload) ⇒ Object
TODO !!! Watch out same payload for multiple notifers that require payload.
- #persist? ⇒ Boolean
-
#template(template) ⇒ Object
Same here as payload.
- #user ⇒ Object
- #with(*args, &block) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Notification
Returns a new instance of Notification.
6 7 8 9 10 11 12 |
# File 'lib/dallal/notification.rb', line 6 def initialize args = {} args.each do |k, v| send("#{k}=", v) end @notifiers = {} end |
Instance Attribute Details
#_object ⇒ Object
Returns the value of attribute _object.
3 4 5 |
# File 'lib/dallal/notification.rb', line 3 def _object @_object end |
#event ⇒ Object
Returns the value of attribute event.
3 4 5 |
# File 'lib/dallal/notification.rb', line 3 def event @event end |
#model_class ⇒ Object
Returns the value of attribute model_class.
3 4 5 |
# File 'lib/dallal/notification.rb', line 3 def model_class @model_class end |
#opts ⇒ Object
Returns the value of attribute opts.
3 4 5 |
# File 'lib/dallal/notification.rb', line 3 def opts @opts end |
#template_name ⇒ Object (readonly)
Returns the value of attribute template_name.
4 5 6 |
# File 'lib/dallal/notification.rb', line 4 def template_name @template_name end |
Instance Method Details
#dispatch! ⇒ Object
46 47 48 49 50 |
# File 'lib/dallal/notification.rb', line 46 def dispatch! validate! @notifiers.each { |_, n| n.notify! } @notifiers.each { |_, n| n.persist! } if persist? end |
#notify(target, &block) ⇒ Object
14 15 16 17 |
# File 'lib/dallal/notification.rb', line 14 def notify target, &block @target = Array(target).flatten.compact.uniq instance_eval(&block) end |
#payload(payload) ⇒ Object
TODO !!! Watch out same payload for multiple notifers that require payload
33 34 35 |
# File 'lib/dallal/notification.rb', line 33 def payload payload @payload = payload end |
#persist? ⇒ Boolean
42 43 44 |
# File 'lib/dallal/notification.rb', line 42 def persist? opts[:persist].present? end |
#template(template) ⇒ Object
Same here as payload
38 39 40 |
# File 'lib/dallal/notification.rb', line 38 def template template @template_name = template end |
#user ⇒ Object
27 28 29 |
# File 'lib/dallal/notification.rb', line 27 def user @target.first end |
#with(*args, &block) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/dallal/notification.rb', line 19 def with *args, &block opts = args. if should_send?(opts[:if]) instance_eval(&block) args.each { |arg| @notifiers[arg] = get_notifier(arg) } end end |