Class: Appydave::Tools::Jump::Commands::Validate
- Defined in:
- lib/appydave/tools/jump/commands/validate.rb
Overview
Validate command checks if location paths exist
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Attributes inherited from Base
#config, #options, #path_validator
Instance Method Summary collapse
-
#initialize(config, key: nil, path_validator: PathValidator.new, **options) ⇒ Validate
constructor
A new instance of Validate.
- #run ⇒ Object
Constructor Details
#initialize(config, key: nil, path_validator: PathValidator.new, **options) ⇒ Validate
Returns a new instance of Validate.
11 12 13 14 |
# File 'lib/appydave/tools/jump/commands/validate.rb', line 11 def initialize(config, key: nil, path_validator: PathValidator.new, **) super(config, path_validator: path_validator, **) @key = key end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
9 10 11 |
# File 'lib/appydave/tools/jump/commands/validate.rb', line 9 def key @key end |
Instance Method Details
#run ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/appydave/tools/jump/commands/validate.rb', line 16 def run locations_to_validate = if key location = config.find(key) return error_result("Location '#{key}' not found", code: 'NOT_FOUND') unless location [location] else config.locations end results = locations_to_validate.map do |loc| { key: loc.key, path: loc.path, expanded_path: path_validator.(loc.path), valid: path_validator.exists?(loc.path), jump: loc.jump } end valid_count = results.count { |r| r[:valid] } invalid_count = results.count { |r| !r[:valid] } # Update validation timestamp config.touch_validated config.save success_result( count: results.size, valid_count: valid_count, invalid_count: invalid_count, results: results ) end |