Class: Katello::HashUtil

Inherits:
Object
  • Object
show all
Defined in:
app/models/katello/hash_util.rb

Instance Method Summary collapse

Instance Method Details

#null_safe_get(hash, default, params) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/katello/hash_util.rb', line 3

def null_safe_get(hash, default, params)
  # Base case .. if we are down to the last param
  # lets actually try and find the value
  if params.size == 1
    begin
      # If we got back null lets assign the default
      return hash[params[0]] || default
    rescue
      # If we errored out trying to fetch the value we return
      # default value.
      return default
    end
  end
  subhash = hash[params.first]
  # If we don't have a subhash don't try and recurse down
  if !subhash.nil? && !subhash.empty?
    self.null_safe_get(subhash, default, params[1..-1])
  else
    default
  end
end