File: config.rb

package info (click to toggle)
ruby-notiffany 0.1.3-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 580 kB
  • sloc: ruby: 3,094; makefile: 10; sh: 4
file content (34 lines) | stat: -rw-r--r-- 727 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require "logger"

module Notiffany
  class Notifier
    # Configuration class for Notifier
    class Config
      DEFAULTS = { notify: true }.freeze

      attr_reader :env_namespace
      attr_reader :logger
      attr_reader :notifiers

      def initialize(opts)
        options = DEFAULTS.merge(opts)
        @env_namespace = opts.fetch(:namespace, "notiffany")
        @logger = _setup_logger(options)
        @notify = options[:notify]
        @notifiers = opts.fetch(:notifiers, {})
      end

      def notify?
        @notify
      end

      private

      def _setup_logger(opts)
        opts.fetch(:logger) do
          Logger.new($stderr).tap { |l| l.level = Logger::WARN }
        end
      end
    end
  end
end