biosphere 0.1.8 → 0.1.9

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: 88020767bf9108cca1476004ddf0341b5feafe88
4
- data.tar.gz: 063cb05d2a0cba8246a49cccdf0d7c396e18ddcb
3
+ metadata.gz: aa6bf1b3024023b7f683aea94a5d9410fb3e5ea2
4
+ data.tar.gz: 2595a001d0345ef607f32a7966c577ddc91da16a
5
5
  SHA512:
6
- metadata.gz: 97728c5ec497caa18604445a6bea2e2adb0cde5f0c906f98a24d97dd62eece20c28519acd4e7072dd8fbf9937594a43e970269e06d28e18b1a325e4a3f8348e9
7
- data.tar.gz: e900d8d19297fe53e4d35d4b2c8b1135d99d4dd80b2174a0b1018e0b631693b8b77650965ac9878bdd4242e7ba12739357ca9939f7e6c672564ae20ad6ec971c
6
+ metadata.gz: 26671009ac8d5ecc2a8a30ca584532aefb447928f1363ee237f5611713d213998a6ea48c813621a9ab8578bc6aa7d69b959ee8809151198a96d9283dc8bf345e
7
+ data.tar.gz: 79c83f3259d51e817a70de605256c3cff2759d1d76d73928f0de10d0ee046d35093f9ea5eea767f9697e9ba203f27a87b266bd9a8c75acc1f0cc4ed87092cbcb
@@ -90,6 +90,7 @@ if options.src
90
90
  STDERR.puts "Loading suite from current directory (#{File.expand_path(options.src)}). Use --src to change the path"
91
91
  end
92
92
 
93
+ # We need to load the suite once so that we can find the Biosphere settings
93
94
  if suite.load_all(options.src) == 0 || suite.deployments.size == 0
94
95
  STDERR.puts "No files found. Are you in the right directory where your biosphere .rb files are?"
95
96
  exit -1
@@ -177,7 +177,33 @@ class Biosphere
177
177
  def self.load_resources(file, context={})
178
178
  resources = []
179
179
  #puts "Loading file #{File.absolute_path(file)}"
180
- str = ERB.new(IO.read(file)).result(OpenStruct.new(context).instance_eval { binding })
180
+ data = IO.read(file)
181
+ begin
182
+ str = ERB.new(data).result(OpenStruct.new(context).instance_eval { binding })
183
+ rescue NoMethodError => e
184
+ puts "Error evaluating erb templating for #{file}. Error: #{e}"
185
+ m = /\(erb\):([0-9]+):/.match(e.backtrace.first)
186
+ if m
187
+ puts "Error at line #{m[1]}. This is before ERB templating."
188
+ linenumber = m[1].to_i
189
+ if linenumber > 0 # Linenumbers seems to be off with 1 as the array is starting at zero
190
+ linenumber = linenumber - 1
191
+ end
192
+ lines = data.split("\n")
193
+ start_line = [0, linenumber - 3].max
194
+ end_line = [lines.length - 1, linenumber + 3].min
195
+ lines[start_line..end_line].each_with_index do |line, num|
196
+ num += start_line
197
+ if num == linenumber
198
+ STDERR.printf("%04d> %s\n".red, num, line)
199
+ else
200
+ STDERR.printf("%04d| %s\n", num, line)
201
+ end
202
+ end
203
+ end
204
+ raise e
205
+ end
206
+
181
207
  begin
182
208
  Psych.load_stream(str) do |document|
183
209
  kind = document["kind"]
@@ -190,11 +216,16 @@ class Biosphere
190
216
  STDERR.puts "Here are the relevant lines. Error '#{e.problem}' occured at line #{e.line}"
191
217
  STDERR.puts "Notice that yaml is very picky about indentation when you have arrays and maps. Check those first."
192
218
  lines = str.split("\n")
193
- start_line = [0, e.line - 3].max
194
- end_line = [lines.length - 1, e.line + 3].min
219
+ linenumber = e.line
220
+ if linenumber > 0 # Linenumbers seems to be off with 1 as the array is starting at zero
221
+ linenumber = linenumber - 1
222
+ end
223
+
224
+ start_line = [0, linenumber - 3].max
225
+ end_line = [lines.length - 1, linenumber + 3].min
195
226
  lines[start_line..end_line].each_with_index do |line, num|
196
227
  num += start_line
197
- if num == e.line
228
+ if num == linenumber
198
229
  STDERR.printf("%04d> %s\n".red, num, line)
199
230
  else
200
231
  STDERR.printf("%04d| %s\n", num, line)
@@ -2,6 +2,7 @@ require 'pp'
2
2
  require 'ipaddress'
3
3
  require 'biosphere/node'
4
4
  require 'deep_merge'
5
+ require 'deep_dup'
5
6
 
6
7
  class Biosphere
7
8
  class State
@@ -51,7 +52,34 @@ class Biosphere
51
52
 
52
53
  def load_from_structure!(structure)
53
54
  if @node
54
- @node.data.deep_merge(structure.data)
55
+
56
+ # Objects which might get removed when building a new state need to be stored away before the merge
57
+ feature_manifests = {}
58
+ @node.data[:deployments].each do |name, deployment|
59
+ if deployment[:feature_manifests]
60
+ feature_manifests[name] = ::DeepDup.deep_dup(deployment[:feature_manifests])
61
+ end
62
+ end
63
+
64
+ # Merge the structured state into the current state
65
+ @node.data.deep_merge(structure.data, {:overwrite_arrays => true})
66
+
67
+ # Now re-apply the stored objects on top of the merged state so that removes are handled correctly
68
+ @node.data[:deployments].each do |name, deployment|
69
+ removed = {}
70
+ if feature_manifests[name]
71
+ feature_manifests[name].each do |section, manifests|
72
+ diff = deployment[:feature_manifests][section] - manifests
73
+ removed[section] = diff if diff.length > 0
74
+ end
75
+ deployment[:feature_manifests] = feature_manifests[name]
76
+ end
77
+
78
+ if removed.length > 0
79
+ deployment[:removed_feature_manifests] = removed
80
+ end
81
+ end
82
+
55
83
  else
56
84
  @node = structure
57
85
  end
@@ -1,3 +1,3 @@
1
1
  class Biosphere
2
- Version = "0.1.8"
2
+ Version = "0.1.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: biosphere
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juho Mäkinen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-24 00:00:00.000000000 Z
11
+ date: 2017-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec