Sha256: 6ef95b829d31b8218fd55db877adda6904a0dea3a898e2252873b21b9e7fb91e

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

module Slack

  module Configurable

    attr_accessor :token, :team, :username, :icon_url, :api_endpoint, :default_media_type,
                  :user_agent, :default_channel, :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,
          :username,
          :icon_url,
          :api_endpoint,
          :user_agent,
          :connection_options,
          :default_media_type,
          :default_channel,
          :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.6 lib/slack/configurable.rb