Class: Salestation::App

Inherits:
Object
  • Object
show all
Defined in:
lib/salestation/app.rb,
lib/salestation/app/errors.rb,
lib/salestation/app/request.rb,
lib/salestation/app/input_verification.rb

Defined Under Namespace

Modules: Errors, InputVerification, Types Classes: Request

Instance Method Summary collapse

Constructor Details

#initialize(env:, hooks: {}) ⇒ App

Returns a new instance of App.



13
14
15
16
17
# File 'lib/salestation/app.rb', line 13

def initialize(env:, hooks: {})
  @environment = env
  @hook_listeners = {}
  @hooks = hooks
end

Instance Method Details

#create_request(input, span: nil) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/salestation/app.rb', line 27

def create_request(input, span: nil)
  Request.create(
    env: @environment,
    input: input,
    initialize_hook: method(:initialize_hook),
    span: span
  )
end

#register_listener(hook_type, listener) ⇒ Object



36
37
38
39
# File 'lib/salestation/app.rb', line 36

def register_listener(hook_type, listener)
  @hook_listeners[hook_type] ||= []
  @hook_listeners[hook_type].push(listener)
end

#startObject



19
20
21
22
23
24
25
# File 'lib/salestation/app.rb', line 19

def start
  @hooks.each do |hook_type, hook|
    hook.start_listening do |payload|
      @hook_listeners.fetch(hook_type, []).each { |handle| handle.call(payload) }
    end
  end
end