Skip to content
Browse files

added --init to create a Gemfile and fix quality spec failures

  • Loading branch information...
1 parent bf7478c commit 2ba4a35f11aed2c69d4c972d15f7d1d57068cf23 bry4n committed with Yehuda Katz Jan 4, 2010
Showing with 105 additions and 3 deletions.
  1. +12 −1 lib/bundler/commands/bundle_command.rb
  2. +2 −2 lib/bundler/source.rb
  3. +72 −0 lib/bundler/templates/Gemfile
  4. +19 −0 spec/bundler/cli_spec.rb
View
13 lib/bundler/commands/bundle_command.rb
@@ -3,6 +3,10 @@ class Gem::Commands::BundleCommand < Gem::Command
def initialize
super('bundle', 'Create a gem bundle based on your Gemfile', {:manifest => nil, :update => false})
+ add_option('-i', '--init',"Create a Gemfile") do
+ options[:init] = true
+ end
+
add_option('-m', '--manifest MANIFEST', "Specify the path to the manifest file") do |manifest, options|
options[:manifest] = manifest
end
@@ -64,9 +68,16 @@ def execute
Bundler::CLI.run(:list, options)
elsif options[:list_outdated]
Bundler::CLI.run(:list_outdated, options)
+ elsif options[:init]
+ if File.exists?("Gemfile")
+ Bundler.logger.error "The Gemfile already exists"
+ else
+ FileUtils.cp File.expand_path("../../templates/Gemfile", __FILE__), "Gemfile"
+ Bundler.logger.info "Initialized Gemfile in #{Dir.pwd}"
+ end
else
Bundler::CLI.run(:bundle, options)
end
end
-end
+end
View
4 lib/bundler/source.rb
@@ -353,11 +353,11 @@ def clone
def current_revision
Dir.chdir(location) { `git rev-parse HEAD`.strip }
end
-
+
def revision_for_ref
Dir.chdir(location) { `git rev-parse #{@ref}`.strip }
end
-
+
def checkout
Dir.chdir(location) { `git checkout --quiet #{@ref}` }
end
View
72 lib/bundler/templates/Gemfile
@@ -0,0 +1,72 @@
+# Specify a dependency on rails. When the bundler downloads gems,
+# it will download rails as well as all of rails' dependencies (such as
+# activerecord, actionpack, etc...)
+#
+# At least one dependency must be specified
+#gem "rails"
+
+# Specify a dependency on rack v.1.0.0. The version is optional. If present,
+# it can be specified the same way as with rubygems' #gem method.
+#gem "rack", "1.0.0"
+
+# Specify a dependency rspec, but only require that gem in the "testing"
+# environment. :except is also a valid option to specify environment
+# restrictions.
+#gem "rspec", :only => :testing
+
+# Specify a dependency, but specify that it is already present and expanded
+# at vendor/rspec. Bundler will treat rspec as though it was the rspec gem
+# for the purpose of gem resolution: if another gem depends on a version
+# of rspec satisfied by "1.1.6", it will be used.
+#
+# If a gemspec is found in the directory, it will be used to specify load
+# paths and supply additional dependencies.
+#
+# Bundler will also recursively search for *.gemspec, and assume that
+# gemspecs it finds represent gems that are rooted in the same directory
+# the gemspec is found in.
+#gem "rspec", "1.1.6", :vendored_at => "vendor/rspec"
+
+# You can also control what will happen when you run Bundler.require_env
+# by using the :require_as option, as per the next two examples.
+
+# Don't auto-require this gem.
+#gem "rspec-rails", "1.2.9", :require_as => nil
+
+# Require something other than the default.
+#gem "yajl-ruby", "0.6.7", :require_as => "yajl/json_gem"
+
+# Works exactly like :vendored_at, but first downloads the repo from
+# git and handles stashing the files for you. As with :vendored_at,
+# Bundler will automatically use *.gemspec files in the root or anywhere
+# in the repository.
+#gem "rails", "3.0.pre", :git => "git://github.com/rails/rails.git"
+
+# Add http://gems.github.com as a source that the bundler will use
+# to find gems listed in the manifest. By default,
+# http://gems.rubyforge.org is already added to the list.
+#
+# This is an optional setting.
+#source "http://gems.github.com"
+
+# Specify where the bundled gems should be stashed. This directory will
+# be a gem repository where all gems are downloaded to and installed to.
+#
+# This is an optional setting.
+# The default is: vendor/gems
+#bundle_path "my/bundled/gems"
+
+# Specify where gem executables should be copied to.
+#
+# This is an optional setting.
+# The default is: bin
+#bin_path "my/executables"
+
+# Specify that rubygems should be completely disabled. This means that it
+# will be impossible to require it and that available gems will be
+# limited exclusively to gems that have been bundled.
+#
+# The default is to automatically require rubygems. There is also a
+# `disable_system_gems` option that will limit available rubygems to
+# the ones that have been bundled.
+#disable_rubygems
View
19 spec/bundler/cli_spec.rb
@@ -2,6 +2,25 @@
describe "Bundler::CLI" do
+ describe "it creates a new Gemfile with gem bundle --init" do
+ it "creates a Gemfile" do
+ FileUtils.mkdir_p(bundled_app)
+ Dir.chdir(bundled_app) do
+ gem_command :bundle, "--init"
+ end
+ bundled_app.join("Gemfile").should exist
+ end
+
+ it "exits with a warning if a Gemfile already exists" do
+ FileUtils.mkdir_p(bundled_app)
+ Dir.chdir(bundled_app) do
+ FileUtils.touch("Gemfile")
+ output = gem_command :bundle, "--init 2>&1"
+ output.should =~ /already exists/
+ end
+ end
+ end
+
describe "it compiles gems that take options" do
before(:each) do
build_manifest <<-Gemfile

0 comments on commit 2ba4a35

Please sign in to comment.
Something went wrong with that request. Please try again.