Class: Slack::Notifier::Config

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

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



5
6
7
8
9
# File 'lib/slack-notifier/config.rb', line 5

def initialize
  @http_client = Util::HTTPClient
  @defaults    = {}
  @middleware  = [:format_message, :format_attachments]
end

Instance Method Details

#defaults(new_defaults = nil) ⇒ Object

Raises:

  • (ArgumentError)


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

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)


11
12
13
14
15
16
# File 'lib/slack-notifier/config.rb', line 11

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



25
26
27
28
29
30
31
32
33
34
# File 'lib/slack-notifier/config.rb', line 25

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