Class: Bundler::GemBytes::ScriptExecutor

Inherits:
Thor::Group
  • Object
show all
Includes:
Actions, Thor::Actions
Defined in:
lib/bundler/gem_bytes/script_executor.rb

Overview

Responsible for executing scripts using Thor and GemBytes actions

This class enables the execution of scripts from a file or URI, integrating with ‘Thor::Actions` to allow advanced file manipulation and action chaining. This can be particularly useful for tasks like creating or modifying files, managing dependencies, and implementing workflows for gem development.

Examples:

Executing a script from a file or URI

executor = Bundler::GemBytes::ScriptExecutor.new
executor.execute('path_or_uri_to_script')

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Actions

#gemspec

Class Method Details

.source_pathsArray<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Sets the source paths for ‘Thor::Actions`

This determines where action scripts will be sourced from.

By default, the source path is set to the current working directory, which allows scripts to access files from the local file system during execution.

Returns:

  • (Array<String>)

    the list of source paths



33
34
35
# File 'lib/bundler/gem_bytes/script_executor.rb', line 33

def self.source_paths
  [Dir.pwd]
end

Instance Method Details

#execute(path_or_uri) ⇒ void

This method returns an undefined value.

Executes a script from a given URI or file path

This method loads the script located at the specified ‘path_or_uri` and executes it within the context of this class which includes `Thor::Actions` and `Bundler::GemBytes::ScriptExecutor`. This allows the script to perform tasks such as modifying files, creating directories, and other common file system operations.

Examples:

Execute a script from a path

execute('path/to/script.rb')

Parameters:

  • path_or_uri (String)

    the URI or file path to the script

Raises:

  • (RuntimeError)

    if the script cannot be loaded



54
55
56
57
58
# File 'lib/bundler/gem_bytes/script_executor.rb', line 54

def execute(path_or_uri)
  apply(path_or_uri)
rescue StandardError => e
  raise "Failed to execute script from #{path_or_uri}: #{e.message}"
end