17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/thjalfi/cli.rb', line 17
def new(name)
argv = ["gem", name]
argv << "--ext" if options[:ext]
argv += ["-t", options[:test]] if options[:text]
Bundler::CLI.start(argv)
target = Pathname.pwd.join(name)
return unless File.directory?(target)
name = name.chomp("/")
namespaced_path = name.tr('-', '/')
constant_name = name.split('_').map{|p| p[0..0].upcase + p[1..-1] }.join
constant_name = constant_name.split('-').map{|q| q[0..0].upcase + q[1..-1] }.join('::') if constant_name =~ /-/
constant_array = constant_name.split('::')
opts = {
namespaced_path: namespaced_path,
constant_name: constant_name,
constant_array: constant_array,
}
templates = {
"bin/newgem.tt" => "bin/#{name}",
"lib/newgem/cli.rb.tt" => "lib/#{namespaced_path}/cli.rb",
}
templates.each do |src, dst|
template(src, target.join(dst), opts)
end
Dir.chdir(target) { `chmod +x bin/#{name}; git add .` }
end
|