Class: AngryMob::NotificationInspector
- Defined in:
- lib/angry_mob/notifier.rb
Instance Attribute Summary collapse
-
#nickname ⇒ Object
readonly
Returns the value of attribute nickname.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #action?(*actions) ⇒ Boolean
-
#initialize(scheduler, nickname, options = {}, &block) ⇒ NotificationInspector
constructor
A new instance of NotificationInspector.
- #notifications ⇒ Object
- #select_and_run_action(actions, &block) ⇒ Object
- #yield_in_context(*args, &block) ⇒ Object
Constructor Details
#initialize(scheduler, nickname, options = {}, &block) ⇒ NotificationInspector
Returns a new instance of NotificationInspector.
4 5 6 7 8 9 10 |
# File 'lib/angry_mob/notifier.rb', line 4 def initialize(scheduler,nickname,={},&block) @scheduler,@nickname,@options = scheduler,nickname.to_s, unless notifications.empty? yield_in_context(self,&block) end end |
Instance Attribute Details
#nickname ⇒ Object (readonly)
Returns the value of attribute nickname.
3 4 5 |
# File 'lib/angry_mob/notifier.rb', line 3 def nickname @nickname end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/angry_mob/notifier.rb', line 3 def @options end |
Instance Method Details
#action?(*actions) ⇒ Boolean
24 25 26 |
# File 'lib/angry_mob/notifier.rb', line 24 def action?(*actions) actions.norm!.all? {|action| notifications.any? {|n| n.actions.include?(action.to_s)}} end |
#notifications ⇒ Object
20 21 22 |
# File 'lib/angry_mob/notifier.rb', line 20 def notifications @notifications ||= @scheduler.notifications.select {|n| n.target == nickname} end |
#select_and_run_action(actions, &block) ⇒ Object
28 29 30 31 32 |
# File 'lib/angry_mob/notifier.rb', line 28 def select_and_run_action(actions, &block) if matched = actions.find {|action| action?(action)} yield_in_context matched, &block end end |
#yield_in_context(*args, &block) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/angry_mob/notifier.rb', line 12 def yield_in_context(*args,&block) if o = [:context] o.instance_exec(*args,&block) else block.call(*args) end end |