Module: Capistrano::DataPlaneApi::Diggable
Overview
Include in a class to grant it the #dig method.
It's implemented so that it calls public methods.
Instance Method Summary collapse
-
#dig(*args) ⇒ Object
Extracts the nested value specified by the sequence of key objects by calling
digat each step, returningnilif any intermediate step isnil.
Instance Method Details
#dig(*args) ⇒ Object
Extracts the nested value specified by the sequence of key objects by calling dig at each step,
returning nil if any intermediate step is nil.
This implementation of dig uses public_send under the hood.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/capistrano/data_plane_api/diggable.rb', line 18 def dig(*args) return unless args.size.positive? return unless respond_to?(key = args.shift) value = public_send(key) return if value.nil? return value if args.empty? raise ::TypeError, "#{value.class} does not have #dig method" unless value.respond_to?(:dig) value.dig(*args) rescue ::ArgumentError nil end |