yml_merger 0.9.0 → 0.9.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 +18 -10
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53bab445865ad2f7414909d6d5d06c94b077de30
4
- data.tar.gz: bbde43c5fe4e037f2711e18c652a2b27823fa4dc
3
+ metadata.gz: 49e76145d789966d34bccbca72e2e6a7dc1a5e03
4
+ data.tar.gz: b31dac2229ba5d425c31c66f958337446bd7fbdd
5
5
  SHA512:
6
- metadata.gz: b9177063653202da7147bf8068f19ff1b3d6f063de2e0392bba467b1e3abe9796047d643abff33c1f9cea7b9d56cb2c34494d9013e7d602fa1bc88dbb3238d9a
7
- data.tar.gz: 7e8936d1301086d2cb9b0396a79a4a60e8036f2ba66e6ee8b056f9f2a11b9c3decdf7b75cb0e024996d9d05cd96b1a1bf1236eafb940c6aa8431fad7c18837da
6
+ metadata.gz: b95b020415c2f0e2a4f95ae4d9aa002aaa1c0a180a84f2741d6e47df9496da78164dbc90c34766a8c9e9fa553cf107012832f60e62381cbc67f6d5be4707d712
7
+ data.tar.gz: 1b7ab34abc0f7090f5083b545cae32a321b99ff646e44b0875945e208c107bddb194531fb0363d055ff7985a64316b04c9184a41e992e6d8c8595b1de0bf6be5
data/lib/yml_merger.rb CHANGED
@@ -4,6 +4,7 @@ require "deep_merge"
4
4
  require 'fileutils'
5
5
  require 'open-uri'
6
6
  require 'uri'
7
+ require 'logger'
7
8
 
8
9
 
9
10
  # implement of deep merge for nested hash and array of hash
@@ -14,7 +15,12 @@ class YML_Merger
14
15
  # Params:
15
16
  # - filepath: the entry file name
16
17
  # - seatch_paths: rootpath to search all the needed YML files
17
- def initialize(filename, search_paths)
18
+ def initialize(filename, search_paths, logger: nil)
19
+ @logger = logger
20
+ unless (logger)
21
+ @logger = Logger.new(STDOUT)
22
+ @logger.level = Logger::INFO
23
+ end
18
24
  @ENTRY_YML = search_paths + '/' + filename
19
25
  @search_paths = search_paths
20
26
  @filestructure = Hash.new()
@@ -49,14 +55,14 @@ class YML_Merger
49
55
  if struct.key?("mode") and struct["mode"] == "post-process-lib"
50
56
  if struct[key].has_key?("attribute")
51
57
  if struct[key]["attribute"] == "required"
52
- #puts "keep #{key}"
58
+ @logger.debug "keep #{key}"
53
59
  else
54
60
  struct.delete(key)
55
- #puts "deletes #{key}"
61
+ @logger.debug "deletes #{key}"
56
62
  next
57
63
  end
58
64
  else
59
- #puts "delete #{key}"
65
+ @logger.debug "delete #{key}"
60
66
  struct.delete(key)
61
67
  next
62
68
  end
@@ -64,21 +70,21 @@ class YML_Merger
64
70
  if struct[key].key?("mode") and struct[key]["mode"] == "post-process-app"
65
71
  if struct[key].has_key?("attribute")
66
72
  if struct[key]["attribute"] == "required"
67
- #puts "keep #{key}"
73
+ @logger.debug "keep #{key}"
68
74
  else
69
75
  struct.delete(key)
70
- #puts "deletes #{key}"
76
+ @logger.debug "deletes #{key}"
71
77
  next
72
78
  end
73
79
  else
74
- #puts "delete #{key}"
80
+ @logger.debug "delete #{key}"
75
81
  struct.delete(key)
76
82
  next
77
83
  end
78
84
  end
79
85
  if struct[key].key?("mode") and struct[key]["mode"] == "pre-process-merge"
80
86
  struct.delete(key)
81
- #puts "deletes #{key}"
87
+ @logger.debug "deletes #{key}"
82
88
  next
83
89
  end
84
90
  post_process(struct[key])
@@ -97,7 +103,7 @@ class YML_Merger
97
103
  #if not loaded,push to stack
98
104
  @filestack.push(file)
99
105
  #add globals.yml before load file
100
- #puts file
106
+ @logger.info file
101
107
  content = open(file.gsub("\\","/")){|f| f.read}
102
108
  content = YAML::load(content)
103
109
  return if content.class == FalseClass
@@ -134,7 +140,7 @@ class YML_Merger
134
140
  if struct[key]['attribute'] == "required"
135
141
  struct[key].each_key do |subkey|
136
142
  if struct.has_key?(subkey) and struct[subkey].class == Hash
137
- #puts "pre process #{key} -> #{subkey}"
143
+ @logger.debug "pre process #{key} -> #{subkey}"
138
144
  struct[subkey] = struct[subkey].deep_merge(deep_copy(struct[key][subkey]))
139
145
  #struct[subkey] = struct[subkey].deep_merge(struct[key][subkey])
140
146
  #puts struct[subkey].to_yaml
@@ -204,6 +210,7 @@ class YML_Merger
204
210
  # - addon: the key that idetify the addon module
205
211
  def deep_add_merge(struct, subnode, addon)
206
212
  return if Hash != struct.class
213
+ return if struct[addon].nil?
207
214
  if struct[addon]['__add__'].nil?
208
215
  #we do not want the addon module to change the status
209
216
  struct[addon]['attribute'] = ""
@@ -232,6 +239,7 @@ class YML_Merger
232
239
  return if Hash != struct.class
233
240
  struct.each_key do |subnode|
234
241
  next if @KEY_LIST.include?(subnode)
242
+ next if struct[subnode].nil?
235
243
  if struct[subnode]['__add__'] != nil
236
244
  struct[subnode]['__add__'].each do |addon|
237
245
  next if struct[addon].class != Hash
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: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hake Huang