Class: Vars::Options
- Inherits:
-
Object
show all
- Defined in:
- lib/vars/options.rb
Defined Under Namespace
Modules: Defaults, EnvKeys
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(opts = {}) ⇒ Options
Returns a new instance of Options.
19
20
21
22
23
|
# File 'lib/vars/options.rb', line 19
def initialize(opts = {})
@opts = opts.transform_keys(&:to_sym)
@need_fetch = true
end
|
Instance Attribute Details
#opts ⇒ Object
Returns the value of attribute opts.
3
4
5
|
# File 'lib/vars/options.rb', line 3
def opts
@opts
end
|
Instance Method Details
#branch ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/vars/options.rb', line 48
def branch
return opts.fetch(:branch) if opts.key?(:branch)
if ENV.key?(EnvKeys::BRANCH)
opts[:branch] = ENV.fetch(EnvKeys::BRANCH)
elsif in_repository?
opts[:branch] = capture("git symbolic-ref --short HEAD")
else
Defaults::BRANCH
end
end
|
#hash(reload = false) ⇒ Object
25
26
27
28
|
# File 'lib/vars/options.rb', line 25
def hash(reload = false)
@hash = nil if reload
@hash ||= load_source
end
|
#in_repository? ⇒ Boolean
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/vars/options.rb', line 68
def in_repository?
opts[:in_repository] = success?("git rev-parse --git-dir") unless opts.key?(:in_repository)
if opts[:in_repository] && @need_fetch
execute("git fetch #{remote_name}")
@need_fetch = false
end
opts.fetch(:in_repository)
end
|
#load_source ⇒ Object
30
31
32
33
34
35
|
# File 'lib/vars/options.rb', line 30
def load_source
src = YAML.safe_load(ERB.new(raw_source, nil, "-").result(Class.new.__binding__), [], [], true)
return {} if src.nil?
src.fetch("default", {}).merge(src.fetch(name.to_s))
end
|
#repo_path ⇒ Object
41
42
43
44
45
46
|
# File 'lib/vars/options.rb', line 41
def repo_path
return opts.fetch(:repo_path) if opts.key?(:repo_path)
return nil unless in_repository?
opts[:repo_path] = capture("git rev-parse --show-toplevel")
end
|
#source_type ⇒ Object
64
65
66
|
# File 'lib/vars/options.rb', line 64
def source_type
opts.fetch(:source_type, Defaults::SOURCE_TYPE)
end
|