Class: Slack::Messenger::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/slack-messenger/config.rb

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



6
7
8
9
10
11
12
13
14
15
# File 'lib/slack-messenger/config.rb', line 6

def initialize
  @http_client = Util::HTTPClient
  @defaults    = {}
  @middleware  = %i[
    format_message
    format_attachments
    at
    channels
  ]
end

Instance Method Details

#defaults(new_defaults = nil) ⇒ Object

Raises:

  • (ArgumentError)


24
25
26
27
28
29
# File 'lib/slack-messenger/config.rb', line 24

def defaults new_defaults=nil
  return @defaults if new_defaults.nil?
  raise ArgumentError, "the defaults must be a Hash" unless new_defaults.is_a?(Hash)

  @defaults = new_defaults
end

#http_client(client = nil) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
22
# File 'lib/slack-messenger/config.rb', line 17

def http_client client=nil
  return @http_client if client.nil?
  raise ArgumentError, "the http client must respond to ::post" unless client.respond_to?(:post)

  @http_client = client
end

#middleware(*args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/slack-messenger/config.rb', line 31

def middleware *args
  return @middleware if args.empty?

  @middleware =
    if args.length == 1 && args.first.is_a?(Array) || args.first.is_a?(Hash)
      args.first
    else
      args
    end
end