Module: OBSWS::Events::Director

Included in:
Client
Defined in:
lib/obsws/event.rb

Instance Method Summary collapse

Instance Method Details

#deregister(cbs) ⇒ Object



47
48
49
50
# File 'lib/obsws/event.rb', line 47

def deregister(cbs)
  cbs = Array(cbs) unless cbs.respond_to? :each
  cbs.each { |cb| observers[cb.name[3..].to_sym]&.reject! { |o| cbs.include? o } }
end

#fire(event, data) ⇒ Object



52
53
54
# File 'lib/obsws/event.rb', line 52

def fire(event, data)
  observers[event.snakecase.to_sym]&.each { |block| data.empty? ? block.call : block.call(data) }
end

#observersObject



34
35
36
# File 'lib/obsws/event.rb', line 34

def observers
  @observers ||= {}
end

#on(event, method = nil, &block) ⇒ Object



38
39
40
# File 'lib/obsws/event.rb', line 38

def on(event, method = nil, &block)
  (observers[event] ||= []) << (block || method)
end

#register(cbs) ⇒ Object



42
43
44
45
# File 'lib/obsws/event.rb', line 42

def register(cbs)
  cbs = Array(cbs) unless cbs.respond_to? :each
  cbs.each { |cb| on(cb.name[3..].to_sym, cb) }
end