Sha256: db1d324c99dbc792c1ef5c10446c35b62c0d1b6cd9a5845ef1c5edc934e65dad

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

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

      extend self

      ATTRIBUTES = %i[
        token
        websocket_ping
        websocket_proxy
        concurrency
        start_options
        store_class
        store_options
        logger
      ].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
      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

2 entries across 2 versions & 1 rubygems

Version Path
slack-ruby-client-2.1.0 lib/slack/real_time/config.rb
slack-ruby-client-2.0.0 lib/slack/real_time/config.rb