Skip to content

Add a safe way to load ruby dependencies #250

@DavidS

Description

@DavidS

Use Case

Providers often would like to access external dependencies (gems, or code from another module) to ease development. Using a unguarded require causes rather unhelpful exceptions when the dependency is not available, and even if augmented by a more helpful error message, can cause widespread disruption (see FM-8643 for an example).

Describe the Solution You Would Like

Allow the type to specify a (optional) list of ruby requires that are necessary for the provider to function:

Puppet::ResourceApi.register_type(
  name: 'complex_thing',
  gem_require: [
    { gem: 'net-connect', version: '~> 1.0', },
    { gem: 'api-sdk', version: '~> 2.0', },
  ],
  ruby_require: [ 'net/connect/mode', 'api/sdkv2' ],

The Resource API would then make sure that the gems in the correct version are available or provide a helpful error message of what is necessary to continue:

Error: `complex_thing` requires `net-connect` matching `~> 1.0`, but it is not installed.
Error: `complex_thing` requires `api-sdk` matching `~> 2.0`, but version `3.5.1` is installed.
Error: `complex_thing` requires ruby file `net/connect/mode`, but loading it failed with `cannot load such file -- net/connect/mode`

Describe Alternatives You've Considered

See FM-8643 for a in-depth discussion of alternatives.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions