Class: Test::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/test/config.rb

Constant Summary collapse

GLOB_RC =

Test configuration file.

The name of the file is an ode to the original Ruby cli test tool.

Examples:

.test
.testrb
.test.rb
.config/test.rb
'{.testrb,.test.rb,.test,.config/test.rb,config/test.rb}'
GLOB_ROOT =
'{.ruby,.git,.hg}'

Class Method Summary collapse

Class Method Details

.loadObject



32
33
34
# File 'lib/test/config.rb', line 32

def self.load
  super(rc_file) if rc_file
end

.rc_fileObject

Find rc file.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/test/config.rb', line 37

def self.rc_file
  @rc_file ||= (
    glob    = GLOB_RC
    stop    = root
    default = nil
    dir     = Dir.pwd
    file    = nil
    loop do
      file = Dir[File.join(dir, glob)].first
      break file if file
      break if dir == stop
      dir = File.dirname(dir)
      break if dir == '/'
    end
    file ? file : default
  )
end

.rootObject

Find project root.



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/test/config.rb', line 56

def self.root
  @root ||= (
    glob    = GLOB_ROOT
    stop    = '/'
    default = Dir.pwd
    dir     = Dir.pwd
    until dir == stop
      break dir if Dir[File.join(dir, glob)].first
      dir = File.dirname(dir)
    end
    dir == stop ? default : dir
  )
end