Sha256: 23a53db2868add8bbef47f8b3a77196b017897f1532f8d0e386e0091c0b8b471

Contents?: true

Size: 1.62 KB

Versions: 31

Compression:

Stored size: 1.62 KB

Contents

require "guard/options"
require "guard/ui/logger"

module Guard
  module UI
    class Config < Guard::Options
      DEFAULTS = {
        only: nil,
        except: nil,

        # nil (will be whatever $stderr is later) or LumberJack device, e.g.
        # $stderr or 'foo.log'
        device: nil,
      }.freeze

      DEPRECATED_OPTS = %w(template time_format level progname).freeze

      attr_reader :logger_config

      def initialize(options = {})
        opts = Guard::Options.new(options, DEFAULTS)

        # migrate old options stored in UI config directly
        deprecated_logger_opts = {}
        DEPRECATED_OPTS.each do |option|
          if opts.key?(option)
            deprecated_logger_opts[option.to_sym] = opts.delete(option)
          end
        end

        @logger_config = Logger::Config.new(deprecated_logger_opts)
        super(opts.to_hash)
      end

      def device
        # Use strings to work around Thor's indifferent Hash's bug
        fetch("device") || $stderr
      end

      def only
        fetch("only")
      end

      def except
        fetch("except")
      end

      def [](name)
        name = name.to_s

        # TODO: remove in Guard 3.x
        return logger_config[name] if DEPRECATED_OPTS.include?(name)
        return device if name == "device"

        # let Thor's Hash handle anything else
        super(name.to_s)
      end

      def with_progname(name)
        if Guard::UI.logger.respond_to?(:set_progname)
          Guard::UI.logger.set_progname(name) do
            yield if block_given?
          end
        elsif block_given?
          yield
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 7 rubygems

Version Path
guard-2.19.0 lib/guard/ui/config.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/guard-2.18.1/lib/guard/ui/config.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/guard-2.18.1/lib/guard/ui/config.rb
guard-2.18.1 lib/guard/ui/config.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/guard-2.18.0/lib/guard/ui/config.rb
guard-2.18.0 lib/guard/ui/config.rb
guard-2.17.0 lib/guard/ui/config.rb
qiita_org-0.1.35 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/ui/config.rb
qiita_org-0.1.34 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/ui/config.rb
qiita_org-0.1.33 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/ui/config.rb
qiita_org-0.1.32 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/ui/config.rb
qiita_org-0.1.31 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/ui/config.rb
qiita_org-0.1.30 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/ui/config.rb
qiita_org-0.1.29 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/ui/config.rb
qiita_org-0.1.28 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/ui/config.rb
qiita_org-0.1.27 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/ui/config.rb
qiita_org-0.1.26 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/ui/config.rb
qiita_org-0.1.25 gems/ruby/2.7.0/gems/guard-2.16.2/lib/guard/ui/config.rb
guard-2.16.2 lib/guard/ui/config.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/guard-2.15.0/lib/guard/ui/config.rb