module Coo::Helper::FileHunter
Public Class Methods
create_file(file_name, content)
click to toggle source
根据文件名和内容创建对应文件 @param [文件名] file_name
@param [文件内容] content
# File lib/coo/helper/file_hunter.rb, line 56 def self.create_file(file_name, content) is_success = false if file_name.to_s.empty? puts 'file_name is wrong!' else new_file = File.new(file_name, 'w') if new_file new_file.syswrite(content) new_file.close is_success = true end end is_success end
file_directory_name(file)
click to toggle source
@param [文件名, 传入 __FILE__] file @return script dir name
# File lib/coo/helper/file_hunter.rb, line 31 def self.file_directory_name(file) return File.dirname(file) end
file_name(file)
click to toggle source
@param [文件名, 传入 __FILE__] file @return script name
# File lib/coo/helper/file_hunter.rb, line 25 def self.file_name(file) return File.basename(Pathname.new(file).realpath) end
file_path(file)
click to toggle source
@param [文件名, 传入 __FILE__] file @return script path
# File lib/coo/helper/file_hunter.rb, line 19 def self.file_path(file) return Pathname.new(file).realpath end
get_file_content(file_name)
click to toggle source
获取文件内容 @param [文件名] file_name
# File lib/coo/helper/file_hunter.rb, line 37 def self.get_file_content(file_name) content = '' if file_name.to_s.empty? puts 'get_file_content file_name is wrong!' else if File.exist?(file_name) && !File.directory?(file_name) target_file = File.new(file_name, 'r') if target_file content = target_file.read target_file.close end end end content end
work_directory_name()
click to toggle source
@return 终端工作 dir name
# File lib/coo/helper/file_hunter.rb, line 13 def self.work_directory_name return File.basename(Dir.pwd) end
work_directory_path()
click to toggle source
@return 终端工作 dir path
# File lib/coo/helper/file_hunter.rb, line 8 def self.work_directory_path return Dir.pwd end