Sha256: 32e8221bf397528754ff596f05ccf090b81b54b851b159d6c6ee0def528c4054

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require 'active_support/logger'
require 'active_support/core_ext/module/attribute_accessors'

require 'net/http'
require 'net/https'
require 'uri'

require 'slack_webhook_logger/logger'
require 'slack_webhook_logger/formatter'
require 'slack_webhook_logger/request_io'

module SlackWebhookLogger
  # Can be modified in Rails app
  mattr_accessor :webhook_url
  mattr_accessor :level
  mattr_accessor :formatter
  mattr_accessor :ignore_patterns

  # Used internally
  mattr_reader :webhook_uri
  mattr_reader :logger
  mattr_reader :https

  # rubocop:disable Style/ClassVars
  def self.setup
    @@logger = SlackWebhookLogger::Logger.new(SlackWebhookLogger::RequestIO)

    yield self

    @@logger.formatter = @@formatter || SlackWebhookLogger::Formatter.new
    @@logger.level = @@level || :warn

    @@webhook_uri = URI.parse(@@webhook_url)
    https = Net::HTTP.new(@@webhook_uri.host, @@webhook_uri.port)
    https.use_ssl = true
    https.verify_mode = OpenSSL::SSL::VERIFY_PEER

    @@https = https

    @@ignore_patterns ||= []
  end
  # rubocop:enable Style/ClassVars
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
slack_webhook_logger-0.3.1 lib/slack_webhook_logger.rb
slack_webhook_logger-0.3.0 lib/slack_webhook_logger.rb
slack_webhook_logger-0.2.2 lib/slack_webhook_logger.rb
slack_webhook_logger-0.2.1 lib/slack_webhook_logger.rb
slack_webhook_logger-0.2.0 lib/slack_webhook_logger.rb