class SlackReporter

Constants

DEFAULTS
VERSION

Attributes

channel[RW]
name[RW]

Public Class Methods

defaults(opts={}) click to toggle source
# File lib/slack-reporter.rb, line 13
def self.defaults(opts={})
  DEFAULTS.merge!(Hash[opts])
end
new(item = nil, options={ channel: nil }) click to toggle source
# File lib/slack-reporter.rb, line 17
def initialize(item = nil, options={ channel: nil })
  @name = create_name(item)
  @channel  = options[:channel] || DEFAULTS[:channel]
  @notifier = Slack::Notifier.new DEFAULTS[:webhook], channel: @channel, username: @name
end

Public Instance Methods

call(allow = false) { || ... } click to toggle source
# File lib/slack-reporter.rb, line 23
def call(allow = false)
  return unless allow || environmet_allows
  @notifier.ping yield
end

Private Instance Methods

create_name(item) click to toggle source
# File lib/slack-reporter.rb, line 30
def create_name(item)
  item = item.class unless item.class == NilClass || String || Class
  string = (item || DEFAULTS[:name]).to_s.downcase
  return string if string.split.count > 1
  string + DEFAULTS[:followup]
end
environment() click to toggle source
# File lib/slack-reporter.rb, line 41
def environment
  if defined?(Rails)
    Rails.env
  elsif defined?(Hanami)
    Hanami.env
  else
    'production'
  end
end
environmet_allows() click to toggle source
# File lib/slack-reporter.rb, line 37
def environmet_allows
  environment == 'production'
end