class Siba::SibaFile

Constants

DIR_REGEXP
FILE_REGEXP
FILE_UTILS_REGEXP

Public Class Methods

get_file_class(meth) click to toggle source
# File lib/siba/siba_file.rb, line 17
def self.get_file_class(meth)
  case meth
  when FILE_UTILS_REGEXP
    return FileUtils, meth.to_s.gsub(FILE_UTILS_REGEXP, "")
  when DIR_REGEXP
    return Dir, meth.to_s.gsub(DIR_REGEXP, "")
  when FILE_REGEXP
    return File, meth.to_s.gsub(FILE_REGEXP, "")
  end
end

Public Instance Methods

file_expand_path(file_name, dir_string=nil) click to toggle source
# File lib/siba/siba_file.rb, line 45
def file_expand_path(file_name, dir_string=nil)
  file_utils_cd Siba.current_dir unless Siba.current_dir.nil?
  File.expand_path file_name, dir_string
end
method_missing(meth, *args, &block) click to toggle source
Calls superclass method
# File lib/siba/siba_file.rb, line 28
def method_missing(meth, *args, &block)
  file_class, class_meth = SibaFile.get_file_class meth
  if file_class
    file_class.send(class_meth, *args, &block)
  else
    super
  end
end
respond_to?(meth) click to toggle source
Calls superclass method
# File lib/siba/siba_file.rb, line 37
def respond_to?(meth)
  if SibaFile.get_file_class meth
    true
  else
    super
  end
end
run_shell(command, fail_message=nil) click to toggle source

Runs shell command and raises error if it fails returns output (both stdout and stderr)

# File lib/siba/siba_file.rb, line 52
    def run_shell(command, fail_message=nil)
      strout, status = Open3.capture2e command
      raise strout if status.to_i != 0
      return strout
    rescue Exception => ex
      fail_message ||= "Failed to run the command: #{command}"
      raise Siba::Error, "#{fail_message}
#{ex.message}"
    end
run_this(name="noname") { || ... } click to toggle source
# File lib/siba/siba_file.rb, line 9
def run_this(name="noname")
  yield
end
shell_ok?(command) click to toggle source

Runs the shell command. Works the same way as Kernel.system method but without showing the output. Returns true if it was successfull.

# File lib/siba/siba_file.rb, line 65
def shell_ok?(command)
  # Using Open3 instead of `` or system("cmd") in order to hide stderr output
  sout, status = Open3.capture2e command
  return status.to_i == 0
rescue
  return false
end