Class: NotifySet
- Inherits:
-
Object
- Object
- NotifySet
- Defined in:
- lib/notifyhub.rb
Overview
Notify object that includes disable/enable features.
Instance Attribute Summary (collapse)
-
- (Object) enable(value)
Enable/disable Notify set.
Instance Method Summary (collapse)
-
- (Object) [](idx)
Get Notify by index.
-
- (Object) action(&action)
(also: #register, #with)
Register Notify.
-
- (Object) each
Iterate over list of notifiers.
-
- (NotifySet) initialize(id = nil)
constructor
Instantiation.
-
- (Array<Object>) notify(*args)
Run all notifiers in Notify set.
-
- (Object) remove(notify = nil)
Remove all or one Notify.
Constructor Details
- (NotifySet) initialize(id = nil)
Instantiation.
246 247 248 249 250 |
# File 'lib/notifyhub.rb', line 246 def initialize( id = nil ) @id = id @enable = true @list = [] end |
Instance Attribute Details
- (Object) enable(value)
Enable/disable Notify set.
240 241 242 |
# File 'lib/notifyhub.rb', line 240 def enable @enable end |
Instance Method Details
- (Object) [](idx)
Get Notify by index.
316 317 318 |
# File 'lib/notifyhub.rb', line 316 def []( idx ) @list[ idx ] end |
- (Object) action(&action) Also known as: register, with
Register Notify.
264 265 266 267 268 |
# File 'lib/notifyhub.rb', line 264 def action( &action ) n = Notify.new( &action ) @list.push n n end |
- (Object) each
Iterate over list of notifiers.
308 309 310 311 312 |
# File 'lib/notifyhub.rb', line 308 def each @list.each do |n| yield n end end |
- (Array<Object>) notify(*args)
Run all notifiers in Notify set.
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/notifyhub.rb', line 289 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 |
- (Object) remove(notify = nil)
Remove all or one Notify.
277 278 279 280 281 282 283 |
# File 'lib/notifyhub.rb', line 277 def remove( notify = nil ) if notify @list.delete( notify ) else @list = [] end end |