Sha256: a4951d144388e78b72c7c0d2abe8b96ef53cf29f6b1a04055b5aca60daf88479

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 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_method
        start_options
        store_class
        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_method = nil
        self.start_options = { request: { timeout: 180 } }
        self.store_class = Slack::RealTime::Store
        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

3 entries across 3 versions & 1 rubygems

Version Path
slack-ruby-client-1.1.0 lib/slack/real_time/config.rb
slack-ruby-client-1.0.0 lib/slack/real_time/config.rb
slack-ruby-client-0.17.0 lib/slack/real_time/config.rb