Class: SlackRubyBot::Server

Inherits:
Object
  • Object
show all
Includes:
Hooks::HookSupport, Loggable
Defined in:
lib/slack-ruby-bot/server.rb

Direct Known Subclasses

App

Constant Summary collapse

TRAPPED_SIGNALS =
%w[INT TERM].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Hooks::HookSupport

#add_hook_handlers, #flush_hook_blocks, #hooks, included, #on

Methods included from Loggable

included

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/slack-ruby-bot/server.rb', line 13

def initialize(options = {})
  @token = options[:token]
  @aliases = options[:aliases]
  @send_gifs = options[:send_gifs]

  # Hook Handling
  flush_hook_blocks

  add_hook_handlers options[:hook_handlers] || {
    hello: SlackRubyBot::Hooks::Hello.new(logger),
    message: SlackRubyBot::Hooks::Message.new
  }
end

Instance Attribute Details

#aliasesObject

Returns the value of attribute aliases.



7
8
9
# File 'lib/slack-ruby-bot/server.rb', line 7

def aliases
  @aliases
end

#send_gifsObject

Returns the value of attribute send_gifs.



7
8
9
# File 'lib/slack-ruby-bot/server.rb', line 7

def send_gifs
  @send_gifs
end

#tokenObject

Returns the value of attribute token.



7
8
9
# File 'lib/slack-ruby-bot/server.rb', line 7

def token
  @token
end

Instance Method Details

#runObject



27
28
29
30
31
32
33
34
# File 'lib/slack-ruby-bot/server.rb', line 27

def run
  loop do
    handle_exceptions do
      handle_signals
      start!
    end
  end
end

#start!Object



36
37
38
# File 'lib/slack-ruby-bot/server.rb', line 36

def start!
  client.start!
end

#start_asyncObject



40
41
42
# File 'lib/slack-ruby-bot/server.rb', line 40

def start_async
  client.start_async
end

#stop!Object



44
45
46
# File 'lib/slack-ruby-bot/server.rb', line 44

def stop!
  client.stop! if @client
end