module ObServ

Constants

VERSION

Attributes

notifies[RW]

Public Instance Methods

config() click to toggle source
# File lib/ob_serv.rb, line 19
def config
  @config ||= {
    publish: ObServ.method(:publish)
  }
end
publish(event, *args) click to toggle source
# File lib/ob_serv.rb, line 32
def publish(event, *args)
  @notifies[event]&.each do |_, (obj, opts, blk)|
    next blk.call(*args) if blk
    m = opts[:on]
    if obj.respond_to?(m) && obj.respond_to?(:name) && obj.to_s == obj.name
      next obj.send m, *args if obj.respond_to? m
    end
    obj.send m, *args if obj.respond_to? m
  end
end
register(obj, event, options = {}) click to toggle source
# File lib/ob_serv.rb, line 25
def register(obj, event, options = {})
  @notifies ||= {}
  block = block_given? ? Proc.new : nil
  @notifies[event] ||= {}
  @notifies[event][obj.__id__] = [obj, options, block]
end