mini_hiera 0.1.2 → 0.2.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile.lock +3 -3
- data/lib/mini_hiera.rb +51 -14
- data/lib/mini_hiera/version.rb +1 -1
- data/mini_hiera.gemspec +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e18494403a76998e355b030bd2db2a80cbc18175
|
4
|
+
data.tar.gz: c330263d17f7921188ffa40dc650a9f8ce02a035
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 568a67276ee9b56ce2cf26dba50f3d08a4e025a30c93e7fb019d34db9ef2ed204e0447a5bca849a0ea76f2c3afe6dd639d4ecc803eec25f332119449418e99ca
|
7
|
+
data.tar.gz: 2cc10f45ed391d13a91872aea74af2dc5840ad72b43a768b61d6729bd133195cfedb2b2c616daff831413d2997ae1fd73624a1050e7e0e43ce441558438a0c9b
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mini_hiera (0.
|
4
|
+
mini_hiera (0.2.0.pre1)
|
5
5
|
deep_merge (~> 1.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -28,10 +28,10 @@ PLATFORMS
|
|
28
28
|
ruby
|
29
29
|
|
30
30
|
DEPENDENCIES
|
31
|
-
bundler
|
31
|
+
bundler
|
32
32
|
mini_hiera!
|
33
33
|
rake (~> 10.0)
|
34
34
|
rspec (~> 3.0)
|
35
35
|
|
36
36
|
BUNDLED WITH
|
37
|
-
|
37
|
+
2.0.1
|
data/lib/mini_hiera.rb
CHANGED
@@ -12,10 +12,19 @@ class MiniHiera
|
|
12
12
|
CircularReferenceError = Class.new(RuntimeError)
|
13
13
|
KeyNotFoundError = Class.new(RuntimeError)
|
14
14
|
|
15
|
-
attr_reader :config, :options
|
15
|
+
attr_reader :config, :options, :context_functions, :value_functions
|
16
16
|
def initialize(config, options={})
|
17
17
|
@config = config
|
18
18
|
@options = options
|
19
|
+
@context_functions = {}
|
20
|
+
@value_functions = {}
|
21
|
+
end
|
22
|
+
|
23
|
+
def context_function(name, &impl)
|
24
|
+
@context_functions[name] = impl
|
25
|
+
end
|
26
|
+
def value_function(name, &impl)
|
27
|
+
@value_functions[name] = impl
|
19
28
|
end
|
20
29
|
|
21
30
|
class Context
|
@@ -26,7 +35,19 @@ class MiniHiera
|
|
26
35
|
def postprocess(value)
|
27
36
|
if value.is_a?(String)
|
28
37
|
value.gsub(/\%\{([^}]+)\}/) do |match|
|
29
|
-
|
38
|
+
replace = $1
|
39
|
+
_, block = @hiera.value_functions.find { |name, _| replace =~ /^#{name}\((.*)\)$/ }
|
40
|
+
if block
|
41
|
+
argument = $1
|
42
|
+
argument = if argument =~ /^["'](.*)['"]$/
|
43
|
+
$1
|
44
|
+
else
|
45
|
+
fetch(argument)
|
46
|
+
end
|
47
|
+
block.call(argument)
|
48
|
+
else
|
49
|
+
fetch(replace)
|
50
|
+
end
|
30
51
|
end
|
31
52
|
elsif value.is_a?(Hash)
|
32
53
|
Hash[value.map { |k,v| [k, postprocess(v)] }]
|
@@ -66,22 +87,38 @@ class MiniHiera
|
|
66
87
|
|
67
88
|
default_block_wrapper = lambda { |*_| default_block.arity == 0 ? default_block.call : default_block.call(key) }
|
68
89
|
|
69
|
-
|
90
|
+
# is the first key a function that yields a tree?
|
91
|
+
split_key = key.split(".")
|
92
|
+
_, block = @hiera.context_functions.find { |name, block| split_key.first =~ /^#{name}\(([^\)]*)\)$/ }
|
93
|
+
argument = $1
|
94
|
+
|
70
95
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
elsif data.is_a?(Hash)
|
76
|
-
data = data.fetch(k, &default_block_wrapper)
|
96
|
+
if !!block
|
97
|
+
split_key.shift
|
98
|
+
argument = if argument =~ /^["'](.*)['"]$/
|
99
|
+
$1
|
77
100
|
else
|
78
|
-
|
79
|
-
break
|
101
|
+
fetch(argument)
|
80
102
|
end
|
81
|
-
end
|
82
103
|
|
83
|
-
|
84
|
-
|
104
|
+
block.call(argument).fetch(split_key.join("."))
|
105
|
+
else
|
106
|
+
data = hiera_data
|
107
|
+
split_key.each do |k|
|
108
|
+
if data.is_a?(Array)
|
109
|
+
raise TypeError, "no implicit conversion of String into Integer" unless k.to_i.to_s == k
|
110
|
+
data = data[k.to_i]
|
111
|
+
elsif data.is_a?(Hash)
|
112
|
+
data = data.fetch(k, &default_block_wrapper)
|
113
|
+
else
|
114
|
+
data = default_block_wrapper.call
|
115
|
+
break
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
detect_circular_interpolation(key) do
|
120
|
+
postprocess(data)
|
121
|
+
end
|
85
122
|
end
|
86
123
|
end
|
87
124
|
|
data/lib/mini_hiera/version.rb
CHANGED
data/mini_hiera.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
|
26
26
|
spec.add_dependency 'deep_merge', '~> 1.0'
|
27
27
|
|
28
|
-
spec.add_development_dependency "bundler"
|
28
|
+
spec.add_development_dependency "bundler"
|
29
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
30
30
|
spec.add_development_dependency "rspec", "~> 3.0"
|
31
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_hiera
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0.pre1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Haggett
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deep_merge
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,12 +101,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
103
|
requirements:
|
104
|
-
- - "
|
104
|
+
- - ">"
|
105
105
|
- !ruby/object:Gem::Version
|
106
|
-
version:
|
106
|
+
version: 1.3.1
|
107
107
|
requirements: []
|
108
108
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.5.2.3
|
110
110
|
signing_key:
|
111
111
|
specification_version: 4
|
112
112
|
summary: Hierarchial key/value configuration
|