Class: SlackRubyBot::Hooks::Hello

Inherits:
Object
  • Object
show all
Defined in:
lib/slack-ruby-bot/hooks/hello.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ Hello

Returns a new instance of Hello.



8
9
10
# File 'lib/slack-ruby-bot/hooks/hello.rb', line 8

def initialize(logger)
  self.logger = logger
end

Instance Attribute Details

#connected_atObject

Returns the value of attribute connected_at.



6
7
8
# File 'lib/slack-ruby-bot/hooks/hello.rb', line 6

def connected_at
  @connected_at
end

#loggerObject

Returns the value of attribute logger.



6
7
8
# File 'lib/slack-ruby-bot/hooks/hello.rb', line 6

def logger
  @logger
end

Instance Method Details

#call(client, _data) ⇒ Object



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

def call(client, _data)
  return unless client&.team

  new_connected_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  log = [
    'Successfully',
    connected_at ? 'reconnected' : 'connected',
    "team #{client.team.name} (#{client.team.id}) to https://#{client.team.domain}.slack.com",
    connected_at ? "after #{last_connection_till(new_connected_at)}s" : nil
  ].compact.join(' ') + '.'

  logger.info log

  self.connected_at = new_connected_at
end