Sha256: 2951727bc2500cec4dd9a56be0c6b0582441c9ac3f7156bd42fdb31fad9620a9

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

module Slack

  module Configurable

    attr_accessor :token, :team, :api_endpoint, :default_media_type,
                  :user_agent, :default_channel, :default_username,
                  :connection_options, :middleware
    attr_writer :api_endpoint

    class << self

      # List of configurable keys for {Octokit::Client}
      # @return [Array] of option keys
      def keys
        @keys ||= [
          :token,
          :team,
          :api_endpoint,
          :user_agent,
          :connection_options,
          :default_media_type,
          :default_channel,
          :default_username,
          :middleware
        ]
      end
    end

    # Set configuration options using a block
    def configure
      yield self
    end

    # Reset configuration options to default values
    def reset!
      Slack::Configurable.keys.each do |key|
        instance_variable_set(:"@#{key}", Slack::Default.options[key])
      end
      self
    end
    alias setup reset!

    private

    def options
      Hash[Slack::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
slack.rb-0.0.5 lib/slack/configurable.rb