hiera-expander 0.0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/hiera/backend/expander.rb +38 -20
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8689daff779c78d3d1410c9b7cbed0d8fc7e3563
|
4
|
+
data.tar.gz: 138659f44c99ebf46ba52199be51419b9454dbb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e59e855de0537dcfb725c87416e8584aae61f8f8f089b064404839071d7d1ff6736005a53aaf5258f84b8162dc23b840e996abf69c015704bb29fb40040b56fd
|
7
|
+
data.tar.gz: e167f321bc96079dfd554a09888d2fb64fb00452a3cdf6422ed018ef2eb192b30a967f40e068ab98ca7c792fa22b48b50a1bf5bf05dae50413942d8a9b09791e
|
data/Gemfile.lock
CHANGED
@@ -20,16 +20,14 @@ require 'hiera' # loads backend and config
|
|
20
20
|
|
21
21
|
class Hiera
|
22
22
|
module Expander
|
23
|
-
VERSION = "0.
|
24
|
-
end
|
23
|
+
VERSION = "0.1.1"
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
}
|
25
|
+
def self.config
|
26
|
+
@config ||= {
|
27
|
+
expand_sources: true,
|
28
|
+
include_roots: false
|
29
|
+
}.merge(Config[:expander] || {})
|
30
|
+
end
|
33
31
|
end
|
34
32
|
|
35
33
|
module Backend
|
@@ -45,24 +43,44 @@ class Hiera
|
|
45
43
|
#
|
46
44
|
# The source names will be subject to variable expansion based
|
47
45
|
# on scope
|
48
|
-
|
46
|
+
alias_method :original_datasources, :datasources
|
47
|
+
def datasources(scope, override=nil, hierarchy=nil, &block)
|
49
48
|
if hierarchy
|
50
49
|
hierarchy = [hierarchy]
|
51
50
|
elsif Config.include?(:hierarchy)
|
52
51
|
hierarchy = [Config[:hierarchy]].flatten
|
53
52
|
else
|
54
|
-
hierarchy = [
|
53
|
+
hierarchy = ['common']
|
55
54
|
end
|
56
55
|
|
57
56
|
hierarchy.insert(0, override) if override
|
58
57
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
58
|
+
# interpolate and expand sources
|
59
|
+
hierarchy.collect! do |source|
|
60
|
+
case method(:parse_string).parameters.size
|
61
|
+
when 4 then
|
62
|
+
source = parse_string(source, scope, {}, :order_override => override)
|
63
|
+
else
|
64
|
+
source = parse_string(source, scope)
|
65
65
|
end
|
66
|
+
|
67
|
+
# cull sources that are empty or have an empty interpolation in the
|
68
|
+
# beginning or middle of the path. Empty interpolations at the end
|
69
|
+
# of the source path are fine and may or may not be culled during the
|
70
|
+
# duplicate source detection and removal phase.
|
71
|
+
next if source.empty? || source =~ %r:(^/|//):
|
72
|
+
|
73
|
+
expand_source(source)
|
74
|
+
end.flatten!.reject!(&:nil?)
|
75
|
+
|
76
|
+
# detect duplicate sources and removing them using a
|
77
|
+
# 'keep-last-duplicate' strategy
|
78
|
+
hierarchy.reverse!
|
79
|
+
hierarchy.uniq!
|
80
|
+
hierarchy.reverse!
|
81
|
+
|
82
|
+
hierarchy.map do |source|
|
83
|
+
yield(source) unless source.empty? || source =~ %r:(^/|//|/$):
|
66
84
|
end
|
67
85
|
end
|
68
86
|
|
@@ -84,7 +102,7 @@ class Hiera
|
|
84
102
|
# If you require the roots on all sources, simply set the config
|
85
103
|
# entry 'include_roots' to true.
|
86
104
|
def expand_source(source)
|
87
|
-
return [source] unless
|
105
|
+
return [source] unless Expander.config[:expand_sources]
|
88
106
|
|
89
107
|
root, path = source.split('/', 2)
|
90
108
|
return [root] if path.nil? || path.empty?
|
@@ -94,9 +112,9 @@ class Hiera
|
|
94
112
|
while subpath = path.pop
|
95
113
|
paths << File.join(root, *path, subpath)
|
96
114
|
end
|
97
|
-
paths << root if
|
115
|
+
paths << root if Expander.config[:include_roots]
|
98
116
|
end
|
99
117
|
end
|
100
118
|
end
|
101
119
|
end
|
102
|
-
end
|
120
|
+
end
|