yml_merger 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/yml_merger.rb +51 -47
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee8fc229ad3ece250642e1723e3897d1494bf70c
4
- data.tar.gz: 4e7d8ee189c605791c86130f7d2562dc7ef3b03b
3
+ metadata.gz: 4ec9c56347fd8ab5c728f052a0d43e5824758f20
4
+ data.tar.gz: 3db4861372aa21f35674c3d6c837a0f8d70dd6fb
5
5
  SHA512:
6
- metadata.gz: 943f1609f38ae057f30539d1be50a01fac1b5c7a0608553ba2cde890760fd21daab4a6e7da035b96461a967210644093ae7ec30e7e5bf5fd53b717cdc916f547
7
- data.tar.gz: e4b408e75ca07309ddb8a6c968f72cf65b6ca021e51a3ab38eb6960d79b90a4baaaacf25c413c9027948cf9ae8fe6313dc0ed41c026925316306cdb06559d625
6
+ metadata.gz: eb0e8c080d2c9401945734ce7d5e3e14f8056414bbdedc000c45b89568b74e6ba16cbaa1ade1d4ba8c1fe5ebe3d47288d1f038088d9bc04acc74889c7d69a0e4
7
+ data.tar.gz: 1fa5b0956da2e1b61b4782b54e62865c29e19acf84b65265fc7ec6153782ec5edebc1f850637bcfdb125cc86c7c7fd1144bdbbf81fe322c93ec90826bf207197
data/lib/yml_merger.rb CHANGED
@@ -25,7 +25,8 @@ class YML_Merger
25
25
  @search_paths = search_paths
26
26
  @filestructure = Hash.new()
27
27
  @filestack = Array.new()
28
- @KEY_LIST = ['__remove__','__load__', '__common__', '__hierarchy__', '__replace__', '__add__']
28
+ # @KEY_LIST = ['__remove__','__load__', '__common__', '__hierarchy__', '__replace__', '__add__']
29
+ @KEY_LIST = %w('__remove__', '__load__', '__common__', '__hierarchy__', '__replace__', '__add__')
29
30
  end
30
31
 
31
32
  # process the YMLs
@@ -51,44 +52,43 @@ class YML_Merger
51
52
  merge_by_replace!(struct)
52
53
  merge_by_remove!(struct)
53
54
  struct.each_key do |key|
54
- if Hash == struct[key].class
55
- if struct.key?("mode") and struct["mode"] == "post-process-lib"
56
- if struct[key].has_key?("attribute")
57
- if struct[key]["attribute"] == "required"
58
- @logger.debug "keep #{key}"
59
- else
60
- struct.delete(key)
61
- @logger.debug "deletes #{key}"
62
- next
63
- end
55
+ next if Hash != struct[key].class
56
+ if struct.key?('mode') and struct['mode'] == 'post-process-lib'
57
+ if struct[key].has_key?('attribute')
58
+ if struct[key]['attribute'] == 'required'
59
+ @logger.debug "keep #{key}"
64
60
  else
65
- @logger.debug "delete #{key}"
66
- struct.delete(key)
67
- next
61
+ struct.delete(key)
62
+ @logger.debug "deletes #{key}"
63
+ next
68
64
  end
65
+ else
66
+ @logger.debug "delete #{key}"
67
+ struct.delete(key)
68
+ next
69
69
  end
70
- if struct[key].key?("mode") and struct[key]["mode"] == "post-process-app"
71
- if struct[key].has_key?("attribute")
72
- if struct[key]["attribute"] == "required"
73
- @logger.debug "keep #{key}"
74
- else
75
- struct.delete(key)
76
- @logger.debug "deletes #{key}"
77
- next
78
- end
70
+ end
71
+ if struct[key].key?('mode') and struct[key]['mode'] == 'post-process-app'
72
+ if struct[key].has_key?('attribute')
73
+ if struct[key]['attribute'] == 'required'
74
+ @logger.debug "keep #{key}"
79
75
  else
80
- @logger.debug "delete #{key}"
81
- struct.delete(key)
82
- next
83
- end
84
- end
85
- if struct[key].key?("mode") and struct[key]["mode"] == "pre-process-merge"
86
76
  struct.delete(key)
87
77
  @logger.debug "deletes #{key}"
88
78
  next
79
+ end
80
+ else
81
+ @logger.debug "delete #{key}"
82
+ struct.delete(key)
83
+ next
89
84
  end
90
- post_process(struct[key])
91
85
  end
86
+ if struct[key].key?('mode') and struct[key]['mode'] == 'pre-process-merge'
87
+ struct.delete(key)
88
+ @logger.debug "deletes #{key}"
89
+ next
90
+ end
91
+ post_process(struct[key])
92
92
  end
93
93
  end
94
94
 
@@ -96,7 +96,7 @@ class YML_Merger
96
96
  if path =~ URI::regexp
97
97
  structure = process_file(path)
98
98
  else
99
- structure = process_file(@search_paths + path.gsub("\\","/"))
99
+ structure = process_file(@search_paths + path.tr('\\','/'))
100
100
  end
101
101
  return structure
102
102
  end
@@ -112,7 +112,7 @@ class YML_Merger
112
112
  @filestack.push(file)
113
113
  #add globals.yml before load file
114
114
  @logger.info file
