module R2OAS::Helpers::FileHelper

Public Instance Methods

mkdir_p_dir_or_skip(dir_path, silent = false) click to toggle source
# File lib/r2-oas/helpers/file_helper.rb, line 44
def mkdir_p_dir_or_skip(dir_path, silent = false)
  unless FileTest.exists?(dir_path)
    FileUtils.mkdir_p(dir_path)
    puts "#{space}#{bold('create')}\t#{relative(dir_path)}" unless silent
  end
end
write_file_or_skip(file_path, data, silent = false) click to toggle source
# File lib/r2-oas/helpers/file_helper.rb, line 37
def write_file_or_skip(file_path, data, silent = false)
  unless FileTest.exists?(file_path)
    File.write(file_path, data)
    puts "#{space}#{bold('create')}\t#{relative(file_path)}" unless silent
  end
end

Private Instance Methods

bold(str) click to toggle source
# File lib/r2-oas/helpers/file_helper.rb, line 59
def bold(str)
  "\e[1m#{str}\e[0m"
end
relative(path) click to toggle source
# File lib/r2-oas/helpers/file_helper.rb, line 53
def relative(path)
  current_dir_pathname = Pathname.new(Dir.pwd)
  target_path = Pathname.new(path)
  target_path.relative_path_from(current_dir_pathname)
end
space() click to toggle source
# File lib/r2-oas/helpers/file_helper.rb, line 63
def space
  '      '
end