lorj 1.0.9 → 1.0.10

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.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -0
  3. data/example/students_1/process/students.rb +1 -1
  4. data/example/students_1/student_v1.md +2 -0
  5. data/example/students_1/students.rb +2 -1
  6. data/example/students_2/process/students.rb +1 -1
  7. data/example/students_2/students.rb +4 -2
  8. data/example/students_3/controller/yaml_students_def.rb +1 -1
  9. data/example/students_3/process/students.rb +1 -1
  10. data/example/students_3/student_v3.md +5 -3
  11. data/example/students_3/students.rb +5 -3
  12. data/example/students_4/controller/yaml_students_def.rb +1 -1
  13. data/example/students_4/process/students/definition/students.rb +1 -1
  14. data/example/students_4/students.rb +5 -3
  15. data/example/students_5/controller/yaml_students.rb +1 -1
  16. data/example/students_5/process/students.rb +1 -1
  17. data/example/students_5/student_v5.md +4 -4
  18. data/example/students_5/students.rb +8 -7
  19. data/example/yaml_students/students.rb +4 -4
  20. data/lib/core/core.rb +110 -64
  21. data/lib/core/core_internal.rb +110 -15
  22. data/lib/core/core_object_data.rb +4 -4
  23. data/lib/core/core_process_setup.rb +3 -30
  24. data/lib/core/lorj_data.rb +1 -1
  25. data/lib/core/lorj_keypath.rb +3 -1
  26. data/lib/core/process.rb +67 -0
  27. data/lib/lorj/version.rb +2 -1
  28. data/lib/lorj.rb +3 -4
  29. data/lib/lorj_account.rb +6 -5
  30. data/lib/lorj_config.rb +3 -2
  31. data/lib/providers/templates/compute.rb +1 -1
  32. data/lorj-spec/controllers/mock/mock.rb +144 -0
  33. data/lorj-spec/data.yaml +0 -0
  34. data/lorj-spec/process/mock2_process.rb +48 -0
  35. data/lorj-spec/process/mock_process.rb +48 -0
  36. data/lorj-spec/providers/mock2/mock2.rb +0 -0
  37. data/lorj.gemspec +2 -4
  38. data/spec/05_lorj_keypath_spec.rb +78 -0
  39. data/spec/20_lorj_meta_spec.rb +1 -1
  40. data/spec/21_lorj_processes_spec.rb +115 -0
  41. metadata +27 -42
  42. data/lib/core_process/cloud/process/common.rb +0 -60
  43. data/lib/core_process/cloud/process/connection.rb +0 -92
  44. data/lib/core_process/cloud/process/external_network.rb +0 -90
  45. data/lib/core_process/cloud/process/flavor.rb +0 -97
  46. data/lib/core_process/cloud/process/images.rb +0 -99
  47. data/lib/core_process/cloud/process/internet_network.rb +0 -33
  48. data/lib/core_process/cloud/process/internet_server.rb +0 -29
  49. data/lib/core_process/cloud/process/keypairs.rb +0 -332
  50. data/lib/core_process/cloud/process/network.rb +0 -107
  51. data/lib/core_process/cloud/process/public_ip.rb +0 -102
  52. data/lib/core_process/cloud/process/router.rb +0 -267
  53. data/lib/core_process/cloud/process/rules.rb +0 -120
  54. data/lib/core_process/cloud/process/security_groups.rb +0 -120
  55. data/lib/core_process/cloud/process/server.rb +0 -126
  56. data/lib/core_process/cloud/process/server_log.rb +0 -34
  57. data/lib/core_process/cloud/process/subnetwork.rb +0 -96
  58. data/lib/core_process/cloud_process.rb +0 -30
  59. data/lib/prc_base_config.rb +0 -300
  60. data/lib/prc_core_config.rb +0 -1258
  61. data/lib/prc_section_config.rb +0 -90
  62. data/lib/providers/hpcloud/compute.rb +0 -105
  63. data/lib/providers/hpcloud/hpcloud.rb +0 -462
  64. data/lib/providers/hpcloud/network.rb +0 -115
  65. data/lib/providers/hpcloud/security_groups.rb +0 -68
  66. data/lib/providers/openstack/openstack.rb +0 -410
  67. data/lib/providers/openstack/openstack_create.rb +0 -205
  68. data/lib/providers/openstack/openstack_delete.rb +0 -28
  69. data/lib/providers/openstack/openstack_get.rb +0 -39
  70. data/lib/providers/openstack/openstack_process.rb +0 -26
  71. data/lib/providers/openstack/openstack_query.rb +0 -96
  72. data/lib/providers/openstack/openstack_update.rb +0 -35
  73. data/lib/rh.rb +0 -426
  74. data/spec/01_hash_rh_spec.rb +0 -282
  75. data/spec/02_prc_base_config_spec.rb +0 -227
  76. data/spec/03_prc_section_config_spec.rb +0 -196
  77. data/spec/04_prc_core_config_spec.rb +0 -325
