Method: ZK::EventHandler#register

Defined in:
lib/zk/event_handler.rb

#register(path, opts = {}, &block) ⇒ Object Also known as: subscribe



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/zk/event_handler.rb', line 68

def register(path, opts={}, &block)
  path = ALL_NODE_EVENTS_KEY if path == :all

  hash = {:thread => @thread_opt}

  # gah, ok, handle the 1.0 form
  case opts
  when Array, Symbol
    warn "Deprecated! #{self.class}#register use the :only option instead of passing a symbol or array"
    hash[:only] = opts
  when Hash
    hash.merge!(opts)
  when nil
    # no-op
  else
    raise ArgumentError, "don't know how to handle options: #{opts.inspect}" 
  end

  EventHandlerSubscription.new(self, path, block, hash).tap do |subscription|
    synchronize do
      (@callbacks[path] ||= []) << subscription
    end
  end
end