Module: VundleCli::Helpers

Defined in:
lib/vundle_cli/helpers.rb

Class Method Summary collapse

Class Method Details

.file_validate(fpath, check_dir = false) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vundle_cli/helpers.rb', line 5

def file_validate(fpath, check_dir = false)
  fpath = File.expand_path(fpath)

  unless File.exist?(fpath)
    raise ArgumentError.new("#{fpath} does not exist")
  end

  fpath = File.readlink(fpath) if File.symlink?(fpath)

  if check_dir
    unless File.directory?(fpath)
      raise ArgumentError.new("#{fpath} is not a directory")
    end
  else
    unless File.file?(fpath)
      raise ArgumentError.new("#{fpath} is not a valid file")
    end
  end

  fpath
end