Method: Webhookdb::Replicator::Column#_dig
- Defined in:
- lib/webhookdb/replicator/column.rb
#_dig(h, keys, optional) ⇒ Object
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
# File 'lib/webhookdb/replicator/column.rb', line 470 def _dig(h, keys, optional) v = h karr = Array(keys) karr.each do |key| begin v = optional ? v[key] : v.fetch(key) rescue KeyError raise KeyError, "key not found: '#{key}' in: #{v.keys}" rescue NoMethodError => e raise NoMethodError, "Element #{key} of #{karr}\n#{e}" end # allow optional nested values by returning nil as soon as key not found # the problem here is that you effectively set all keys in the sequence as optional break if optional && v.nil? end return v end |