Module: Capistrano::DataPlaneApi::Diggable
- Included in:
- Type
- Defined in:
- lib/capistrano/data_plane_api/diggable.rb
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 ‘dig` at each step, returning `nil` if any intermediate step is `nil`.
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.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/capistrano/data_plane_api/diggable.rb', line 15 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.size.zero? raise ::TypeError, "#{value.class} does not have #dig method" unless value.respond_to?(:dig) value.dig(*args) rescue ::ArgumentError nil end |