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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cbdf028e46e168248cefff82e182b2f2e7945fd0
4
- data.tar.gz: c50f410c7f4b87a6d3eaa36d79d4b75aaeb37fea
3
+ metadata.gz: 8689daff779c78d3d1410c9b7cbed0d8fc7e3563
4
+ data.tar.gz: 138659f44c99ebf46ba52199be51419b9454dbb2
5
5
  SHA512:
6
- metadata.gz: 7a13b4484e759eafcb564db5060561703668ba8da192713bc02598f9469b84df68668b3161240be4180b08bb1ceb2731f086523f7dd31fcc4bfafb144e0de80f
7
- data.tar.gz: fbfe91cccdd4ed58a5b84c76637a05e379e0cd9b3009eb88369273c08a4fe4631db03f41a4bce5f1c2477924732f7119beffa5d4f37189a0573e4102824c7ce2
6
+ metadata.gz: e59e855de0537dcfb725c87416e8584aae61f8f8f089b064404839071d7d1ff6736005a53aaf5258f84b8162dc23b840e996abf69c015704bb29fb40040b56fd
7
+ data.tar.gz: e167f321bc96079dfd554a09888d2fb64fb00452a3cdf6422ed018ef2eb192b30a967f40e068ab98ca7c792fa22b48b50a1bf5bf05dae50413942d8a9b09791e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hiera-expander (0.0.1)
4
+ hiera-expander (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -20,16 +20,14 @@ require 'hiera' # loads backend and config
20
20
 
21
21
  class Hiera
22
22
  module Expander
23
- VERSION = "0.0.1"
24
- end
23
+ VERSION = "0.1.1"
25
24
 
26
- alias_method :original_initialize, :initialize
27
- def initialize(*args)
28
- original_initialize(*args)
29
- Config[:expander] ||= {
30
- expand_sources: true,
31
- include_roots: false
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
- def datasources(scope, override=nil, hierarchy=nil)
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 = ["common"]
53
+ hierarchy = ['common']
55
54
  end
56
55
 
57
56
  hierarchy.insert(0, override) if override
58
57
 
59
- hierarchy.flatten.map do |source|
60
- source = parse_string(source, scope, {}, :order_override => override)
61
- unless source.empty? || source =~ %r:(^/|/{2,}|/$):
62
- expand_source(source).each do |src|
63
- yield(src)
64
- end
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 Config[:expander][:expand_sources]
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 Config[:expander][:include_roots]
115
+ paths << root if Expander.config[:include_roots]
98
116
  end
99
117
  end
100
118
  end
101
119
  end
102
- end
120
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiera-expander
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl P. Corliss