Class: CorosyncCommander::CallbackList
- Inherits:
-
Object
- Object
- CorosyncCommander::CallbackList
- Includes:
- Enumerable
- Defined in:
- lib/corosync_commander/callback_list.rb
Instance Method Summary collapse
-
#[](command) ⇒ Proc
Retrieve a registered command callback.
-
#[]=(command, block) ⇒ Proc
Assign a callback.
-
#delete(command) ⇒ Proc
Delete a command callback.
-
#each {|command, callback| ... } ⇒ Object
Iterate through each command/callback.
-
#initialize ⇒ CallbackList
constructor
A new instance of CallbackList.
-
#register(command, &block) ⇒ Proc
Assign a callback This is another method of assigning a callback.
Constructor Details
#initialize ⇒ CallbackList
4 5 6 7 |
# File 'lib/corosync_commander/callback_list.rb', line 4 def initialize @callbacks = {} @callbacks.extend(Sync_m) end |
Instance Method Details
#[](command) ⇒ Proc
Retrieve a registered command callback
51 52 53 54 55 |
# File 'lib/corosync_commander/callback_list.rb', line 51 def [](command) @callbacks.synchronize(:SH) do @callbacks[command] end end |
#[]=(command, block) ⇒ Proc
Assign a callback
28 29 30 31 32 33 |
# File 'lib/corosync_commander/callback_list.rb', line 28 def []=(command, block) @callbacks.synchronize(:EX) do @callbacks[command] = block end block end |
#delete(command) ⇒ Proc
Delete a command callback
60 61 62 63 64 |
# File 'lib/corosync_commander/callback_list.rb', line 60 def delete(command) @callbacks.synchronize(:EX) do @callbacks.delete(command) end end |
#each {|command, callback| ... } ⇒ Object
Iterate through each command/callback
12 13 14 15 16 17 18 |
# File 'lib/corosync_commander/callback_list.rb', line 12 def each(&block) callbacks = nil @callbacks.synchronize(:SH) do callbacks = @callbacks.dup end callbacks.each(&block) end |
#register(command, &block) ⇒ Proc
Assign a callback This is another method of assigning a callback
44 45 46 |
# File 'lib/corosync_commander/callback_list.rb', line 44 def register(command, &block) self[command] = block end |