Class: NotifySet
- Inherits:
-
Object
- Object
- NotifySet
- Defined in:
- lib/notifyhub.rb
Overview
Notify object container that includes disable/enable features.
Instance Attribute Summary collapse
-
#enable(value) ⇒ Object
Enable/disable NotifySet.
Instance Method Summary collapse
-
#[](idx) ⇒ Object
Get Notify by index.
-
#action(&action) ⇒ Object
(also: #register, #with)
Register Notify.
-
#each ⇒ Object
Iterate over list of notifiers.
-
#initialize(id = nil) ⇒ NotifySet
constructor
Instantiation.
-
#notify(*args) ⇒ Array<Object>
Run all notifiers in NotifySet.
-
#remove(notify = nil) ⇒ Object
Remove all or one Notify.
Constructor Details
#initialize(id = nil) ⇒ NotifySet
Instantiation.
251 252 253 254 255 |
# File 'lib/notifyhub.rb', line 251 def initialize( id = nil ) @id = id @enable = true @list = [] end |
Instance Attribute Details
#enable(value) ⇒ Object
Enable/disable NotifySet.
245 246 247 |
# File 'lib/notifyhub.rb', line 245 def enable @enable end |
Instance Method Details
#[](idx) ⇒ Object
Get Notify by index.
321 322 323 |
# File 'lib/notifyhub.rb', line 321 def []( idx ) @list[ idx ] end |
#action(&action) ⇒ Object Also known as: register, with
Register Notify.
269 270 271 272 273 |
# File 'lib/notifyhub.rb', line 269 def action( &action ) n = Notify.new( &action ) @list.push n n end |
#each ⇒ Object
Iterate over list of notifiers.
313 314 315 316 317 |
# File 'lib/notifyhub.rb', line 313 def each @list.each do |n| yield n end end |
#notify(*args) ⇒ Array<Object>
Run all notifiers in NotifySet.
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/notifyhub.rb', line 294 def notify( *args ) ret = [] if @enable @list.each do |n| ret.push n.notify( *args ) end end if ret.length == 1 # Return single value. ret[0] else # Return array of results. ret end end |
#remove(notify = nil) ⇒ Object
Remove all or one Notify.
282 283 284 285 286 287 288 |
# File 'lib/notifyhub.rb', line 282 def remove( notify = nil ) if notify @list.delete( notify ) else @list = [] end end |