Class: Appydave::Tools::Jump::Commands::Update
- Defined in:
- lib/appydave/tools/jump/commands/update.rb
Overview
Update command modifies an existing location entry
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Attributes inherited from Base
#config, #options, #path_validator
Instance Method Summary collapse
-
#initialize(config, key, attrs, path_validator: PathValidator.new, **options) ⇒ Update
constructor
A new instance of Update.
- #run ⇒ Object
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, **) super(config, path_validator: path_validator, **) @key = key @attrs = attrs end |
Instance Attribute Details
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
9 10 11 |
# File 'lib/appydave/tools/jump/commands/update.rb', line 9 def attrs @attrs end |
#key ⇒ Object (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
#run ⇒ Object
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., code: 'INVALID_INPUT') end |