Module: Resources

Defined in:
lib/resources/path_helper.rb

Overview

The Resources module manages and provides access to file system paths used by a script or application.

It facilitates the definition and retrieval of a default library path, alongside a customizable path that can be set at runtime either programmatically using the Resources.define method or through the environment variable "SCRIPT_CUSTOM_RESOURCES".

This flexibility allows applications to dynamically access resources stored in various locations, depending on execution environment or user-defined settings.

Class Method Summary collapse

Class Method Details

.custom_pathString?

Returns the custom path for resources as defined by the user. This path can be set at runtime through the use of the environment variable "SCRIPT_CUSTOM_RESOURCES" or programmatically via the define method. This method allows for easy retrieval of the custom path, facilitating flexible resource management.

Returns:

  • (String, nil)

    the custom path as defined by the environment variable, or nil if it hasn't been set.



25
26
27
# File 'lib/resources/path_helper.rb', line 25

def self.custom_path
  ENV['SCRIPT_CUSTOM_RESOURCES']
end

.define(custom_path:) ⇒ void

This method returns an undefined value.

Provides a means to programmatically define a custom resources path at runtime. This method updates the "SCRIPT_CUSTOM_RESOURCES" environment variable to store the custom path, making it retrievable through the custom_path method. This allows for dynamic setting of resource paths based on runtime conditions or user preferences.

Parameters:

  • custom_path (String)

    the custom path to be set for resource access.



36
37
38
# File 'lib/resources/path_helper.rb', line 36

def self.define(custom_path:)
  ENV['SCRIPT_CUSTOM_RESOURCES'] = custom_path
end

.library_pathString

Retrieves the path to the directory containing this module, which serves as the default library path.

Returns:

  • (String)

    the directory path of this module, used as the default library path.



15
16
17
# File 'lib/resources/path_helper.rb', line 15

def self.library_path
  __dir__
end