Class: Appydave::Tools::Jump::Commands::Update

Inherits:
Base
  • Object
show all
Defined in:
lib/appydave/tools/jump/commands/update.rb

Overview

Update command modifies an existing location entry

Instance Attribute Summary collapse

Attributes inherited from Base

#config, #options, #path_validator

Instance Method Summary collapse

Constructor Details

#initialize(config, key, attrs, path_validator: PathValidator.new, **options) ⇒ Update

Returns a new instance of Update.



11
12
13
14
15
# File 'lib/appydave/tools/jump/commands/update.rb', line 11

def initialize(config, key, attrs, path_validator: PathValidator.new, **options)
  super(config, path_validator: path_validator, **options)
  @key = key
  @attrs = attrs
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



9
10
11
# File 'lib/appydave/tools/jump/commands/update.rb', line 9

def attrs
  @attrs
end

#keyObject (readonly)

Returns the value of attribute key.



9
10
11
# File 'lib/appydave/tools/jump/commands/update.rb', line 9

def key
  @key
end

Instance Method Details

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/appydave/tools/jump/commands/update.rb', line 17

def run
  # Validate key exists
  return error_result("Location '#{key}' not found", code: 'NOT_FOUND') unless config.key_exists?(key)

  # Validate path if provided
  @path_warning = "Warning: Path '#{attrs[:path]}' does not exist" if attrs[:path] && !path_validator.exists?(attrs[:path])

  # Update
  config.update(key, attrs)
  config.save

  updated = config.find(key)
  result = success_result(
    message: "Location '#{key}' updated successfully",
    location: updated.to_h
  )
  result[:warning] = @path_warning if @path_warning
  result
rescue ArgumentError => e
  error_result(e.message, code: 'INVALID_INPUT')
end