Class: EventMachine::Ssh::Callbacks::Callback
- Inherits:
-
Object
- Object
- EventMachine::Ssh::Callbacks::Callback
- Defined in:
- lib/em-ssh/callbacks.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
The block to call when the event is fired.
-
#event ⇒ Object
readonly
- Sybmol
-
the name of the event.
-
#obj ⇒ Object
readonly
The object that keeps this callback.
Instance Method Summary collapse
-
#call(*args) ⇒ Object
Call the callback with optional arguments.
-
#cancel ⇒ Object
register.
-
#initialize(obj, event, &blk) ⇒ Callback
constructor
A new instance of Callback.
-
#register ⇒ Object
Registers the callback with the object.
Constructor Details
#initialize(obj, event, &blk) ⇒ Callback
Returns a new instance of Callback.
76 77 78 79 80 81 |
# File 'lib/em-ssh/callbacks.rb', line 76 def initialize(obj, event, &blk) raise ArgumentError.new("a block is required") unless block_given? @obj = obj @event = event @block = blk end |
Instance Attribute Details
#block ⇒ Object (readonly)
The block to call when the event is fired
74 75 76 |
# File 'lib/em-ssh/callbacks.rb', line 74 def block @block end |
#event ⇒ Object (readonly)
- Sybmol
-
the name of the event
72 73 74 |
# File 'lib/em-ssh/callbacks.rb', line 72 def event @event end |
#obj ⇒ Object (readonly)
The object that keeps this callback
70 71 72 |
# File 'lib/em-ssh/callbacks.rb', line 70 def obj @obj end |
Instance Method Details
#call(*args) ⇒ Object
Call the callback with optional arguments
84 85 86 |
# File 'lib/em-ssh/callbacks.rb', line 84 def call(*args) block.call(*args) end |
#cancel ⇒ Object
register
94 95 96 97 98 99 |
# File 'lib/em-ssh/callbacks.rb', line 94 def cancel raise "#{@obj} does not have any callbacks for #{@event.inspect}" unless @obj.respond_to?(:callbacks) && @obj.callbacks.respond_to?(:[]) && @obj.callbacks[@event].respond_to?(:delete) @obj.callbacks[@event].delete(self) @obj = nil self end |
#register ⇒ Object
Registers the callback with the object. This is useful if you cancel the callback at one point and want to re-enable it later on.
90 91 92 |
# File 'lib/em-ssh/callbacks.rb', line 90 def register @obj.on(self) end |