Module: DevSuite::Utils::DependencyLoader

Defined in:
lib/dev_suite/utils/dependency_loader.rb

Class Method Summary collapse

Class Method Details

.gem_installed?(gem_name) ⇒ Boolean

Check if a gem is installed by attempting to require it.

Parameters:

  • gem_name (String)

    The name of the gem to check.

Returns:

  • (Boolean)

    true if the gem is installed, false otherwise.



28
29
30
31
32
33
# File 'lib/dev_suite/utils/dependency_loader.rb', line 28

def gem_installed?(gem_name)
  require gem_name
  true
rescue LoadError
  false
end

.safe_load_dependencies(dependencies = [], on_failure: method(:default_failure_handler)) { ... } ⇒ Object

Public method to safely load multiple dependencies. Executes the given block if all dependencies are successfully loaded. Calls the on_failure handler with the list of missing dependencies if any are not found.

Parameters:

  • dependencies (Array<String>) (defaults to: [])

    List of gem names to load.

  • on_failure (Proc) (defaults to: method(:default_failure_handler))

    Handler to call with missing dependencies if any are not found.

Yields:

  • Executes the block if all dependencies are loaded.



14
15
16
17
18
19
20
21
22
# File 'lib/dev_suite/utils/dependency_loader.rb', line 14

def safe_load_dependencies(dependencies = [], on_failure: method(:default_failure_handler))
  missing_dependencies = find_missing_dependencies(dependencies)

  if missing_dependencies.empty?
    yield if block_given?
  else
    on_failure.call(missing_dependencies)
  end
end