Sha256: ffae8d8bcacd0a95ee1615db77a44679034c4a72d38979bf2e17ef912bcbd2a3

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true
module Slack
  module RealTime
    module Config
      class NoConcurrencyError < StandardError; end
      class InvalidAsyncHandlersError < StandardError; end

      extend self

      ATTRIBUTES = %i[
        token
        websocket_ping
        websocket_proxy
        concurrency
        start_options
        store_class
        store_options
        logger
        async_handlers
      ].freeze

      attr_accessor(*Config::ATTRIBUTES - [:concurrency])
      attr_writer :concurrency

      def reset
        self.websocket_ping = 30
        self.websocket_proxy = nil
        self.token = nil
        self.concurrency = method(:detect_concurrency)
        self.start_options = { request: { timeout: 180 } }
        self.store_class = Slack::RealTime::Stores::Starter
        self.store_options = {}
        self.logger = nil
        self.async_handlers = :none
      end

      def concurrency
        (val = @concurrency).respond_to?(:call) ? val.call : val
      end

      private

      def detect_concurrency
        Slack::RealTime::Concurrency.const_get(:Async)
      rescue LoadError, NameError
        raise NoConcurrencyError, 'Missing concurrency. Add async-websocket to your Gemfile.'
      end
    end

    class << self
      def configure
        block_given? ? yield(Config) : Config
      end

      def config
        Config
      end
    end
  end
end

Slack::RealTime::Config.reset

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
slack-ruby-client-2.4.0 lib/slack/real_time/config.rb
slack-ruby-client-2.3.0 lib/slack/real_time/config.rb
slack-ruby-client-2.2.0 lib/slack/real_time/config.rb