Module: FileTest

Defined in:
lib/ratch/support/filetest.rb

Class Method Summary collapse

Class Method Details

.bin?(fname) ⇒ Boolean

Is a file a command executable? TODO: Make more robust (Windows?)

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
# File 'lib/ratch/support/filetest.rb', line 9

def bin?(fname)
  @command_paths ||= ENV['PATH'].split(/[:;]/)
  is_bin = @command_paths.any? do |f|
    FileTest.exist?(File.join(f, fname))
  end
  #is_bin ? File.basename(fname) : false
  is_bin ? fname : false
end

.safe?(path) ⇒ Boolean

Is a path considered reasonably “safe”? TODO: Make more robust.

Returns:

  • (Boolean)


21
22
23
24
25
26
27
# File 'lib/ratch/support/filetest.rb', line 21

def safe?(path)
  case path
  when *[ '/', '/*', '/**/*' ]
    return false
  end
  true
end