Module: CatchBox::Fanout

Defined in:
lib/catch_box/fanout.rb

Defined Under Namespace

Modules: Initialize

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(descendant) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/catch_box/fanout.rb', line 36

def self.extended(descendant)
  descendant.class_eval do
    extend ::Dry::Configurable

    setting :event, ::CatchBox::Event.new
    setting :auth, ::CatchBox::Auth.new

    setting :on, ::CatchBox::On.new
    setting :emitter, ::CatchBox::Emitter.new

    @_fanout = []
  end
end

.included(descendant) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/catch_box/fanout.rb', line 19

def self.included(descendant)
  descendant.class_eval do
    extend ::Dry::Configurable
    prepend ::CatchBox::Fanout::Initialize

    setting :event, ::CatchBox::Event.new
    setting :auth, ::CatchBox::Auth.new

    setting :on, ::CatchBox::On.new
    setting :emitter, ::CatchBox::Emitter.new

    def config
      self.class.config
    end
  end
end

Instance Method Details

#all(callable = nil, &block) ⇒ Object



64
65
66
67
68
# File 'lib/catch_box/fanout.rb', line 64

def all(callable = nil, &block)
  config.on.call(
    _fanout, nil, callable || block
  )
end

#auth(callable = nil, &block) ⇒ Object



54
55
56
# File 'lib/catch_box/fanout.rb', line 54

def auth(callable = nil, &block)
  config.auth.call(callable || block)
end

#emit(payload, env) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/catch_box/fanout.rb', line 70

def emit(payload, env)
  config.auth.map(payload, env)

  pattern = config.event.map(payload)

  config.emitter.call(
    _fanout, pattern, payload
  )
end

#event(callable = nil, &block) ⇒ Object



50
51
52
# File 'lib/catch_box/fanout.rb', line 50

def event(callable = nil, &block)
  config.event.call(callable || block)
end

#on(pattern, callable = nil, &block) ⇒ Object



58
59
60
61
62
# File 'lib/catch_box/fanout.rb', line 58

def on(pattern, callable = nil, &block)
  config.on.call(
    _fanout, pattern, callable || block
  )
end