Class: Console::Config

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Class Method Details

.defaultObject

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, **options)
	if options[:verbose].nil?
		options[:verbose] = self.verbose?(env)
	end
	
	if options[:level].nil?
		options[:level] = self.log_level(env)
	end
	
	output = self.make_output(io, env, **options)
	
	logger = Logger.new(output, **options)
	
	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, **options)
	Output.new(io, env, **options)
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`.

Returns:

  • (Boolean)


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

def verbose?(env = ENV)
	!$VERBOSE.nil? || env["CONSOLE_VERBOSE"]
end