Class: Dingding::Notifier::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/dingding-notifier/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/dingding-notifier/config.rb', line 6

def initialize
  @http_client = Util::HTTPClient
  @middleware  = %i[
    format_text
    format_link
    format_markdown
    format_action_card
    format_feed_card
  ]
end

Instance Method Details

#http_client(client = nil) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
22
# File 'lib/dingding-notifier/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



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

def middleware *args
  args.delete_if{|a| a.nil?}
  return [:format_text] if args.empty? || args.nil?
  
  @middleware =
    if args.length == 1 && args.first.is_a?(Array) || args.first.is_a?(Hash)
      args.first
    else
      args
    end
end