Skip to content

Commit

Permalink
[merb-core] [merb-gen] Seamless bundler support from system bin
Browse files Browse the repository at this point in the history
This merb-gen patch provides newly generated apps with the ability to work seamlessly with the bundler, whether you run merb, rake, spec from either your local system gem path or from bin/merb, bin/rake, bin/spec.

No more having to bundle rake and rspec. w00t!
  • Loading branch information
merbjedi authored and pk committed Nov 17, 2009
1 parent 1faae25 commit e66a0fc
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 47 deletions.
7 changes: 0 additions & 7 deletions merb-core/lib/merb-core.rb
Expand Up @@ -5,13 +5,6 @@
root_key = %w[-m --merb-root].detect { |o| ARGV.index(o) }
root = ARGV[ARGV.index(root_key) + 1] if root_key
root = root.to_a.empty? ? Dir.getwd : root
if File.directory?(gems_dir = File.join(root, "gems")) && !$BUNDLE
# Warn if local merb-core is available but not loaded.
if File.expand_path($0).index(root) != 0 &&
(local_mc = Dir[File.join(gems_dir, "specifications", "merb-core-*.gemspec")].last)
puts "Warning: please use bin/#{File.basename($0)} to load #{File.basename(local_mc, ".gemspec")} from ./gems"
end
end

require 'bundler'
require "thread"
Expand Down
22 changes: 22 additions & 0 deletions merb-core/lib/merb-core/bootloader.rb
Expand Up @@ -379,6 +379,7 @@ def self.run
load_initfile
load_env_config
end
load_bundler_environment
expand_ruby_path
load_bundler_dependencies
load_kernel_dependencies if Merb::Config[:kernel_dependencies]
Expand All @@ -387,6 +388,27 @@ def self.run
nil
end

# Try to load the gem environment file (set via Merb::Config[:gemenv])
# defaults to ./gems/environment
#
# Falls back to rubygems if no bundler environment exists
#
# ==== Returns
# nil
#
# :api: private
def self.load_bundler_environment
begin
# Try to load the bundler environment from Merb::Config[:gemenv]
# default to ./gems/environment.rb
require Merb.root / (Merb::Config[:gemenv] || "gems" / "environment")
rescue LoadError
# Default to using system rubygems if not bundled
require "rubygems"
end
nil
end

# Load each the dependencies defined in the Merb::Config[:gemfile]
# using the bundler gem's Bundler::Environment.load
#
Expand Down
3 changes: 2 additions & 1 deletion merb-core/lib/merb-core/config.rb
Expand Up @@ -31,7 +31,8 @@ def defaults
:verbose => false,
:name => "merb",
:kernel_dependencies => true,
:gemfile => nil
:gemfile => nil,
:gemenv => nil
}
end

Expand Down
8 changes: 8 additions & 0 deletions merb-gen/lib/generators/templates/application/common/Rakefile
@@ -1,3 +1,11 @@
begin
# Load the bundler environment from #{Merb.root}/gems/environment.rb
require File.join(File.dirname(__FILE__), "gems", "environment")
rescue LoadError
# Default to using system rubygems if there's no bundle detected
require "rubygems"
end

require 'rake/rdoctask'

require 'merb-core'
Expand Down
@@ -1,5 +1,5 @@
# Go to http://wiki.merbivore.com/pages/init-rb

# Specify your dependencies in the Gemfile
<%= "use_orm :#{orm}" unless orm == :none %>
use_test :<%= testing_framework %>
Expand Down
@@ -1,6 +1,13 @@
require "rubygems"
require "merb-core"
begin
# Load the bundler environment from #{Merb.root}/gems/environment.rb
require File.join(File.dirname(__FILE__), "..", "gems", "environment")
rescue LoadError
# Default to using system rubygems if there's no bundle detected
require "rubygems"
end

require "spec" # Satisfies Autotest and anyone else not using the Rake tasks
require "merb-core"

# this loads all plugins required in your init file so don't add them
# here again, Merb will do it for you
Expand Down
@@ -1,9 +1,9 @@
require "rubygems"

# Add the local gems dir if found within the app root; any dependencies loaded
# hereafter will try to load from the local gems before loading system gems.
if (local_gem_dir = File.join(File.dirname(__FILE__), '..', 'gems')) && $BUNDLE.nil?
$BUNDLE = true; Gem.clear_paths; Gem.path.unshift(local_gem_dir)
begin
# Load the bundler environment from #{Merb.root}/gems/environment.rb
require File.join(File.dirname(__FILE__), "..", "gems", "environment")
rescue LoadError
# Default to using system rubygems if there's no bundle detected
require "rubygems"
end

