class NotifySet
{Notify} object container that includes disable/enable features.
Attributes
enable[RW]
Enable/disable {NotifySet}.
Public Class Methods
new( id = nil )
click to toggle source
Instantiation.
@param id [Symbol] Id of the set.
# File lib/notifyhub.rb, line 251 def initialize( id = nil ) @id = id @enable = true @list = [] end
Public Instance Methods
[]( idx )
click to toggle source
Get {Notify} by index.
# File lib/notifyhub.rb, line 321 def []( idx ) @list[ idx ] end
action( &action )
click to toggle source
Register {Notify}.
@param action [Block] {Notify} action.
# File lib/notifyhub.rb, line 269 def action( &action ) n = Notify.new( &action ) @list.push n n end
each() { |n| ... }
click to toggle source
Iterate over list of notifiers.
# File lib/notifyhub.rb, line 313 def each @list.each do |n| yield n end end
notify( *args )
click to toggle source
Run all notifiers in {NotifySet}.
@param args [Array<Object>] Arguments for notifiers. @return [Array<Object>] Array or single callback return value.
# 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 )
click to toggle source
Remove all or one Notify
.
@param notify [Notify] {Notify} to remove (all if not given).
# File lib/notifyhub.rb, line 282 def remove( notify = nil ) if notify @list.delete( notify ) else @list = [] end end