Class: Console::Config
- Inherits:
-
Object
- Object
- Console::Config
- Defined in:
- lib/console/config.rb
Overview
Represents a configuration for the traces library.
Constant Summary collapse
- PATH =
ENV.fetch("CONSOLE_CONFIG_PATH", "config/console.rb")
- DEFAULT =
Load the default configuration.
self.default
Class Method Summary collapse
-
.default ⇒ Object
Load the default configuration.
-
.load(path) ⇒ Object
Load the configuration from the given path.
Instance Method Summary collapse
-
#log_level(env = ENV) ⇒ Object
Set the default log level based on ‘$DEBUG` and `$VERBOSE`.
-
#make_logger(io = $stderr, env = ENV, **options) ⇒ Object
Create a logger with the given output and options.
-
#make_output(io = nil, env = ENV, **options) ⇒ Object
Create an output with the given output and options.
-
#make_resolver(logger) ⇒ Object
Create a resolver with the given logger.
-
#verbose?(env = ENV) ⇒ Boolean
Controls verbose output using ‘$VERBOSE`.
Class Method Details
.default ⇒ Object
Load the default configuration.
32 33 34 |
# File 'lib/console/config.rb', line 32 def self.default @default ||= self.load(PATH) end |
.load(path) ⇒ Object
Load the configuration from the given path.
20 21 22 23 24 25 26 27 28 |
# File 'lib/console/config.rb', line 20 def self.load(path) config = self.new if File.exist?(path) config.instance_eval(File.read(path), path) end return config end |
Instance Method Details
#log_level(env = ENV) ⇒ Object
Set the default log level based on ‘$DEBUG` and `$VERBOSE`. You can also specify CONSOLE_LEVEL=debug or CONSOLE_LEVEL=info in environment. mislav.net/2011/06/ruby-verbose-mode/ has more details about how it all fits together.
39 40 41 |
# File 'lib/console/config.rb', line 39 def log_level(env = ENV) Logger.default_log_level(env) end |
#make_logger(io = $stderr, env = ENV, **options) ⇒ Object
Create a logger with the given output and options.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/console/config.rb', line 72 def make_logger(io = $stderr, env = ENV, **) if [:verbose].nil? [:verbose] = self.verbose?(env) end if [:level].nil? [:level] = self.log_level(env) end output = self.make_output(io, env, **) logger = Logger.new(output, **) make_resolver(logger) return logger end |
#make_output(io = nil, env = ENV, **options) ⇒ Object
Create an output with the given output and options.
54 55 56 |
# File 'lib/console/config.rb', line 54 def make_output(io = nil, env = ENV, **) Output.new(io, env, **) end |
#make_resolver(logger) ⇒ Object
Create a resolver with the given logger.
62 63 64 |
# File 'lib/console/config.rb', line 62 def make_resolver(logger) Resolver.default_resolver(logger) end |
#verbose?(env = ENV) ⇒ Boolean
Controls verbose output using ‘$VERBOSE`.
44 45 46 |
# File 'lib/console/config.rb', line 44 def verbose?(env = ENV) !$VERBOSE.nil? || env["CONSOLE_VERBOSE"] end |