Module: Plumbum::Consumers::InstanceMethods

Included in:
Plumbum::Consumer, ScopedConsumer
Defined in:
lib/plumbum/consumers/instance_methods.rb

Overview

Instance methods for defining the Consumer interface.

Instance Method Summary collapse

Instance Method Details

#get_plumbum_dependency(key, optional: false) ⇒ Object

Retrieves the dependency with the specified key.

Parameters:

  • key (String, Symbol)

    the key for the requested dependency.

  • optional (true, false) (defaults to: false)

    if true, returns nil if the dependency is not defined. Defaults to false.

Returns:

  • (Object)

    the dependency value.

Raises:



24
25
26
27
28
29
30
31
32
33
# File 'lib/plumbum/consumers/instance_methods.rb', line 24

def get_plumbum_dependency(key, optional: false)
  SleepingKingStudios::Tools::Toolbelt
    .instance
    .assertions
    .validate_name(key, as: :key)

  find_plumbum_dependency(key) do
    handle_missing_plumbum_dependency(key, optional:)
  end
end

#has_plumbum_dependency?(key) ⇒ true, false

Checks if the dependency with the given key is defined.

Parameters:

  • key (String, Symbol)

    the key for the requested dependency.

Returns:

  • (true, false)

    true if the dependency is defined, otherwise false.

Raises:

  • (ArgumentError)

    if the key is not a String or Symbol, or is empty.



42
43
44
45
46
47
48
49
50
51
# File 'lib/plumbum/consumers/instance_methods.rb', line 42

def has_plumbum_dependency?(key) # rubocop:disable Naming/PredicatePrefix
  SleepingKingStudios::Tools::Toolbelt
    .instance
    .assertions
    .validate_name(key, as: :key)

  find_plumbum_dependency(key) { return false }

  true
end