Class: Dply::MetaConfig
- Inherits:
-
Object
show all
- Includes:
- Helper
- Defined in:
- lib/dply/meta_config.rb
Instance Method Summary
collapse
Methods included from Helper
#cmd, #error, #git, #logger, #sh, #symlink
Constructor Details
10
11
12
13
14
15
|
# File 'lib/dply/meta_config.rb', line 10
def initialize(dir)
@sources = []
@dir = dir
@output_path = "#{dir}/meta_generated.yml"
@tmpfile = "#{dir}/meta.tmp"
end
|
Instance Method Details
#define(&block) ⇒ Object
17
18
19
|
# File 'lib/dply/meta_config.rb', line 17
def define(&block)
instance_eval(&block)
end
|
#generate ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/dply/meta_config.rb', line 21
def generate
config = {}
@sources.each do |i|
path = i.fetch(:path)
url = i.fetch(:url)
optional = i.fetch(:optional)
deep_merge = i.fetch(:deep_merge)
block = i.fetch(:block)
if url
download(url, path, optional: optional)
end
if block
instance_exec path, optional, &block
end
h = load_yml(path, optional: optional)
deep_merge ? config.deep_merge!(h) : config.merge!(h)
end
File.write @tmpfile, YAML.dump(config)
FileUtils.mv @tmpfile, @output_path
end
|