Module: TouchP
- Defined in:
- lib/touch_p.rb,
lib/touch_p/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
Class Method Details
.exe ⇒ Object
4 5 6 7 |
# File 'lib/touch_p.rb', line 4 def self.exe return if !is_valid?(ARGV) touch_p(ARGV) end |
.extract_dir(file_path) ⇒ Object
35 36 37 38 |
# File 'lib/touch_p.rb', line 35 def self.extract_dir(file_path) return file_path if file_path[-1] == "/" return file_path.split("/").slice(0..-2).join("/") end |
.is_valid?(argv) ⇒ Boolean
28 29 30 31 32 33 |
# File 'lib/touch_p.rb', line 28 def self.is_valid?(argv) return puts("Usage: touch_p FILE...") if argv[0] == "--help" return puts("touch_p: '#{TouchP::VERSION}'") if argv[0] == "--version" return puts("Try 'touch_p --help' for more information.") if argv.length == 0 || argv[0][0] == "-" return true end |
.touch_p(argv) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/touch_p.rb', line 9 def self.touch_p(argv) argv.each do |file_path| if file_path.include?("/") dir = extract_dir(file_path) begin FileUtils.mkdir_p(dir) rescue Errno::EEXIST end end end begin FileUtils.touch(argv) rescue => exception puts exception end end |