Skip to content

Instantly share code, notes, and snippets.

@tkfm-yamaguchi
Last active December 11, 2015 20:19
Show Gist options
  • Save tkfm-yamaguchi/4654691 to your computer and use it in GitHub Desktop.
Save tkfm-yamaguchi/4654691 to your computer and use it in GitHub Desktop.
# coding: utf-8
require 'pathname'
require 'fileutils'
class Pathname
def basename_without_ext
Pathname(basename.to_s.gsub(/#{extname}$/, ""))
end
def to_spec_fname
dirname.join(basename_without_ext.to_s + "_spec" + extname.to_s)
end
def search_with_extname(ext=".rb")
[].tap do |files|
children.each do |path|
if path.directory?
files << path.search_with_extname(ext)
else
files << path if path.extname == ext
end
end
files.flatten!
end
end
def mkdir_p
FileUtils.mkdir_p to_s
end
def touch_p
dirname.mkdir_p unless dirname.exist?
FileUtils.touch to_s
end
end
if __FILE__ == $0
src_dirs = %w[bin lib].map{|d| Pathname(d)}
tgt_dir = Pathname("spec")
src_dirs.each do |src_dir|
src_dir.search_with_extname.each do |rbfile_path|
puts tgt_dir.join(rbfile_path.to_spec_fname).touch_p
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment