Class: VCLog::Config
- Inherits:
-
Object
- Object
- VCLog::Config
- Defined in:
- lib/vclog/config.rb
Overview
Encapsulates configuration settings for running vclog.
Constant Summary collapse
- MAP_FILE =
If not in a default location a ‘.map` entry can be used to tell vclog where the config file it located.
".map"
- DEFAULT_GLOB =
Default vclog config file glob looks for these possible matches in order:
-
.vclog
-
.config/vclog
-
config/vclog
-
.dot/vclog
-
dot/vclog
File may have optional ‘.rb` extension.
-
'{.,.config/,config/.dot/,dot/}vclog{,.rb}'
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Project’s root directory.
Instance Method Summary collapse
-
#file ⇒ Object
The vclog config file.
-
#file_map ⇒ Object
Load the map file.
-
#force? ⇒ Boolean
Force mode active?.
-
#heuristics ⇒ Object
Load heuristics.
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
-
#level ⇒ Object
Default change level.
-
#lookup_root ⇒ Object
Find project root.
-
#map_file ⇒ Object
Project’s map file, if present.
-
#vcs_type ⇒ Object
Which version control system?.
-
#version ⇒ Object
Indicates the version of HEAD.
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
35 36 37 38 39 40 |
# File 'lib/vclog/config.rb', line 35 def initialize(={}) @root = [:root] || lookup_root @level = [:level] || 0 @force = [:force] || false @version = [:version] end |
Instance Attribute Details
#root ⇒ Object (readonly)
Project’s root directory.
45 46 47 |
# File 'lib/vclog/config.rb', line 45 def root @root end |
Instance Method Details
#file ⇒ Object
The vclog config file.
97 98 99 100 101 102 103 |
# File 'lib/vclog/config.rb', line 97 def file if glob = file_map['vclog'] Dir.glob(glob).first else Dir.glob(DEFAULT_GLOB).first end end |
#file_map ⇒ Object
Load the map file.
117 118 119 120 121 |
# File 'lib/vclog/config.rb', line 117 def file_map @file_map ||= ( map_file ? YAML.load_file(map_file) : {} ) end |
#force? ⇒ Boolean
Force mode active?
57 58 59 |
# File 'lib/vclog/config.rb', line 57 def force? @force end |
#heuristics ⇒ Object
Load heuristics.
71 72 73 74 75 76 77 78 79 |
# File 'lib/vclog/config.rb', line 71 def heuristics @heuristics ||= ( if file Heuristics.load(file) else Heuristics.new end ) end |
#level ⇒ Object
Default change level.
50 51 52 |
# File 'lib/vclog/config.rb', line 50 def level heuristics.level end |
#lookup_root ⇒ Object
Find project root. This searches up from the current working directory for a .map configuration file or source control manager directory.
.ruby/
.map
.git/
.hg/
.svn/
_darcs/
If all else fails the current directory is returned.
137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/vclog/config.rb', line 137 def lookup_root root = nil Dir.ascend(Dir.pwd) do |path| check = Dir[ROOT_GLOB].first if check root = path break end end root || Dir.pwd end |
#map_file ⇒ Object
Project’s map file, if present.
108 109 110 111 112 |
# File 'lib/vclog/config.rb', line 108 def map_file file = File.join(root, MAP_FILE) return file if File.exist?(file) return nil end |
#vcs_type ⇒ Object
Which version control system?
84 85 86 87 88 89 90 91 92 |
# File 'lib/vclog/config.rb', line 84 def vcs_type @vcs_type ||= ( dir = nil Dir.chdir(root) do dir = Dir.glob("{.git,.hg,.svn,_darcs}").first end dir[1..-1] if dir ) end |
#version ⇒ Object
Indicates the version of HEAD.
64 65 66 |
# File 'lib/vclog/config.rb', line 64 def version @version end |