require "merb-core"
Expand Down
Expand Up @@ -4,8 +4,7 @@
use_test :<%= testing_framework %>
use_template_engine :<%= template_engine %>

# Specify a specific version of a dependency
# dependency "RedCloth", "> 3.0"
# Specify your dependencies in the Gemfile

Merb::BootLoader.before_app_loads do
# This will get executed after dependencies have been loaded but before your app's classes have loaded.
Expand Down
@@ -1,4 +1,11 @@
require "rubygems"
begin
# Load the bundler environment from #{Merb.root}/gems/environment.rb
require File.join(File.dirname(__FILE__), "..", "gems", "environment")
rescue LoadError
# Default to using system rubygems if there's no bundle detected
require "rubygems"
end

require "spec"
require "merb-core"

Expand Down
@@ -1,9 +1,9 @@
require "rubygems"

# Add the local gems dir if found within the app root; any dependencies loaded
# hereafter will try to load from the local gems before loading system gems.
if (local_gem_dir = File.join(File.dirname(__FILE__), '..', 'gems')) && $BUNDLE.nil?
$BUNDLE = true; Gem.clear_paths; Gem.path.unshift(local_gem_dir)
begin
# Load the bundler environment from #{Merb.root}/gems/environment.rb
require File.join(File.dirname(__FILE__), "..", "gems", "environment")
rescue LoadError
# Default to using system rubygems if there's no bundle detected
require "rubygems"
end

require "merb-core"
Expand Down
@@ -1,11 +1,9 @@
begin
require File.join(File.dirname(__FILE__), "gems/environment")
# Load the bundler environment from #{Merb.root}/gems/environment.rb
require File.join(File.dirname(__FILE__), "gems", "environment")
rescue LoadError
begin
require 'minigems'
rescue LoadError
require 'rubygems'
end
# Default to using system rubygems if there's no bundle detected
require "rubygems"
end

require 'merb-core'
Expand Down
@@ -1,5 +1,7 @@
# Go to http://wiki.merbivore.com/pages/init-rb

# Specify your dependencies in the Gemfile

use_orm :datamapper
use_test :<%= testing_framework %>
use_template_engine :<%= template_engine %>
Expand Down
@@ -1,6 +1,13 @@
require "rubygems"
require "merb-core"
begin
# Load the bundler environment from #{Merb.root}/gems/environment.rb
require File.join(File.dirname(__FILE__), "..", "gems", "environment")
rescue LoadError
# Default to using system rubygems if there's no bundle detected
require "rubygems"
end

require "spec" # Satisfies Autotest and anyone else not using the Rake tasks
require "merb-core"

# this loads all plugins required in your init file so don't add them
# here again, Merb will do it for you
Expand Down
@@ -1,9 +1,9 @@
require "rubygems"

# Add the local gems dir if found within the app root; any dependencies loaded
# hereafter will try to load from the local gems before loading system gems.
if (local_gem_dir = File.join(File.dirname(__FILE__), '..', 'gems')) && $BUNDLE.nil?
$BUNDLE = true; Gem.clear_paths; Gem.path.unshift(local_gem_dir)
begin
# Load the bundler environment from #{Merb.root}/gems/environment.rb
require File.join(File.dirname(__FILE__), "..", "gems", "environment")
rescue LoadError
# Default to using system rubygems if there's no bundle detected
require "rubygems"
end

require "merb-core"
Expand Down
@@ -1,4 +1,11 @@
require "rubygems"
begin
# Load the bundler environment from #{Merb.root}/gems/environment.rb
require File.join(File.dirname(__FILE__), "..", "gems", "environment")
rescue LoadError
# Default to using system rubygems if there's no bundle detected
require "rubygems"
end

require "spec"
require "merb-core"

Expand Down
10 changes: 4 additions & 6 deletions merb-gen/lib/generators/templates/component/fcgi/merb.fcgi
@@ -1,12 +1,10 @@
#!/usr/bin/env ruby
begin
require File.join(File.dirname(__FILE__), "../gems/environment")
# Load the bundler environment from #{Merb.root}/gems/environment.rb
require File.join(File.dirname(__FILE__), "..", "gems", "environment")
rescue LoadError
begin
require 'minigems'
rescue LoadError
require 'rubygems'
end
# Default to using system rubygems if there's no bundle detected
require "rubygems"
end

require 'merb-core'
Expand Down

0 comments on commit e66a0fc

Please sign in to comment.