Class: SlackBot::Events::Configuration

Inherits:
Object
  • Object
show all
Includes:
ClassComposer::Generator
Defined in:
lib/slack_bot/events/configuration.rb

Constant Summary collapse

ALLOWED_ACKNOWLEDGE =
[
  DEFAULT_ACKNOWLEDGE = :on_complete,
  :on_success,
  :on_receive,
]

Instance Method Summary collapse

Instance Method Details

#listenersObject



54
55
56
# File 'lib/slack_bot/events/configuration.rb', line 54

def listeners
  @listeners ||= {}
end

#loggerObject



46
47
48
# File 'lib/slack_bot/events/configuration.rb', line 46

def logger
  @logger ||= Logger.new(STDOUT)
end

#logger=(log) ⇒ Object



50
51
52
# File 'lib/slack_bot/events/configuration.rb', line 50

def logger=(log)
  @logger = log
end

#register_listener(name:, handler:, on_success: nil, on_failure: nil) ⇒ Object



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

def register_listener(name:, handler:, on_success: nil, on_failure: nil)
  if event_handler = listeners[name.to_sym]
    logger.warn "`#{name}` already exists as listener event. Reseting with new input"
  end

  validate_listener!(handler: handler, on_success: on_success, on_failure: on_failure)

  listeners[name.to_sym] = { handler: handler, name: name, on_success: on_success, on_failure: on_failure }
  true
end

#remove_listener(name:) ⇒ Object



42
43
44
# File 'lib/slack_bot/events/configuration.rb', line 42

def remove_listener(name:)
  listeners ||= {}
end