Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Accept consistent gem naming
Browse files Browse the repository at this point in the history
library_name => LibraryName
  e.g.) newrelic_rpm and factory_girl.

library_name-extention => LibraryName::Extension
  e.g.) net-http-persistent and autotest-growl.

See also: http://guides.rubygems.org/patterns/#consistent-naming
  • Loading branch information
banyan committed Dec 3, 2012
1 parent dcb7a6e commit eeba36b
Show file tree
Hide file tree
Showing 8 changed files with 274 additions and 111 deletions.
10 changes: 6 additions & 4 deletions lib/bundler/cli.rb
Expand Up @@ -593,6 +593,7 @@ def viz
method_option :test, :type => :string, :default => 'rspec', :aliases => '-t', :banner => "Generate a test directory for your library: 'rspec' is the default, but 'minitest' is also supported."
def gem(name)
name = name.chomp("/") # remove trailing slash if present
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 =~ /-/
Expand All @@ -602,6 +603,7 @@ def gem(name)
git_user_email = `git config user.email`.chomp
opts = {
:name => 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,
Expand All @@ -613,19 +615,19 @@ def gem(name)
template(File.join("newgem/README.md.tt"), File.join(target, "README.md"), opts)
template(File.join("newgem/gitignore.tt"), File.join(target, ".gitignore"), opts)
template(File.join("newgem/newgem.gemspec.tt"), File.join(target, "#{name}.gemspec"), opts)
template(File.join("newgem/lib/newgem.rb.tt"), File.join(target, "lib/#{name}.rb"), opts)
template(File.join("newgem/lib/newgem/version.rb.tt"), File.join(target, "lib/#{name}/version.rb"), opts)
template(File.join("newgem/lib/newgem.rb.tt"), File.join(target, "lib/#{namespaced_path}.rb"), opts)
template(File.join("newgem/lib/newgem/version.rb.tt"), File.join(target, "lib/#{namespaced_path}/version.rb"), opts)
if options[:bin]
template(File.join("newgem/bin/newgem.tt"), File.join(target, 'bin', name), opts)
end
case options[:test]
when 'rspec'
template(File.join("newgem/rspec.tt"), File.join(target, ".rspec"), opts)
template(File.join("newgem/spec/spec_helper.rb.tt"), File.join(target, "spec/spec_helper.rb"), opts)
template(File.join("newgem/spec/newgem_spec.rb.tt"), File.join(target, "spec/#{name}_spec.rb"), opts)
template(File.join("newgem/spec/newgem_spec.rb.tt"), File.join(target, "spec/#{namespaced_path}_spec.rb"), opts)
when 'minitest'
template(File.join("newgem/test/minitest_helper.rb.tt"), File.join(target, "test/minitest_helper.rb"), opts)
template(File.join("newgem/test/test_newgem.rb.tt"), File.join(target, "test/test_#{name}.rb"), opts)
template(File.join("newgem/test/test_newgem.rb.tt"), File.join(target, "test/test_#{namespaced_path}.rb"), opts)
end
Bundler.ui.info "Initializating git repo in #{target}"
Dir.chdir(target) { `git init`; `git add .` }
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/templates/newgem/bin/newgem.tt
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby

require '<%= config[:name] %>'
require '<%= config[:namespaced_path] %>'
2 changes: 1 addition & 1 deletion lib/bundler/templates/newgem/lib/newgem.rb.tt
@@ -1,4 +1,4 @@
require "<%=config[:name]%>/version"
require "<%=config[:namespaced_path]%>/version"

<%- config[:constant_array].each_with_index do |c,i| -%>
<%= ' '*i %>module <%= c %>
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/templates/newgem/newgem.gemspec.tt
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require '<%=config[:name]%>/version'
require '<%=config[:namespaced_path]%>/version'

Gem::Specification.new do |gem|
gem.name = <%=config[:name].inspect%>
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/templates/newgem/spec/spec_helper.rb.tt
@@ -1,2 +1,2 @@
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require '<%= config[:name] %>'
require '<%= config[:namespaced_path] %>'
2 changes: 1 addition & 1 deletion lib/bundler/templates/newgem/test/minitest_helper.rb.tt
@@ -1,4 +1,4 @@
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require '<%= config[:name] %>'
require '<%= config[:namespaced_path] %>'

require 'minitest/autorun'
2 changes: 1 addition & 1 deletion spec/bundler/gem_helper_spec.rb
Expand Up @@ -35,7 +35,7 @@

it "handles namespaces and converting to CamelCase" do
bundle 'gem test-foo_bar'
lib = bundled_app('test-foo_bar').join('lib/test-foo_bar.rb').read
lib = bundled_app('test-foo_bar').join('lib/test/foo_bar.rb').read
expect(lib).to include("module Test")
expect(lib).to include("module FooBar")
end
Expand Down

0 comments on commit eeba36b

Please sign in to comment.