Module: ObServ

Defined in:
lib/ob_serv.rb,
lib/ob_serv/version.rb

Defined Under Namespace

Modules: DSL

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.configObject



18
19
20
21
22
# File 'lib/ob_serv.rb', line 18

def config
  @config ||= {
    publish: ObServ.method(:publish)
  }
end

.publish(event, *args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/ob_serv.rb', line 31

def publish(event, *args)
  @notifies[event]&.each do |_, (obj, m, blk)|
    next blk.call(*args) if blk
    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
    obj.send event, *args if obj.respond_to? event
  end
end

.register(obj, event, on: :receive) ⇒ Object



24
25
26
27
28
29
# File 'lib/ob_serv.rb', line 24

def register(obj, event, on: :receive)
  @notifies ||= {}
  block = block_given? ? Proc.new : nil
  @notifies[event] ||= {}
  @notifies[event][obj.__id__] = [obj, on, block]
end