Sha256: b39b17b3f54afeaefd2b984f8580570b78edd89105c1fdda669f9da3eb0f6b91
Contents?: true
Size: 1.78 KB
Versions: 4
Compression:
Stored size: 1.78 KB
Contents
module ZK module EventHandlerSubscription class Base < Subscription::Base include ZK::Logging # the path this subscription is for # @return [String] attr_accessor :path # the block associated with the path # @return [Proc] # attr_accessor :callback # an array of what kinds of events this handler is interested in receiving # this is the :only option, essentially # # @return [Set] containing any combination of :create, :change, :delete, # or :children # # @private attr_accessor :interests alias event_handler parent alias callback callable ALL_EVENTS = [:created, :deleted, :changed, :child].freeze unless defined?(ALL_EVENTS) ALL_EVENT_SET = Set.new(ALL_EVENTS).freeze unless defined?(ALL_EVENT_SET) # @private def initialize(event_handler, path, callback, opts={}) super(event_handler, callback) @path = path @interests = prep_interests(opts[:only]) end # the Actor returns true for this # @private def async? false end protected def prep_interests(a) # logger.debug { "prep_interests: #{a.inspect}" } return ALL_EVENT_SET if a.nil? rval = case a when Array Set.new(a) when Symbol Set.new([a]) else raise ArgumentError, "Don't know how to handle interests: #{a.inspect}" end rval.tap do |rv| invalid = (rv - ALL_EVENT_SET) raise ArgumentError, "Invalid event name(s) #{invalid.to_a.inspect} given" unless invalid.empty? end end end # Base end # EventHandlerSubscription end # ZK
Version data entries
4 entries across 4 versions & 1 rubygems