Class: Miteru::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/miteru/notifier.rb

Instance Method Summary collapse

Instance Method Details

#notify(url:, kits:, message:) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/miteru/notifier.rb', line 8

def notify(url:, kits:, message:)
  attachement = Attachement.new(url)
  kits = kits.select(&:filesize)

  if post_to_slack? && kits.any?
    notifier = Slack::Notifier.new(slack_webhook_url, channel: slack_channel)
    notifier.post(text: message, attachments: attachement.to_a)
  end

  message = message.colorize(:light_red) if kits.any?
  puts "#{url}: #{message}"
end

#post_to_slack?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/miteru/notifier.rb', line 21

def post_to_slack?
  slack_webhook_url? && Miteru.configuration.post_to_slack?
end

#slack_channelObject



29
30
31
# File 'lib/miteru/notifier.rb', line 29

def slack_channel
  ENV.fetch "SLACK_CHANNEL", "#general"
end

#slack_webhook_urlObject



25
26
27
# File 'lib/miteru/notifier.rb', line 25

def slack_webhook_url
  ENV.fetch "SLACK_WEBHOOK_URL"
end

#slack_webhook_url?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/miteru/notifier.rb', line 33

def slack_webhook_url?
  ENV.key? "SLACK_WEBHOOK_URL"
end