erb-hiera 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cad7d10ee664cf6998134bc530864207bf5af649
4
- data.tar.gz: cb9f9fd07e9622641ebf124d555da74cba8c53d3
3
+ metadata.gz: fc6d4ae917342fbb62b9debfdcc027099284d98a
4
+ data.tar.gz: b00a638a52371b3cb53622aed168a2964a025214
5
5
  SHA512:
6
- metadata.gz: 99fc9a1ee9264237f40c57ae7bbdba4ee52f188a12eb17226d2e75df211f6e7af2bb38771edf2dfd619525d98da7a5acd89d191a095703e68411b5de4c3e3351
7
- data.tar.gz: d1ba6e4b7626fee5f9812b2d8aa6723ec51fb6aa0cb49d34f3b48105d36d39af0bb357004a15ce994543fc632c7696d32fc9f41fcb884d0081f97b12caf6a0df
6
+ metadata.gz: f5acefa45f15ca30d341c8718d84b904d5bd0292d7f33d5875db10e2ace2e28425c23141bcea0492109a3d90b338c713308232128af22aa1b878e8b020c1e5a6
7
+ data.tar.gz: 33abb2397e7cdac18f735d04660be51c2d0a71609fac1920e65cad7af176c9bf26f97e29ac4ec4f2a737fbefc73950da1d3908d1dfe4f2cff08864210964c731
data/lib/erb-hiera.rb CHANGED
@@ -20,26 +20,23 @@ module ErbHiera
20
20
 
21
21
  mappings.each do |mapping|
22
22
  ErbHiera.scope = mapping["scope"]
23
- in_dir = mapping["dir"]["input"]
24
- out_dir = mapping["dir"]["output"]
23
+ input = mapping["dir"]["input"]
24
+ output = mapping["dir"]["output"]
25
25
 
26
- [:in_dir, :out_dir].each do |dir|
27
- raise StandardError, "error: undefined #{dir.to_s.split('_')[0]}put directory" unless binding.local_variable_get(dir)
26
+ [:input, :output].each do |location|
27
+ raise StandardError, "error: undefined #{dir.to_s.split('_')[0]}put" unless binding.local_variable_get(location)
28
28
  end
29
29
 
30
- manifests(in_dir).each do |manifest|
31
- out_file = File.join(out_dir, manifest.gsub(in_dir, ""))
32
-
33
- Manifest.info(manifest, out_file) if options[:verbose]
34
-
35
- erb = ERB.new(File.read(manifest), nil, "-").result(Hiera.get_binding)
36
-
37
- puts erb if options[:verbose]
30
+ # if input is a file then out_file is a file too
31
+ if input =~ /.erb$/
32
+ generate(output, input)
33
+ next
34
+ end
38
35
 
39
- unless options[:dry_run]
40
- FileUtils.mkdir_p File.dirname(out_file) unless Dir.exists?(File.dirname(out_file))
41
- File.write(out_file, erb)
42
- end
36
+ # otherwise the input/output are directories and all files should be processed..
37
+ manifests(input).each do |manifest|
38
+ out_file = File.join(output, manifest.gsub(input, ""))
39
+ generate(out_file, manifest)
43
40
  end
44
41
  end
45
42
  rescue => error
@@ -49,6 +46,19 @@ module ErbHiera
49
46
 
50
47
  private
51
48
 
49
+ def self.generate(out_file, manifest)
50
+ Manifest.info(manifest, out_file) if options[:verbose]
51
+
52
+ erb = ERB.new(File.read(manifest), nil, "-").result(Hiera.get_binding)
53
+
54
+ puts erb if options[:verbose]
55
+
56
+ unless options[:dry_run]
57
+ FileUtils.mkdir_p File.dirname(out_file) unless Dir.exists?(File.dirname(out_file))
58
+ File.write(out_file, erb)
59
+ end
60
+ end
61
+
52
62
  def self.handle_error(error)
53
63
  if options[:debug]
54
64
  puts
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  module ErbHiera
4
- VERSION = "0.4.2"
4
+ VERSION = "0.4.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erb-hiera
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Wilson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-15 00:00:00.000000000 Z
11
+ date: 2018-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hiera