Class: Appydave::Tools::Jump::Commands::Validate

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

Overview

Validate command checks if location paths exist

Instance Attribute Summary collapse

Attributes inherited from Base

#config, #options, #path_validator

Instance Method Summary collapse

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, **options)
  super(config, path_validator: path_validator, **options)
  @key = key
end

Instance Attribute Details

#keyObject (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

#runObject



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.expand(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