Class: VCLog::Config

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

Examples:

---
vclog: task/vclog.rb
".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

Instance Method Summary collapse

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(options={})
  @root    = options[:root]  || lookup_root
  @level   = options[:level] || 0
  @force   = options[:force] || false
  @version = options[:version]
end

Instance Attribute Details

#rootObject (readonly)

Project’s root directory.



45
46
47
# File 'lib/vclog/config.rb', line 45

def root
  @root
end

Instance Method Details

#fileObject

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_mapObject

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?

Returns:

  • (Boolean)


57
58
59
# File 'lib/vclog/config.rb', line 57

def force?
  @force
end

#heuristicsObject

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

#levelObject

Default change level.



50
51
52
# File 'lib/vclog/config.rb', line 50

def level
  heuristics.level
end

#lookup_rootObject

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_fileObject

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_typeObject

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

#versionObject

Indicates the version of HEAD.



64
65
66
# File 'lib/vclog/config.rb', line 64

def version
  @version
end