Class: Guard::UI::Config

Inherits:
Options
  • Object
show all
Defined in:
lib/guard/ui/config.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Options

#fetch

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/guard/ui/config.rb', line 20

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

Instance Attribute Details

#logger_configObject (readonly)

Returns the value of attribute logger_config


18
19
20
# File 'lib/guard/ui/config.rb', line 18

def logger_config
  @logger_config
end

Instance Method Details

#[](name) ⇒ Object


48
49
50
51
52
53
54
55
56
57
# File 'lib/guard/ui/config.rb', line 48

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

#deviceObject


35
36
37
38
# File 'lib/guard/ui/config.rb', line 35

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

#exceptObject


44
45
46
# File 'lib/guard/ui/config.rb', line 44

def except
  fetch("except")
end

#onlyObject


40
41
42
# File 'lib/guard/ui/config.rb', line 40

def only
  fetch("only")
end

#with_progname(name) ⇒ Object


59
60
61
62
63
64
65
66
67
# File 'lib/guard/ui/config.rb', line 59

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