Class: Appydave::Tools::Jump::PathValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/appydave/tools/jump/path_validator.rb

Overview

PathValidator checks if filesystem paths exist

This class is designed for dependency injection in tests. Production code uses the real filesystem, while tests inject a mock that returns predetermined results.

Examples:

Production usage

validator = PathValidator.new
validator.exists?('~/dev/project')  # => true/false based on real filesystem

Test usage (see spec/support/jump_test_helpers.rb)

validator = TestPathValidator.new(valid_paths: ['~/dev/project'])
validator.exists?('~/dev/project')  # => true
validator.exists?('~/dev/other')    # => false

Instance Method Summary collapse

Instance Method Details

#exists?(path) ⇒ Boolean

Check if a path exists as a directory

Parameters:

  • path (String)

    Path to check (supports ~ expansion)

Returns:

  • (Boolean)

    true if directory exists



25
26
27
# File 'lib/appydave/tools/jump/path_validator.rb', line 25

def exists?(path)
  File.directory?(expand(path))
end

#expand(path) ⇒ String

Expand a path (resolve ~ and relative paths)

Parameters:

  • path (String)

    Path to expand

Returns:

  • (String)

    Absolute path



41
42
43
# File 'lib/appydave/tools/jump/path_validator.rb', line 41

def expand(path)
  File.expand_path(path)
end

#file_exists?(path) ⇒ Boolean

Check if a path exists as a file

Parameters:

  • path (String)

    Path to check (supports ~ expansion)

Returns:

  • (Boolean)

    true if file exists



33
34
35
# File 'lib/appydave/tools/jump/path_validator.rb', line 33

def file_exists?(path)
  File.exist?(expand(path))
end