lib/bundler/cli/gem.rb in bundler-1.8.9 vs lib/bundler/cli/gem.rb in bundler-1.9.0.pre
- old
+ new
@@ -35,12 +35,14 @@
: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,
:test => options[:test],
:ext => options[:ext],
- :bin => options[:bin]
+ :bin => options[:bin],
+ :bundler_version => bundler_dependency_version
}
+ ensure_safe_gem_name(opts[:name], opts[:constant_array])
templates = {
"Gemfile.tt" => "Gemfile",
"gitignore.tt" => ".gitignore",
"lib/newgem.rb.tt" => "lib/#{namespaced_path}.rb",
@@ -157,9 +159,26 @@
if Bundler.settings["gem.test"].nil?
Bundler.settings.set_global("gem.test", test_framework)
end
test_framework
+ end
+
+ def bundler_dependency_version
+ v = Gem::Version.new(Bundler::VERSION)
+ req = v.segments[0..1]
+ req << v.segments.last if v.prerelease?
+ req.join(".")
+ end
+
+ def ensure_safe_gem_name name, constant_array
+ if name =~ /^\d/
+ Bundler.ui.error "Invalid gem name #{name} Please give a name which does not start with numbers."
+ exit 1
+ elsif Object.const_defined?(constant_array.first)
+ Bundler.ui.error "Invalid gem name #{name} constant #{constant_array.join("::")} is already in use. Please choose another gem name."
+ exit 1
+ end
end
end
end