Make requiring gems optional.
Signed-off-by: Michael Koziarski <michael@koziarski.com> [#743 state:resolved]
This commit is contained in:
parent
82343859d5
commit
61842d97c5
|
@ -688,13 +688,17 @@ Run `rake gems:install` to install the missing gems.
|
|||
# You can add gems with the #gem method.
|
||||
attr_accessor :gems
|
||||
|
||||
# Adds a single Gem dependency to the rails application.
|
||||
# Adds a single Gem dependency to the rails application. By default, it will require
|
||||
# the library with the same name as the gem. Use :lib to specify a different name.
|
||||
#
|
||||
# # gem 'aws-s3', '>= 0.4.0'
|
||||
# # require 'aws/s3'
|
||||
# config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', \
|
||||
# :source => "http://code.whytheluckystiff.net"
|
||||
#
|
||||
# To require a library be installed, but not attempt to load it, pass :lib => false
|
||||
#
|
||||
# config.gem 'qrp', :version => '0.4.1', :lib => false
|
||||
def gem(name, options = {})
|
||||
@gems << Rails::GemDependency.new(name, options)
|
||||
end
|
||||
|
|
|
@ -58,7 +58,7 @@ module Rails
|
|||
|
||||
def load
|
||||
return if @loaded || @load_paths_added == false
|
||||
require(@lib || @name)
|
||||
require(@lib || @name) unless @lib == false
|
||||
@loaded = true
|
||||
rescue LoadError
|
||||
puts $!.to_s
|
||||
|
|
|
@ -11,6 +11,7 @@ uses_mocha "Plugin Tests" do
|
|||
@gem_with_source = Rails::GemDependency.new "hpricot", :source => "http://code.whytheluckystiff.net"
|
||||
@gem_with_version = Rails::GemDependency.new "hpricot", :version => "= 0.6"
|
||||
@gem_with_lib = Rails::GemDependency.new "aws-s3", :lib => "aws/s3"
|
||||
@gem_without_load = Rails::GemDependency.new "hpricot", :lib => false
|
||||
end
|
||||
|
||||
def test_configuration_adds_gem_dependency
|
||||
|
@ -62,5 +63,13 @@ uses_mocha "Plugin Tests" do
|
|||
@gem_with_lib.add_load_paths
|
||||
@gem_with_lib.load
|
||||
end
|
||||
|
||||
def test_gem_without_lib_loading
|
||||
@gem_without_load.expects(:gem).with(@gem_without_load.name)
|
||||
@gem_without_load.expects(:require).with(@gem_without_load.lib).never
|
||||
@gem_without_load.add_load_paths
|
||||
@gem_without_load.load
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue