Class: Zookeeper::Callbacks::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/zookeeper/callbacks.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase


22
23
24
25
26
27
28
29
# File 'lib/zookeeper/callbacks.rb', line 22

def initialize
  @completed = false
  @proc = Proc.new do |hash|
    initialize_context(hash)
    yield if block_given?
    @completed = true
  end
end

Instance Attribute Details

#completedObject (readonly)

Returns the value of attribute completed


4
5
6
# File 'lib/zookeeper/callbacks.rb', line 4

def completed
  @completed
end

#contextObject (readonly)

Returns the value of attribute context


4
5
6
# File 'lib/zookeeper/callbacks.rb', line 4

def context
  @context
end

#procObject (readonly)

Returns the value of attribute proc


4
5
6
# File 'lib/zookeeper/callbacks.rb', line 4

def proc
  @proc
end

Class Method Details

.createObject

allows for easier construction of a user callback block that will be called with the callback object itself as an argument.

Examples:


Base.create do |cb|
  puts "watcher callback called with argument: #{cb.inspect}"
end

"watcher callback called with argument: #<Zookeeper::Callbacks::Base:0x1018a3958 @state=3, @type=1, ...>"

18
19
20
# File 'lib/zookeeper/callbacks.rb', line 18

def self.create
  cb_inst = new { yield cb_inst }
end

Instance Method Details

#call(*args) ⇒ Object


31
32
33
# File 'lib/zookeeper/callbacks.rb', line 31

def call(*args)
  @proc.call(*args)
end

#completed?Boolean


35
36
37
# File 'lib/zookeeper/callbacks.rb', line 35

def completed?
  @completed
end

#initialize_context(hash) ⇒ Object


39
40
41
# File 'lib/zookeeper/callbacks.rb', line 39

def initialize_context(hash)
  @context = nil
end