class ExecutablePathname
Constants
- VERSION
Public Class Methods
new(path)
click to toggle source
Calls superclass method
# File lib/executable_pathname.rb, line 37 def initialize(path) super(path) @first_line = nil @shbang_paths = nil end
path_list()
click to toggle source
# File lib/executable_pathname.rb, line 29 def self.path_list @@path_list ||= ENV['PATH'].split(':') end
remote_path_list()
click to toggle source
# File lib/executable_pathname.rb, line 33 def self.remote_path_list (ENV['REMOTE_PATH'] || '/bin:/usr/bin:/usr/local/bin').split(':') end
valid_executable?(name)
click to toggle source
Define the envar REMOTE_PATH as the colon-separated list of well-known directory paths that will be referenced on remote hosts. The default is '/bin:/usr/bin:/usr/local/bin'
# File lib/executable_pathname.rb, line 15 def self.valid_executable?(name) case name when %r{^/}, %r{.+/.+} pn = new(name) return true if pn.valid_executable? else path_list.each do |dirname| pn = new(File.join(dirname, name)) return true if pn.valid_executable? end end false end
Public Instance Methods
env_shbang?()
click to toggle source
# File lib/executable_pathname.rb, line 65 def env_shbang? shbang_paths && shbang_paths.size > 1 && shbang_paths[0].end_with?('env') end
executable_file?()
click to toggle source
# File lib/executable_pathname.rb, line 85 def executable_file? exist? && file? && executable? end
first_line()
click to toggle source
# File lib/executable_pathname.rb, line 43 def first_line @first_line ||= open { |io| line = io.gets line.chomp if line } rescue Errno::ENOENT, Errno::EACCES, IOError nil end
invalid_shbang?()
click to toggle source
# File lib/executable_pathname.rb, line 73 def invalid_shbang? shbang? && (env_shbang? ? !valid_env_shbang? : !valid_shbang_command?) end
remove_execute_permissions()
click to toggle source
# File lib/executable_pathname.rb, line 98 def remove_execute_permissions chmod(stat.mode & ~0111) end
shbang?()
click to toggle source
# File lib/executable_pathname.rb, line 52 def shbang? first_line && first_line[0..1] == '#!' end
shbang_paths()
click to toggle source
# File lib/executable_pathname.rb, line 56 def shbang_paths @shbang_paths ||= first_line && case first_line when /^#!\s*(\S+)\s+(\S+.)/ then [$1, $2.chomp] when /^#!\s*(\S+)/ then [$1.chomp] else [] end end
valid_env_shbang?()
click to toggle source
# File lib/executable_pathname.rb, line 77 def valid_env_shbang? env_shbang? && valid_shbang_command? && shbang_paths.last.split('/').size == 1 end
valid_executable?()
click to toggle source
# File lib/executable_pathname.rb, line 89 def valid_executable? exist? && executable_file? && (!shbang? || valid_shbang?) end
valid_shbang?()
click to toggle source
# File lib/executable_pathname.rb, line 69 def valid_shbang? shbang? && (env_shbang? ? valid_env_shbang? : valid_shbang_command?) end
valid_shbang_command?()
click to toggle source
# File lib/executable_pathname.rb, line 81 def valid_shbang_command? shbang_paths.size > 0 && ExecutablePathname.valid_executable?(shbang_paths[0]) end
well_known_path?()
click to toggle source
# File lib/executable_pathname.rb, line 93 def well_known_path? return false unless exist? ExecutablePathname.remote_path_list.any? {|rp| (shbang? ? shbang_paths.first : to_path).start_with?(rp)} end