data/lib/rh.rb DELETED
@@ -1,426 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
-
18
- require 'rubygems'
19
- require 'yaml'
20
-
21
- # Adding rh_clone at object level. This be able to use a generic rh_clone
22
- # redefined per object Hash and Array.
23
- class Object
24
- alias_method :rh_clone, :clone
25
- end
26
-
27
- # Recursive Hash added to the Hash class
28
- class Hash
29
- # Recursive Hash deep level found counter
30
- # This function will returns the count of deep level of recursive hash.
31
- # * *Args* :
32
- # - +p+ : Array of string or symbols. keys tree to follow and check
33
- # existence in yVal.
34
- #
35
- # * *Returns* :
36
- # - +integer+ : Represents how many deep level was found in the recursive
37
- # hash
38
- #
39
- # * *Raises* :
40
- # No exceptions
41
- #
42
- # Example: (implemented in spec)
43
- #
44
- # yVal = { :test => {:test2 => 'value1', :test3 => 'value2'},
45
- # :test4 => 'value3'}
46
- #
47
- # yVal can be represented like:
48
- #
49
- # yVal:
50
- # test:
51
- # test2 = 'value1'
52
- # test3 = 'value2'
53
- # test4 = 'value3'
54
- #
55
- # so:
56
- # # test is found
57
- # yVal.rh_lexist?(:test) => 1
58
- #
59
- # # no test5
60
- # yVal.rh_lexist?(:test5) => 0
61
- #
62
- # # :test/:test2 tree is found
63
- # yVal.rh_lexist?(:test, :test2) => 2
64
- #
65
- # # :test/:test2 is found (value = 2), but :test5 was not found in this tree
66
- # yVal.rh_lexist?(:test, :test2, :test5) => 2
67
- #
68
- # # :test was found. but :test/:test5 tree was not found. so level 1, ok.
69
- # yVal.rh_lexist?(:test, :test5 ) => 1
70
- #
71
- # # it is like searching for nothing...
72
- # yVal.rh_lexist? => 0
73
-
74
- def rh_lexist?(*p)
75
- p = p.flatten
76
-
77
- return 0 if p.length == 0
78
-
79
- if p.length == 1
80
- return 1 if self.key?(p[0])
81
- return 0
82
- end
83
- return 0 unless self.key?(p[0])
84
- ret = 0
85
- ret = self[p[0]].rh_lexist?(p.drop(1)) if self[p[0]].is_a?(Hash)
86
- 1 + ret
87
- end
88
-
89
- # Recursive Hash deep level existence
90
- #
91
- # * *Args* :
92
- # - +p+ : Array of string or symbols. keys tree to follow and check
93
- # existence in yVal.
94
- #
95
- # * *Returns* :
96
- # - +boolean+ : Returns True if the deep level of recursive hash is found.
97
- # false otherwise
98
- #
99
- # * *Raises* :
100
- # No exceptions
101
- #
102
- # Example:(implemented in spec)
103
- #
104
- # yVal = { :test => {:test2 => 'value1', :test3 => 'value2'},
105
- # :test4 => 'value3'}
106
- #
107
- # yVal can be represented like:
108
- #
109
- # yVal:
110
- # test:
111
- # test2 = 'value1'
112
- # test3 = 'value2'
113
- # test4 = 'value3'
114
- #
115
- # so:
116
- # # test is found
117
- # yVal.rh_exist?(:test) => True
118
- #
119
- # # no test5
120
- # yVal.rh_exist?(:test5) => False
121
- #
122
- # # :test/:test2 tree is found
123
- # yVal.rh_exist?(:test, :test2) => True
124
- #
125
- # # :test/:test2 is found (value = 2), but :test5 was not found in this tree
126
- # yVal.rh_exist?(:test, :test2, :test5) => False
127
- #
128
- # # :test was found. but :test/:test5 tree was not found. so level 1, ok.
129
- # yVal.rh_exist?(:test, :test5 ) => False
130
- #
131
- # # it is like searching for nothing...
132
- # yVal.rh_exist? => nil
133
- def rh_exist?(*p)
134
- p = p.flatten
135
-
136
- return nil if p.length == 0
137
-
138
- count = p.length
139
- (rh_lexist?(*p) == count)
140
- end
141
-
142
- # Recursive Hash Get
143
- # This function will returns the level of recursive hash was found.
144
- # * *Args* :
145
- # - +p+ : Array of string or symbols. keys tree to follow and check
146
- # existence in yVal.
147
- #
148
- # * *Returns* :
149
- # - +value+ : Represents the data found in the tree. Can be of any type.
150
- #
151
- # * *Raises* :
152
- # No exceptions
153
- #
154
- # Example:(implemented in spec)
155
- #
156
- # yVal = { :test => {:test2 => 'value1', :test3 => 'value2'},
157
- # :test4 => 'value3'}
158
- #
159
- # yVal can be represented like:
160
- #
161
- # yVal:
162
- # test:
163
- # test2 = 'value1'
164
- # test3 = 'value2'
165
- # test4 = 'value3'
166
- #
167
- # so:
168
- # yVal.rh_get(:test) => {:test2 => 'value1', :test3 => 'value2'}
169
- # yVal.rh_get(:test5) => nil
170
- # yVal.rh_get(:test, :test2) => 'value1'
171
- # yVal.rh_get(:test, :test2, :test5) => nil
172
- # yVal.rh_get(:test, :test5 ) => nil
173
- # yVal.rh_get => { :test => {:test2 => 'value1', :test3 => 'value2'},
174
- # :test4 => 'value3'}
175
- def rh_get(*p)
176
- p = p.flatten
177
- return self if p.length == 0
178
-
179
- if p.length == 1
180
- return self[p[0]] if self.key?(p[0])
181
- return nil
182
- end
183
- return self[p[0]].rh_get(p.drop(1)) if self[p[0]].is_a?(Hash)
184
- nil
185
- end
186
-
187
- # Recursive Hash Set
188
- # This function will build a recursive hash according to the '*p' key tree.
189
- # if yVal is not nil, it will be updated.
190
- #
191
- # * *Args* :
192
- # - +p+ : Array of string or symbols. keys tree to follow and check
193
- # existence in yVal.
194
- #
195
- # * *Returns* :
196
- # - +value+ : the value set.
197
- #
198
- # * *Raises* :
199
- # No exceptions
200
- #
201
- # Example:(implemented in spec)
202
- #
203
- # yVal = {}
204
- #
205
- # yVal.rh_set(:test) => nil
206
- # # yVal = {}
207
- #
208
- # yVal.rh_set(:test5) => nil
209
- # # yVal = {}
210
- #
211
- # yVal.rh_set(:test, :test2) => :test
212
- # # yVal = {:test2 => :test}
213
- #
214
- # yVal.rh_set(:test, :test2, :test5) => :test
215
- # # yVal = {:test2 => {:test5 => :test} }
216
- #
217
- # yVal.rh_set(:test, :test5 ) => :test
218
- # # yVal = {:test2 => {:test5 => :test}, :test5 => :test }
219
- #
220
- # yVal.rh_set('blabla', :test2, 'text') => :test
221
- # # yVal = {:test2 => {:test5 => :test, 'text' => 'blabla'},
222
- # :test5 => :test }
223
- def rh_set(value, *p)
224
- p = p.flatten
225
- return nil if p.length == 0
226
-
227
- if p.length == 1
228
- self[p[0]] = value
229
- return value
230
- end
231
-
232
- self[p[0]] = {} unless self[p[0]].is_a?(Hash)
233
- self[p[0]].rh_set(value, p.drop(1))
234
- end
235
-
236
- # Recursive Hash delete
237
- # This function will remove the last key defined by the key tree
238
- #
239
- # * *Args* :
240
- # - +p+ : Array of string or symbols. keys tree to follow and check
241
- # existence in yVal.
242
- #
243
- # * *Returns* :
244
- # - +value+ : The Hash updated.
245
- #
246
- # * *Raises* :
247
- # No exceptions
248
- #
249
- # Example:(implemented in spec)
250
- #
251
- # yVal = {{:test2 => { :test5 => :test,
252
- # 'text' => 'blabla' },
253
- # :test5 => :test}}
254
- #
255
- #
256
- # yVal.rh_del(:test) => nil
257
- # # yVal = no change
258
- #
259
- # yVal.rh_del(:test, :test2) => nil
260
- # # yVal = no change
261
- #
262
- # yVal.rh_del(:test2, :test5) => {:test5 => :test}
263
- # # yVal = {:test2 => {:test5 => :test} }
264
- #
265
- # yVal.rh_del(:test, :test2)
266
- # # yVal = {:test2 => {:test5 => :test} }
267
- #
268
- # yVal.rh_del(:test, :test5)
269
- # # yVal = {:test2 => {} }
270
- #
271
- def rh_del(*p)
272
- p = p.flatten
273
-
274
- return nil if p.length == 0
275
-
276
- return delete(p[0]) if p.length == 1
277
-
278
- return nil if self[p[0]].nil?
279
- self[p[0]].rh_del(p.drop(1))
280
- end
281
-
282
- # Move levels (default level 1) of tree keys to become symbol.
283
- #
284
- # * *Args* :
285
- # - +levels+: level of key tree to update.
286
- # * *Returns* :
287
- # - a new hash of hashes updated. Original Hash is not updated anymore.
288
- #
289
- # examples:
290
- # With hdata = { :test => { :test2 => { :test5 => :test,
291
- # 'text' => 'blabla' },
292
- # 'test5' => 'test' }}
293
- #
294
- # hdata.rh_key_to_symbol(1) return no diff
295
- # hdata.rh_key_to_symbol(2) return "test5" is replaced by :test5
296
- # # hdata = { :test => { :test2 => { :test5 => :test,
297
- # # 'text' => 'blabla' },
298
- # # :test5 => 'test' }}
299
- # rh_key_to_symbol(3) return "test5" replaced by :test5, and "text" to :text
300
- # # hdata = { :test => { :test2 => { :test5 => :test,
301
- # # :text => 'blabla' },
302
- # # :test5 => 'test' }}
303
- # rh_key_to_symbol(4) same like rh_key_to_symbol(3)
304
-
305
- def rh_key_to_symbol(levels = 1)
306
- result = {}
307
- each do |key, value|
308
- new_key = key
309
- new_key = key.to_sym if key.is_a?(String)
310
- if value.is_a?(Hash) && levels > 1
311
- value = value.rh_key_to_symbol(levels - 1)
312
- end
313
- result[new_key] = value
314
- end
315
- result
316
- end
317
-
318
- # Check if levels of tree keys are all symbols.
319
- #
320
- # * *Args* :
321
- # - +levels+: level of key tree to update.
322
- # * *Returns* :
323
- # - true : one key path is not symbol.
324
- # - false : all key path are symbols.
325
- # * *Raises* :
326
- # Nothing
327
- #
328
- # examples:
329
- # With hdata = { :test => { :test2 => { :test5 => :test,
330
- # 'text' => 'blabla' },
331
- # 'test5' => 'test' }}
332
- #
333
- # hdata.rh_key_to_symbol?(1) return false
334
- # hdata.rh_key_to_symbol?(2) return true
335
- # hdata.rh_key_to_symbol?(3) return true
336
- # hdata.rh_key_to_symbol?(4) return true
337
- def rh_key_to_symbol?(levels = 1)
338
- each do |key, value|
339
- return true if key.is_a?(String)
340
-
341
- res = false
342
- if levels > 1 && value.is_a?(Hash)
343
- res = value.rh_key_to_symbol?(levels - 1)
344
- end
345
- return true if res
346
- end
347
- false
348
- end
349
-
350
- # return an exact clone of the recursive Array and Hash contents.
351
- #
352
- # * *Args* :
353
- #
354
- # * *Returns* :
355
- # - Recursive Array/Hash cloned. Other kind of objects are kept referenced.
356
- # * *Raises* :
357
- # Nothing
358
- #
359
- # examples:
360
- # hdata = { :test => { :test2 => { :test5 => :test,
361
- # 'text' => 'blabla' },
362
- # 'test5' => 'test' },
363
- # :array => [{ :test => :value1 }, 2, { :test => :value3 }]}
364
- #
365
- # hclone = hdata.rh_clone
366
- # hclone[:test] = "test"
367
- # hdata[:test] == { :test2 => { :test5 => :test,'text' => 'blabla' }
368
- # # => true
369
- # hclone[:array].pop
370
- # hdata[:array].length != hclone[:array].length
371
- # # => true
372
- # hclone[:array][0][:test] = "value2"
373
- # hdata[:array][0][:test] != hclone[:array][0][:test]
374
- # # => true
375
- def rh_clone
376
- result = {}
377
- each do |key, value|
378
- if [Array, Hash].include?(value.class)
379
- result[key] = value.rh_clone
380
- else
381
- result[key] = value
382
- end
383
- end
384
- result
385
- end
386
- end
387
-
388
- # Defines rh_clone for Array
389
- class Array
390
- # return an exact clone of the recursive Array and Hash contents.
391
- #
392
- # * *Args* :
393
- #
394
- # * *Returns* :
395
- # - Recursive Array/Hash cloned.
396
- # * *Raises* :
397
- # Nothing
398
- #
399
- # examples:
400
- # hdata = { :test => { :test2 => { :test5 => :test,
401
- # 'text' => 'blabla' },
402
- # 'test5' => 'test' },
403
- # :array => [{ :test => :value1 }, 2, { :test => :value3 }]}
404
- #
405
- # hclone = hdata.rh_clone
406
- # hclone[:test] = "test"
407
- # hdata[:test] == { :test2 => { :test5 => :test,'text' => 'blabla' }
408
- # # => true
409
- # hclone[:array].pop
410
- # hdata[:array].length != hclone[:array].length
411
- # # => true
412
- # hclone[:array][0][:test] = "value2"
413
- # hdata[:array][0][:test] != hclone[:array][0][:test]
414
- # # => true
415
- def rh_clone
416
- result = []
417
- each do |value|
418
- begin
419
- result << value.rh_clone
420
- rescue
421
- result << value
422
- end
423
- end
424
- result
425
- end
426
- end
@@ -1,282 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
-
18
- # require 'byebug'
19
-
20
- $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
21
-
22
- require 'rh'
23
-
24
- describe 'Recursive Hash/Array extension,' do
25
- context "With { :test => {:test2 => 'value1', :test3 => 'value2'},"\
26
- ":test4 => 'value3'}" do
27
- before(:all) do
28
- @hdata = { :test => { :test2 => 'value1', :test3 => 'value2' },
29
- :test4 => 'value3' }
30
- end
31
- it 'rh_lexist?(:test) return 1' do
32
- expect(@hdata.rh_lexist?(:test)).to eq(1)
33
- end
34
-
35
- it 'rh_lexist?(:test5) return 0' do
36
- expect(@hdata.rh_lexist?(:test5)).to eq(0)
37
- end
38
-
39
- it 'rh_lexist?(:test, :test2) return 2' do
40
- expect(@hdata.rh_lexist?(:test, :test2)).to eq(2)
41
- end
42
-
43
- it 'rh_lexist?(:test, :test2, :test5) return 2' do
44
- expect(@hdata.rh_lexist?(:test, :test2, :test5)).to eq(2)
45
- end
46
-
47
- it 'rh_lexist?(:test, :test5 ) return 1' do
48
- expect(@hdata.rh_lexist?(:test, :test5)).to eq(1)
49
- end
50
-
51
- it 'rh_lexist? return 0' do
52
- expect(@hdata.rh_lexist?).to eq(0)
53
- end
54
- end
55
-
56
- context "With { :test => {:test2 => 'value1', :test3 => 'value2'},"\
57
- ":test4 => 'value3'}" do
58
- before(:all) do
59
- @hdata = { :test => { :test2 => 'value1', :test3 => 'value2' },
60
- :test4 => 'value3' }
61
- end
62
- it 'rh_exist?(:test) return true' do
63
- expect(@hdata.rh_exist?(:test)).to equal(true)
64
- end
65
-
66
- it 'rh_exist?(:test5) return false' do
67
- expect(@hdata.rh_exist?(:test5)).to equal(false)
68
- end
69
-
70
- it 'rh_exist?(:test, :test2) return true' do
71
- expect(@hdata.rh_exist?(:test, :test2)).to equal(true)
72
- end
73
-
74
- it 'rh_exist?(:test, :test2, :test5) return false' do
75
- expect(@hdata.rh_exist?(:test, :test2, :test5)).to equal(false)
76
- end
77
-
78
- it 'rh_exist?(:test, :test5 ) return false' do
79
- expect(@hdata.rh_exist?(:test, :test5)).to equal(false)
80
- end
81
-
82
- it 'rh_exist? return nil' do
83
- expect(@hdata.rh_exist?).to eq(nil)
84
- end
85
- end
86
-
87
- context "With { :test => {:test2 => 'value1', :test3 => 'value2'},"\
88
- ":test4 => 'value3'}" do
89
- before(:all) do
90
- @hdata = { :test => { :test2 => 'value1',
91
- :test3 => 'value2' },
92
- :test4 => 'value3' }
93
- end
94
- it "rh_get(:test) return {:test2 => 'value1', :test3 => 'value2'}" do
95
- expect(@hdata.rh_get(:test)).to eq(:test2 => 'value1',
96
- :test3 => 'value2')
97
- end
98
-
99
- it 'rh_get(:test5) return nil' do
100
- expect(@hdata.rh_get(:test5)).to equal(nil)
101
- end
102
-
103
- it "rh_get(:test, :test2) return 'value1'" do
104
- expect(@hdata.rh_get(:test, :test2)).to eq('value1')
105
- end
106
-
107
- it 'rh_get(:test, :test2, :test5) return nil' do
108
- expect(@hdata.rh_get(:test, :test2, :test5)).to equal(nil)
109
- end
110
-
111
- it 'rh_get(:test, :test5) return nil' do
112
- expect(@hdata.rh_get(:test, :test5)).to equal(nil)
113
- end
114
-
115
- it 'rh_get return original data' do
116
- expect(@hdata.rh_get).to eq(:test => { :test2 => 'value1',
117
- :test3 => 'value2' },
118
- :test4 => 'value3')
119
- end
120
- end
121
-
122
- context 'With hdata = {}' do
123
- before(:all) do
124
- @hdata = {}
125
- end
126
- it 'rh_set(:test) return nil, with no change to hdata.' do
127
- expect(@hdata.rh_set(:test)).to equal(nil)
128
- expect(@hdata).to eq({})
129
- end
130
-
131
- it 'rh_set(:test, :test2) add a new element :test2 => :test' do
132
- expect(@hdata.rh_set(:test, :test2)).to eq(:test)
133
- expect(@hdata).to eq(:test2 => :test)
134
- end
135
-
136
- it 'rh_set(:test, :test2, :test5) replace :test2 by :test5 => :test' do
137
- expect(@hdata.rh_set(:test, :test2, :test5)).to eq(:test)
138
- expect(@hdata).to eq(:test2 => { :test5 => :test })
139
- end
140
-
141
- it 'rh_set(:test, :test5 ) add :test5 => :test, colocated with :test2' do
142
- expect(@hdata.rh_set(:test, :test5)).to equal(:test)
143
- expect(@hdata).to eq(:test2 => { :test5 => :test },
144
- :test5 => :test)
145
- end
146
-
147
- it "rh_set('blabla', :test2, 'text') add a 'test' => 'blabla' under"\
148
- ' :test2, colocated with ẗest5 ' do
149
- expect(@hdata.rh_set('blabla', :test2, 'text')).to eq('blabla')
150
- expect(@hdata).to eq(:test2 => { :test5 => :test,
151
- 'text' => 'blabla' },
152
- :test5 => :test)
153
- end
154
-
155
- it 'rh_set(nil, :test2) remove :test2 value' do
156
- expect(@hdata.rh_set(nil, :test2)).to equal(nil)
157
- expect(@hdata).to eq(:test2 => nil,
158
- :test5 => :test)
159
- end
160
- end
161
-
162
- context 'With hdata = {:test2 => { :test5 => :test,'\
163
- "'text' => 'blabla' },"\
164
- ':test5 => :test}' do
165
- before(:all) do
166
- @hdata = { :test2 => { :test5 => :test,
167
- 'text' => 'blabla' },
168
- :test5 => :test }
169
- end
170
- it 'rh_del(:test) return nil, with no change to hdata.' do
171
- expect(@hdata.rh_del(:test)).to equal(nil)
172
- expect(@hdata).to eq(:test2 => { :test5 => :test,
173
- 'text' => 'blabla' },
174
- :test5 => :test)
175
- end
176
-
177
- it 'rh_del(:test, :test2) return nil, with no change to hdata.' do
178
- expect(@hdata.rh_del(:test, :test2)).to eq(nil)
179
- expect(@hdata).to eq(:test2 => { :test5 => :test,
180
- 'text' => 'blabla' },
181
- :test5 => :test)
182
- end
183
-
184
- it 'rh_del(:test2, :test5) remove :test5 keys tree from :test2' do
185
- expect(@hdata.rh_del(:test2, :test5)).to eq(:test)
186
- expect(@hdata).to eq(:test2 => { 'text' => 'blabla' },
187
- :test5 => :test)
188
- end
189
-
190
- it 'rh_del(:test5 ) remove :test5' do
191
- expect(@hdata.rh_del(:test5)).to equal(:test)
192
- expect(@hdata).to eq(:test2 => { 'text' => 'blabla' })
193
- end
194
-
195
- it 'rh_del(:test2) remove the :test2. hdata is now {}.'\
196
- ' :test2, colocated with ẗest5 ' do
197
- expect(@hdata.rh_del(:test2)).to eq('text' => 'blabla')
198
- expect(@hdata).to eq({})
199
- end
200
- end
201
-
202
- context "With hdata = { :test => { :test2 => { :test5 => :test,\n"\
203
- " 'text' => 'blabla' },\n"\
204
- " 'test5' => 'test' },\n"\
205
- ' :array => [{ :test => :value1 }, '\
206
- '2, { :test => :value3 }]}' do
207
- before(:all) do
208
- @hdata = { :test => { :test2 => { :test5 => :test,
209
- 'text' => 'blabla' },
210
- 'test5' => 'test' },
211
- :array => [{ :test => :value1 }, 2, { :test => :value3 }]
212
- }
213
- end
214
- it 'rh_clone is done without error' do
215
- expect { @hdata.rh_clone }.to_not raise_error
216
- end
217
- it 'hclone[:test] = "test" => hdata[:test] != hclone[:test]' do
218
- hclone = @hdata.rh_clone
219
- hclone[:test] = 'test'
220
- expect(@hdata[:test]).to eq(:test2 => { :test5 => :test,
221
- 'text' => 'blabla' },
222
- 'test5' => 'test')
223
- end
224
- it 'hclone[:array].pop => hdata[:array].length != hclone[:array].length' do
225
- hclone = @hdata.rh_clone
226
- hclone[:array].pop
227
- expect(@hdata[:array].length).not_to eq(hclone[:array].length)
228
- end
229
-
230
- it 'hclone[:array][0][:test] = "value2" '\
231
- '=> hdata[:array][0][:test] != hclone[:array][0][:test]' do
232
- hclone = @hdata.rh_clone
233
- hclone[:array][0][:test] = 'value2'
234
- expect(@hdata[:array][0][:test]).to eq(:value1)
235
- end
236
- end
237
-
238
- context 'With hdata = { :test => { :test2 => { :test5 => :test,'\
239
- "'text' => 'blabla' },"\
240
- "'test5' => 'test' }}" do
241
- before(:all) do
242
- @hdata = { :test => { :test2 => { :test5 => :test,
243
- 'text' => 'blabla' },
244
- 'test5' => 'test' } }
245
- end
246
- it 'rh_key_to_symbol?(1) return false' do
247
- expect(@hdata.rh_key_to_symbol?(1)).to equal(false)
248
- end
249
- it 'rh_key_to_symbol?(2) return true' do
250
- expect(@hdata.rh_key_to_symbol?(2)).to equal(true)
251
- end
252
- it 'rh_key_to_symbol?(3) return true' do
253
- expect(@hdata.rh_key_to_symbol?(3)).to equal(true)
254
- end
255
- it 'rh_key_to_symbol?(4) return true' do
256
- expect(@hdata.rh_key_to_symbol?(4)).to equal(true)
257
- end
258
-
259
- it 'rh_key_to_symbol(1) return no diff' do
260
- expect(@hdata.rh_key_to_symbol(1)
261
- ).to eq(:test => { :test2 => { :test5 => :test,
262
- 'text' => 'blabla' },
263
- 'test5' => 'test' })
264
- end
265
- it 'rh_key_to_symbol(2) return "test5" is replaced by :ẗest5' do
266
- expect(@hdata.rh_key_to_symbol(2)
267
- ).to eq(:test => { :test2 => { :test5 => :test,
268
- 'text' => 'blabla' },
269
- :test5 => 'test' })
270
- end
271
- it 'rh_key_to_symbol(3) return "test5" replaced by :ẗest5, '\
272
- 'and "text" to :text' do
273
- expect(@hdata.rh_key_to_symbol(3)
274
- ).to eq(:test => { :test2 => { :test5 => :test,
275
- :text => 'blabla' },
276
- :test5 => 'test' })
277
- end
278
- it 'rh_key_to_symbol(4) same like rh_key_to_symbol(3)' do
279
- expect(@hdata.rh_key_to_symbol(4)).to eq(@hdata.rh_key_to_symbol(3))
280
- end
281
- end
282
- end