Module: Capistrano::DataPlaneApi::Diggable

Includes:
Kernel
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

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.

Signature:

  • (*untyped) -> untyped

Raises:

  • (TypeError)

    value has no #dig method



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