Module: Pindo::Hashhelper

Included in:
Command::Deploy::Updateconfig, CommonConfuseProj
Defined in:
lib/pindo/base/hashhelper.rb

Instance Method Summary collapse

Instance Method Details

#deepcopy_hash(des_hash: nil, src_hash: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pindo/base/hashhelper.rb', line 10

def deepcopy_hash(des_hash:nil, src_hash:nil)

  des_hash = des_hash || {}
  if !src_hash.nil? && (src_hash.kind_of? Hash)
      src_hash.each do |key, value|
          if !value.nil? && (value.kind_of? Hash)
              des_hash[key] = {}
              deepcopy_hash(des_hash:des_hash[key], src_hash:value)
          elsif !value.nil? && (value.kind_of? Array)
              des_hash[key] = des_hash[key] || []
              des_hash[key] = des_hash[key] + value
          else
              des_hash[key] = value
          end
      end
  end
  return des_hash
end

#deepcopy_hash_struct(src_hash: nil, key_value: "") ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/pindo/base/hashhelper.rb', line 29

def deepcopy_hash_struct(src_hash:nil, key_value:"")
  des_hash = des_hash || {}
  if !src_hash.nil? && (src_hash.kind_of? Hash)
      src_hash.each do |key, value|
          if !value.nil? && (value.kind_of? Hash)
              
              des_hash[key] = deepcopy_hash_struct(src_hash:value, key_value:key_value)
          elsif !value.nil? && (value.kind_of? Array)
                des_hash[key] = []
          else
              new_value = key_value + key + "__________"
              des_hash[key] = new_value
              if key == 'module_git_url' || key == 'module_git_branch' || key == 'module_git_tag'
                des_hash[key] = ""
              end
          end
      end
  end
  return des_hash
end

#init_hash_value_wihtout_add_key(hash1: nil, hash2: nil) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/pindo/base/hashhelper.rb', line 81

def init_hash_value_wihtout_add_key(hash1:nil, hash2:nil)
  hash2 = hash2 || {}
  
  if !hash1.nil? && (hash1.kind_of? Hash)
    hash1.each do |key, value1|
        value2 = hash2[key]
        if !value1.nil? && (value1.kind_of? Hash) 
            if hash2.has_key?(key) && (value2.kind_of? Hash) 
              hash1[key] = init_hash_value_wihtout_add_key(hash1:value1, hash2:value2)
            end
        elsif !value1.nil? && (value1.kind_of? Array)
            value1 = value1 || []
            value2 = value2 || []
            hash1[key] = value1 | value2
        else
          if hash2.has_key?(key)
            hash1[key] = hash2[key]
          end
        end
    end
  end
  return hash1
end

#init_hash_value_wihtout_exludekeys(hash1: nil, hash2: nil, exlude_keys: nil) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/pindo/base/hashhelper.rb', line 105

def init_hash_value_wihtout_exludekeys(hash1:nil, hash2:nil, exlude_keys:nil)
  exlude_keys = exlude_keys || []
  hash2 = hash2 || {}
  
  if !hash1.nil? && (hash1.kind_of? Hash)
    hash1.each do |key, value1|
        value2 = hash2[key]              

        if exlude_keys.include?(key)

        elsif (value1.kind_of? Hash) 
            if hash2.has_key?(key) && (value2.kind_of? Hash) 
              hash1[key] = init_hash_value_wihtout_exludekeys(hash1:value1, hash2:value2, exlude_keys:exlude_keys)
            end
        elsif (value1.kind_of? Array)
            value1 = value1 || []
            value2 = value2 || []
            hash1[key] = value1 | value2
        else
          if hash2.has_key?(key)
            hash1[key] = hash2[key]
          end
        end
    end
  end
  return hash1
end

#minus_hash(hash1: nil, hash2: nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/pindo/base/hashhelper.rb', line 51

def minus_hash(hash1:nil, hash2:nil)
  minus_hash = {}
  hash2 = hash2 || {}
  if !hash1.nil? && (hash1.kind_of? Hash)
    hash1.each do |key, value1|
        value2 = hash2[key]
        if !value1.nil? && (value1.kind_of? Hash) 
            if !value2.nil? && (value2.kind_of? Hash) 

              valut_temp = minus_hash(hash1:value1, hash2:value2)
              if valut_temp.size > 0
                minus_hash[key] = valut_temp
              end
            end
        elsif !value1.nil? && (value1.kind_of? Array)
            value1 = value1 || []
            value2 = value2 || []
            minus_hash[key] = value1 - value2
        else

          unless hash2.has_key?(key)
            minus_hash[key] = hash1[key]
          end

        end
    end
  end
  return minus_hash
end