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
TODO Add support for multiple targets.
-
#initialize(args = {}) ⇒ Notification
constructor
A new instance of Notification.
-
#notify(*args, &block) ⇒ Object
TODO Collection of targets is not supported.
-
#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
TODO fix this.
- #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
TODO Add support for multiple targets
53 54 55 56 57 |
# File 'lib/dallal/notification.rb', line 53 def dispatch! validate! @notifiers.each { |_, n| n.notify! } @notifiers.each { |_, n| n.persist! } if persist? end |
#notify(*args, &block) ⇒ Object
TODO Collection of targets is not supported
15 16 17 18 19 20 21 |
# File 'lib/dallal/notification.rb', line 15 def notify *args, &block notify_opts = args. return unless should_send?(notify_opts[:if]) @target = Array(args).flatten.compact.uniq instance_eval(&block) end |
#payload(payload) ⇒ Object
TODO !!! Watch out same payload for multiple notifers that require payload
39 40 41 |
# File 'lib/dallal/notification.rb', line 39 def payload payload @payload = payload end |
#persist? ⇒ Boolean
48 49 50 |
# File 'lib/dallal/notification.rb', line 48 def persist? opts[:persist].present? end |
#template(template) ⇒ Object
Same here as payload
44 45 46 |
# File 'lib/dallal/notification.rb', line 44 def template template @template_name = template end |
#user ⇒ Object
TODO fix this. This is a quick and dirty patch for email
33 34 35 |
# File 'lib/dallal/notification.rb', line 33 def user @target.first end |
#with(*args, &block) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/dallal/notification.rb', line 23 def with *args, &block opts = args. # TODO Move if condition to notify method if should_send?(opts[:if]) instance_eval(&block) args.each { |arg| @notifiers[arg] = get_notifier(arg) } end end |