bosh-template 1.3202.0 → 1.3213.0
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 +4 -4
- data/lib/bosh/template/evaluation_context.rb +34 -1
- data/lib/bosh/template/evaluation_link.rb +38 -0
- data/lib/bosh/template/evaluation_link_instance.rb +48 -0
- data/lib/bosh/template/invalid_property_type.rb +6 -0
- data/lib/bosh/template/property_helper.rb +7 -0
- data/lib/bosh/template/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8a2e0f6e8214ef6fe94b23e3dccc8de6f75b926e
|
|
4
|
+
data.tar.gz: 2ccf9bbb42af66e7daed05c5ff4cd49a4bc8021a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bcdf735a7df58356a46612b2c5de56b9341d789b67e5b511432cb5f6e7f1062d7b49647a288316d7aee044cd0a28016841b5522d9c1a806bd91307a059bb2052
|
|
7
|
+
data.tar.gz: a922bdade2b486692709411d0188adf71c45edd576dc26367b2d43f8c0889f8cfb0a0fec36dc0a880ddcfd2750963dd9883f49d17031b500ae0bec50e402a285
|
|
@@ -3,6 +3,8 @@ require 'bosh/template/evaluation_failed'
|
|
|
3
3
|
require 'bosh/template/unknown_property'
|
|
4
4
|
require 'bosh/template/unknown_link'
|
|
5
5
|
require 'bosh/template/property_helper'
|
|
6
|
+
require 'bosh/template/evaluation_link_instance'
|
|
7
|
+
require 'bosh/template/evaluation_link'
|
|
6
8
|
|
|
7
9
|
module Bosh
|
|
8
10
|
module Template
|
|
@@ -93,8 +95,14 @@ module Bosh
|
|
|
93
95
|
|
|
94
96
|
def link(name)
|
|
95
97
|
result = lookup_property(@links, name)
|
|
96
|
-
|
|
98
|
+
raise UnknownLink.new(name) if result.nil?
|
|
97
99
|
|
|
100
|
+
if result.has_key?("instances")
|
|
101
|
+
instance_array = result["instances"].map do |link_spec|
|
|
102
|
+
EvaluationLinkInstance.new(link_spec["name"], link_spec["index"], link_spec["id"], link_spec["az"], link_spec["address"], link_spec["properties"])
|
|
103
|
+
end
|
|
104
|
+
return EvaluationLink.new(instance_array, result["properties"])
|
|
105
|
+
end
|
|
98
106
|
raise UnknownLink.new(name)
|
|
99
107
|
end
|
|
100
108
|
|
|
@@ -112,6 +120,23 @@ module Bosh
|
|
|
112
120
|
InactiveElseBlock.new
|
|
113
121
|
end
|
|
114
122
|
|
|
123
|
+
# Run a block of code if the link given exists
|
|
124
|
+
# @param [String] name of the link
|
|
125
|
+
# @yield [Object] link, which is an array of instances
|
|
126
|
+
def if_link(name)
|
|
127
|
+
link_found = lookup_property(@links, name)
|
|
128
|
+
if link_found.nil? || !link_found.has_key?("instances")
|
|
129
|
+
return ActiveElseBlock.new(self)
|
|
130
|
+
else
|
|
131
|
+
instance_array = link_found["instances"].map do |link_spec|
|
|
132
|
+
EvaluationLinkInstance.new(link_spec["name"], link_spec["index"], link_spec["id"], link_spec["az"], link_spec["address"], link_spec["properties"])
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
yield EvaluationLink.new(instance_array, link_found["properties"])
|
|
136
|
+
InactiveElseBlock.new
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
115
140
|
# @return [Object] Object representation where all hashes are unrolled
|
|
116
141
|
# into OpenStruct objects. This exists mostly for backward
|
|
117
142
|
# compatibility, as it doesn't provide good error reporting.
|
|
@@ -139,6 +164,10 @@ module Bosh
|
|
|
139
164
|
def else_if_p(*names, &block)
|
|
140
165
|
@context.if_p(*names, &block)
|
|
141
166
|
end
|
|
167
|
+
|
|
168
|
+
def else_if_link(name, &block)
|
|
169
|
+
@context.if_link(name, &block)
|
|
170
|
+
end
|
|
142
171
|
end
|
|
143
172
|
|
|
144
173
|
class InactiveElseBlock
|
|
@@ -148,6 +177,10 @@ module Bosh
|
|
|
148
177
|
def else_if_p(*names)
|
|
149
178
|
InactiveElseBlock.new
|
|
150
179
|
end
|
|
180
|
+
|
|
181
|
+
def else_if_link(name)
|
|
182
|
+
InactiveElseBlock.new
|
|
183
|
+
end
|
|
151
184
|
end
|
|
152
185
|
end
|
|
153
186
|
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Bosh
|
|
2
|
+
module Template
|
|
3
|
+
class EvaluationLink
|
|
4
|
+
include PropertyHelper
|
|
5
|
+
|
|
6
|
+
attr_reader :instances
|
|
7
|
+
attr_reader :properties
|
|
8
|
+
|
|
9
|
+
def initialize(instances, properties)
|
|
10
|
+
@instances = instances
|
|
11
|
+
@properties = properties
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def p(*args)
|
|
15
|
+
names = Array(args[0])
|
|
16
|
+
|
|
17
|
+
names.each do |name|
|
|
18
|
+
result = lookup_property(@properties, name)
|
|
19
|
+
return result unless result.nil?
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
return args[1] if args.length == 2
|
|
23
|
+
raise UnknownProperty.new(names)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def if_p(*names)
|
|
27
|
+
values = names.map do |name|
|
|
28
|
+
value = lookup_property(@properties, name)
|
|
29
|
+
return ActiveElseBlock.new(self) if value.nil?
|
|
30
|
+
value
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
yield *values
|
|
34
|
+
InactiveElseBlock.new
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'bosh/template/property_helper'
|
|
2
|
+
|
|
3
|
+
module Bosh
|
|
4
|
+
module Template
|
|
5
|
+
class EvaluationLinkInstance
|
|
6
|
+
include PropertyHelper
|
|
7
|
+
|
|
8
|
+
attr_reader :name
|
|
9
|
+
attr_reader :index
|
|
10
|
+
attr_reader :id
|
|
11
|
+
attr_reader :az
|
|
12
|
+
attr_reader :address
|
|
13
|
+
attr_reader :properties
|
|
14
|
+
|
|
15
|
+
def initialize(name, index, id, az, address, properties)
|
|
16
|
+
@name = name
|
|
17
|
+
@index = index
|
|
18
|
+
@id = id
|
|
19
|
+
@az = az
|
|
20
|
+
@address = address
|
|
21
|
+
@properties = properties
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def p(*args)
|
|
25
|
+
names = Array(args[0])
|
|
26
|
+
|
|
27
|
+
names.each do |name|
|
|
28
|
+
result = lookup_property(@properties, name)
|
|
29
|
+
return result unless result.nil?
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
return args[1] if args.length == 2
|
|
33
|
+
raise UnknownProperty.new(names)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def if_p(*names)
|
|
37
|
+
values = names.map do |name|
|
|
38
|
+
value = lookup_property(@properties, name)
|
|
39
|
+
return ActiveElseBlock.new(self) if value.nil?
|
|
40
|
+
value
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
yield *values
|
|
44
|
+
InactiveElseBlock.new
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'bosh/template/invalid_property_type'
|
|
2
|
+
|
|
1
3
|
module Bosh
|
|
2
4
|
module Template
|
|
3
5
|
module PropertyHelper
|
|
@@ -12,6 +14,10 @@ module Bosh
|
|
|
12
14
|
dst_ref = dst
|
|
13
15
|
|
|
14
16
|
keys.each do |key|
|
|
17
|
+
unless src_ref.is_a?(Hash)
|
|
18
|
+
raise Bosh::Template::InvalidPropertyType,
|
|
19
|
+
"Property '#{name}' expects a hash, but received '#{src_ref.class}'"
|
|
20
|
+
end
|
|
15
21
|
src_ref = src_ref[key]
|
|
16
22
|
break if src_ref.nil? # no property with this name is src
|
|
17
23
|
end
|
|
@@ -28,6 +34,7 @@ module Bosh
|
|
|
28
34
|
# @param [Hash] collection Property collection
|
|
29
35
|
# @param [String] name Dot-separated property name
|
|
30
36
|
def lookup_property(collection, name)
|
|
37
|
+
return nil if collection.nil?
|
|
31
38
|
keys = name.split(".")
|
|
32
39
|
ref = collection
|
|
33
40
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bosh-template
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3213.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Pivotal
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-03-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: semi_semantic
|
|
@@ -78,6 +78,9 @@ files:
|
|
|
78
78
|
- lib/bosh/template.rb
|
|
79
79
|
- lib/bosh/template/evaluation_context.rb
|
|
80
80
|
- lib/bosh/template/evaluation_failed.rb
|
|
81
|
+
- lib/bosh/template/evaluation_link.rb
|
|
82
|
+
- lib/bosh/template/evaluation_link_instance.rb
|
|
83
|
+
- lib/bosh/template/invalid_property_type.rb
|
|
81
84
|
- lib/bosh/template/property_helper.rb
|
|
82
85
|
- lib/bosh/template/renderer.rb
|
|
83
86
|
- lib/bosh/template/unknown_link.rb
|