-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlinear.rb
More file actions
59 lines (48 loc) · 1.52 KB
/
linear.rb
File metadata and controls
59 lines (48 loc) · 1.52 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true
require 'pathname'
require 'semantic_logger'
SemanticLogger.default_level = :info
SemanticLogger.add_appender(io: $stderr, formatter: :color)
# Add the / operator for path separation
class Pathname
def /(other)
join(other.to_s)
end
end
module Rubyists
# Namespace for Linear classes
module Linear
include SemanticLogger::Loggable
# rubocop:disable Layout/SpaceAroundOperators
ROOT = (Pathname(__FILE__)/'../..').expand_path
LIBROOT = ROOT/:lib/:linear
MODEL_ROOT = ROOT/:lib/:linear/:models
SPEC_ROOT = ROOT/:spec
FEATURE_ROOT = ROOT/:features
DEBUG_LEVELS = %i[warn info debug trace].freeze
def self.tmpdir=(other)
@tmpdir = other.is_a?(Pathname) ? other : Pathname(other)
end
def self.tmpdir
@tmpdir || raise('tmpdir not set')
end
def self.L(*libraries) # rubocop:disable Naming/MethodName
Array(libraries).each { |library| require LIBROOT/library }
end
L :exceptions, :version
def self.M(*models) # rubocop:disable Naming/MethodName
Array(models).each { |model| require MODEL_ROOT/model }
end
# rubocop:enable Layout/SpaceAroundOperators
def self.verbosity
@verbosity ||= 0
end
def self.verbosity=(debug)
return unless debug
logger.warn 'Debug level should be between 0 and 3' unless debug.between?(0, 3)
@verbosity = debug
level = @verbosity > (DEBUG_LEVELS.size - 1) ? :trace : DEBUG_LEVELS[@verbosity]
SemanticLogger.default_level = level
end
end
end