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
47
48
49
50
51
52
|
# File 'lib/private_gem/cli.rb', line 17
def new(gem_name)
name = gem_name.chomp('/') underscored_name = name.tr('-', '_')
namespaced_path = name.tr('-', '/')
target = File.join(Dir.pwd, name)
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('::')
git_user_name = `git config user.name`.chomp
git_user_email = `git config user.email`.chomp
opts = {
:name => name,
:underscored_name => underscored_name,
:namespaced_path => namespaced_path,
:constant_name => constant_name,
:constant_array => constant_array,
:author => git_user_name.empty? ? 'TODO: Write your name' : git_user_name,
:email => git_user_email.empty? ? 'TODO: Write your email address' : git_user_email
}
template 'newgem/Gemfile.tt', "#{target}/Gemfile", opts
template "newgem/Rakefile.tt", "#{target}/Rakefile", opts
template "newgem/README.md.tt", "#{target}/README.md", opts
template "newgem/gitignore.tt", "#{target}/.gitignore", opts
template "newgem/newgem.gemspec.tt", "#{target}/#{name}.gemspec", opts
template "newgem/lib/newgem.rb.tt", "#{target}/lib/#{namespaced_path}.rb", opts
template "newgem/lib/newgem/version.rb.tt", "#{target}/lib/#{namespaced_path}/version.rb", opts
template "newgem/test/minitest_helper.rb.tt", "#{target}/test/minitest_helper.rb", opts
template "newgem/test/test_newgem.rb.tt", "#{target}/test/test_#{namespaced_path}.rb", opts
template "newgem/travis.yml.tt", "#{target}/.travis.yml", opts
if options[:bin]
template "newgem/bin/newgem.tt", "#{target}/bin/#{name}", opts
end
Dir.chdir(target) { `git init; git add .` }
end
|