Sha256: 694ed37319d628f3d8769282f6f6ffeb6c22d62600d8f1a3d12aef400a6c3280

Contents?: true

Size: 1.49 KB

Versions: 4

Compression:

Stored size: 1.49 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)

      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
        %i[Async Eventmachine Celluloid].each do |concurrency|
          begin
            return Slack::RealTime::Concurrency.const_get(concurrency)
          rescue LoadError, NameError
            false # could not be loaded, missing dependencies
          end
        end

        raise(
          NoConcurrencyError,
          'Missing concurrency. Add async-websocket, faye-websocket ' \
          'or celluloid-io 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

4 entries across 4 versions & 1 rubygems

Version Path
slack-ruby-client-0.15.1 lib/slack/real_time/config.rb
slack-ruby-client-0.15.0 lib/slack/real_time/config.rb
slack-ruby-client-0.14.6 lib/slack/real_time/config.rb
slack-ruby-client-0.14.5 lib/slack/real_time/config.rb