40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/hiera/backend/fragment_backend.rb', line 40
def self.process_files
conf = Config[:fragment]
data_dir = conf[:datadir]
if conf[:extensions] and not conf[:extensions].to_set.subset? SUPPORTED_EXTENSIONS.to_set
raise "Unsupported extensions #{conf[:extensions]}. Only #{SUPPORTED_EXTENSIONS} are supported"
end
extensions = [conf[:extensions] || SUPPORTED_EXTENSIONS].flatten.join(',')
fragments = [conf[:fragments]].flatten.map do |fragment|
path_join_glob(data_dir, "#{fragment}.{#{extensions}}")
end.flatten.select do |file|
File.file? file
end
if fragments.empty?
warn "No fragments found in #{data_dir}"
end
dest_dir = conf[:destdir] || Config[:yaml][:datadir]
input_dirs = [conf[:inputdirs]].flatten.map { |file| Pathname.new(file).realpath.to_s }
debug "Cleaning output dir: #{dest_dir}"
FileUtils.rm_rf dest_dir
FileUtils.mkdir_p dest_dir
glob_pattern = "**/*.{#{extensions}}"
debug "Using fragments #{fragments.join(',')}"
merge_input(fragments, glob_pattern, input_dirs) do |yaml_file, input_dir, yaml|
output_file = Pathname.new(yaml_file).realpath.to_s.sub(input_dir, dest_dir)
debug "Writing to #{output_file}"
FileUtils.mkdir_p File.dirname(output_file)
File.open(output_file, 'w+') { |file| YAML.dump(yaml, file) }
end
end
|