Class: RubynCode::Tools::BundleAdd

Inherits:
Base
  • Object
show all
Defined in:
lib/rubyn_code/tools/bundle_add.rb

Constant Summary collapse

TOOL_NAME =
'bundle_add'
DESCRIPTION =
'Adds a gem to the Gemfile and installs it via `bundle add`.'
PARAMETERS =
{
  gem_name: { type: :string, required: true, description: 'Name of the gem to add' },
  version: { type: :string, required: false, description: "Version constraint (e.g. '~> 1.0')" },
  group: { type: :string, required: false, description: "Gemfile group (e.g. 'development', 'test')" }
}.freeze
RISK_LEVEL =
:execute
REQUIRES_CONFIRMATION =
false

Instance Attribute Summary

Attributes inherited from Base

#project_root

Instance Method Summary collapse

Methods inherited from Base

description, #initialize, parameters, requires_confirmation?, risk_level, #safe_path, summarize, to_schema, tool_name, #truncate

Constructor Details

This class inherits a constructor from RubynCode::Tools::Base

Instance Method Details

#execute(gem_name:, version: nil, group: nil) ⇒ Object

Raises:



20
21
22
23
24
25
26
27
28
29
# File 'lib/rubyn_code/tools/bundle_add.rb', line 20

def execute(gem_name:, version: nil, group: nil)
  gemfile_path = File.join(project_root, 'Gemfile')

  raise Error, 'No Gemfile found in project root. Cannot run bundle add.' unless File.exist?(gemfile_path)

  command = build_command(gem_name, version, group)
  stdout, stderr, status = safe_capture3(command, chdir: project_root)

  build_output(stdout, stderr, status)
end