Class: Versioneer::Config
- Inherits:
-
Object
- Object
- Versioneer::Config
show all
- Defined in:
- lib/versioneer/config.rb
Constant Summary
collapse
- DEFAULT_TYPE =
'Git'
- DEFAULT_FILE =
'.versioneer.yml'
- DEFAULT_LOCK =
'version.lock'
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(base_dir_or_config_file, repo_options = nil) ⇒ Config
Returns a new instance of Config.
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
|
# File 'lib/versioneer/config.rb', line 12
def initialize(base_dir_or_config_file, repo_options=nil)
base_dir_or_config_file = base_dir_or_config_file.to_s
if Dir.exist?(base_dir_or_config_file)
@config_base = base_dir_or_config_file
@config_file = File.join(base_dir_or_config_file, DEFAULT_FILE)
unless File.exist?(@config_file)
raise MissingConfigError, "Versioneer config file does not exist. (#{@config_file})"
end
elsif File.exist?(base_dir_or_config_file)
@config_file = base_dir_or_config_file
@config_base = File.dirname(@config_file)
else
raise RuntimeError, "Versioneer base path does not exist. (#{base_dir_or_config_file})"
end
params = YAML.load_file(@config_file)
raise RuntimeError, "Failed to parse YAML file. (#{@config_file})" unless params
params = params.inject({}) { |x, (k, v)| x[k.to_sym] = v; x }
@lock_file = File.join(@config_base, params.delete(:lock_file) || DEFAULT_LOCK)
@repo = nil
@repo_type = (params.delete(:type) || DEFAULT_TYPE).capitalize.to_sym
@repo_options = Hash.new().merge(params.to_h).merge(repo_options.to_h)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
92
93
94
95
96
97
98
|
# File 'lib/versioneer/config.rb', line 92
def method_missing(name, *args, &block)
if repo.respond_to? name
repo.send(name, *args, &block)
else
super
end
end
|
Instance Attribute Details
#config_file ⇒ Object
Returns the value of attribute config_file.
38
39
40
|
# File 'lib/versioneer/config.rb', line 38
def config_file
@config_file
end
|
#lock_file ⇒ Object
Returns the value of attribute lock_file.
38
39
40
|
# File 'lib/versioneer/config.rb', line 38
def lock_file
@lock_file
end
|
Instance Method Details
#lock!(version = nil) ⇒ Object
63
64
65
66
67
68
69
70
|
# File 'lib/versioneer/config.rb', line 63
def lock!(version=nil)
@repo = nil
version ||= repo.to_s
raise RuntimeError, 'Cannot lock. Version neither given nor detected.' if version.to_s.empty?
File.open(@lock_file, 'w') do |file|
file.write(version)
end
end
|
#locked? ⇒ Boolean
59
60
61
|
# File 'lib/versioneer/config.rb', line 59
def locked?
File.exist?(@lock_file)
end
|
#repo ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/versioneer/config.rb', line 40
def repo
return @repo unless @repo.nil?
@repo = case locked?
when true
Bypass.new(@config_base, release: version)
else
unless ::Versioneer.const_defined? @repo_type
raise RuntimeError, "Versioneer::#{@repo_type} is an unknown VCS type."
end
repo_class = ::Versioneer.const_get(@repo_type)
unless repo_class.superclass == ::Versioneer::Repo
raise RuntimeError, "Versioneer::#{@repo_type} is an invalid VCS type."
end
@repo = repo_class.new(@config_base, @repo_options)
end
end
|
#respond_to?(name) ⇒ Boolean
100
101
102
103
|
# File 'lib/versioneer/config.rb', line 100
def respond_to?(name)
return true if repo.respond_to? name
super
end
|
#to_s ⇒ Object
88
89
90
|
# File 'lib/versioneer/config.rb', line 88
def to_s
version.to_s
end
|
#unlock! ⇒ Object
72
73
74
75
76
77
|
# File 'lib/versioneer/config.rb', line 72
def unlock!
@repo = nil
if File.exist?(@lock_file)
File.delete(@lock_file)
end
end
|
#version ⇒ Object
79
80
81
82
83
84
85
86
|
# File 'lib/versioneer/config.rb', line 79
def version
if File.exist?(@lock_file)
version = File.read(@lock_file)
::Gem::Version.new(version)
else
super
end
end
|