115
- content = open(file.gsub("\\","/")){|f| f.read}
115
+ content = open(file.tr('\\','/')){|f| f.read}
116
116
  content = YAML::load(content)
117
117
  return if content.class == FalseClass
118
118
  #if has file dependence load it
@@ -136,7 +136,7 @@ class YML_Merger
136
136
  if loadfile =~ URI::regexp
137
137
  structure = process_file(loadfile)
138
138
  else
139
- structure = process_file(@search_paths + loadfile.gsub("\\","/"))
139
+ structure = process_file(@search_paths + loadfile.gsub('\\','/'))
140
140
  end
141
141
  end
142
142
  content = content.deep_merge(deep_copy(structure))
@@ -159,8 +159,8 @@ class YML_Merger
159
159
  return if struct.class != Hash
160
160
  struct.each_key do |key|
161
161
  next if struct[key].class != Hash
162
- if struct[key].has_key?('mode') and struct[key]['mode'] == "pre-process-merge"
163
- if struct[key]['attribute'] == "required"
162
+ if struct[key].has_key?('mode') and struct[key]['mode'] == 'pre-process-merge'
163
+ if struct[key]['attribute'] == 'required'
164
164
  struct[key].each_key do |subkey|
165
165
  if struct.has_key?(subkey) and struct[subkey].class == Hash
166
166
  @logger.debug "pre process #{key} -> #{subkey}"
@@ -243,7 +243,11 @@ class YML_Merger
243
243
  end
244
244
  #if has more addon
245
245
  if struct[addon]['__add__'].count != 0
246
- struct[addon]['__add__'].each do |submodule|
246
+ #puts "add #{addon}"
247
+ struct[addon]['attribute'] = ""
248
+ #struct[subnode] = struct[subnode].deep_merge(deep_copy(struct[addon]))
249
+ struct[addon]['attribute'] = 'required'
250
+ struct[addon]['__add__'].each do |submodule|
247
251
  deep_add_merge(struct, addon, submodule)
248
252
  end
249
253
  else
@@ -268,8 +272,8 @@ class YML_Merger
268
272
  struct[subnode]['__add__'].each do |addon|
269
273
  next if struct[addon].class != Hash
270
274
  begin
271
- next if struct[subnode]['configuration']['section-type'] != "application"
272
- if struct[addon]['configuration']['section-type'] != "component"
275
+ next if struct[subnode]['configuration']['section-type'] != 'application'
276
+ if struct[addon]['configuration']['section-type'] != 'component'
273
277
  @logger.warn "WARNING #{addon} is required as component but has not a component attribute"
274
278
  end
275
279
  rescue
@@ -288,9 +292,9 @@ class YML_Merger
288
292
  def merge_by_replace!(struct)
289
293
  return if Hash != struct.class
290
294
  #get the replace hash
291
- return if ! struct.has_key?("__replace__")
295
+ return if ! struct.has_key?('__replace__')
292
296
  temp = Hash.new
293
- temp = temp.deep_merge(deep_copy(struct["__replace__"]))
297
+ temp = temp.deep_merge(deep_copy(struct['__replace__']))
294
298
  temp.each_key do |key|
295
299
  next if ! struct.has_key?(key)
296
300
  delete_node(struct, key)
@@ -305,24 +309,24 @@ class YML_Merger
305
309
  def merge_by_remove!(struct)
306
310
  return if Hash != struct.class
307
311
  #get the replace hash
308
- return if ! struct.has_key?("__remove__")
312
+ return if ! struct.has_key?('__remove__')
309
313
  temp = Hash.new
310
- temp = temp.deep_merge(deep_copy(struct["__remove__"]))
314
+ temp = temp.deep_merge(deep_copy(struct['__remove__']))
311
315
  temp.each_key do |key|
312
316
  next if ! struct.has_key?(key)
313
- if struct["__remove__"][key] == nil
317
+ if struct['__remove__'][key] == nil
314
318
  delete_node(struct, key)
315
319
  else
316
- if struct["__remove__"][key].class == Array
320
+ if struct['__remove__'][key].class == Array
317
321
  arr = Array.new
318
- arr = deep_copy(struct["__remove__"][key])
322
+ arr = deep_copy(struct['__remove__'][key])
319
323
  arr.each do |item|
320
324
  next if ! struct[key].include?(item)
321
325
  struct[key].delete(item)
322
326
  end
323
- elsif struct["__remove__"][key].class == Hash
327
+ elsif struct['__remove__'][key].class == Hash
324
328
  hash = Hash.new
325
- hash = hash.deep_merge(deep_copy(struct["__remove__"][key]))
329
+ hash = hash.deep_merge(deep_copy(struct['__remove__'][key]))
326
330
  hash.each_key do |subkey|
327
331
  next if ! struct[key].has_key?(subkey)
328
332
  delete_node(struct[key], subkey)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yml_merger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hake Huang
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-12-20 00:00:00.000000000 Z
12
+ date: 2017-06-16 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: yaml extension for heiarchy merge
15
15
  email: hakehuang@gmail.com
@@ -38,7 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
38
38
  version: '0'
39
39
  requirements: []
40
40
  rubyforge_project:
41
- rubygems_version: 2.6.7
41
+ rubygems_version: 2.6.6
42
42
  signing_key:
43
43
  specification_version: 4
44
44
  summary: yaml_merger