summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsutosh Palai <asupalai@gmail.com>2016-05-27 12:33:32 +0530
committerAsutosh Palai <asupalai@gmail.com>2016-05-27 12:51:55 +0530
commit10c87cff76e2ec5a21d7b8978debfb19ea9e5ebb (patch)
tree71a917b667b84f5a099e4e7f9402d8c667705da7
parent5ab32cdb78510079d203a2c56ecb2ac56b9de984 (diff)
downloadbundler-10c87cff76e2ec5a21d7b8978debfb19ea9e5ebb.tar.gz
Added spec for gemfile eval and a few docs
-rw-r--r--lib/bundler/plugin.rb4
-rw-r--r--lib/bundler/plugin/dsl.rb8
-rw-r--r--lib/bundler/plugin/installer.rb18
-rw-r--r--lib/bundler/plugin/source_list.rb4
-rw-r--r--spec/plugins/install.rb49
5 files changed, 70 insertions, 13 deletions
diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb
index 1421b6fdcb..e4ab928735 100644
--- a/lib/bundler/plugin.rb
+++ b/lib/bundler/plugin.rb
@@ -27,6 +27,10 @@ module Bundler
Bundler.ui.error "Failed to install plugin #{name}: #{e.message}\n #{e.backtrace.join("\n ")}"
end
+ # Evaluates the Gemfile with a limited DSL and installs the plugins
+ # specified by plugin method
+ #
+ # @param [Pathname] gemfile path
def eval_gemfile(gemfile)
definition = Dsl.evaluate(gemfile, nil, {})
return unless definition.dependencies.any?
diff --git a/lib/bundler/plugin/dsl.rb b/lib/bundler/plugin/dsl.rb
index f59c051f77..b0fb6735ad 100644
--- a/lib/bundler/plugin/dsl.rb
+++ b/lib/bundler/plugin/dsl.rb
@@ -1,12 +1,14 @@
# frozen_string_literal: true
module Bundler
+ # Dsl to parse the Gemfile looking for plugins to install
class Plugin::Dsl < Bundler::Dsl
alias_method :_gem, :gem # To use for plugin installation as gem
- # So that we don't have to overwrite all there methods to dummy ones
- [:gemspec, :gem, :path, :install_if, :platforms, :env]
- .each {|m| undef_method m}
+ # So that we don't have to override all there methods to dummy ones
+ # explicitly.
+ # They will be handled by missing_methods
+ [:gemspec, :gem, :path, :install_if, :platforms, :env].each {|m| undef_method m }
def initialize
@sources = Plugin::SourceList.new
diff --git a/lib/bundler/plugin/installer.rb b/lib/bundler/plugin/installer.rb
index 16dc05a519..605d272db0 100644
--- a/lib/bundler/plugin/installer.rb
+++ b/lib/bundler/plugin/installer.rb
@@ -6,8 +6,6 @@ module Bundler
# This class is supposed to be wrapper over the existing gem installation infra
# but currently it itself handles everything as the Source's subclasses (e.g. Source::RubyGems)
# are heavily dependent on the Gemfile.
- #
- # @todo: Remove the dependencies of Source's subclasses and try to use the Bundler sources directly. This will reduce the redundancies.
class Plugin::Installer
def install(name, options)
if options[:git]
@@ -22,6 +20,11 @@ module Bundler
end
end
+ # Installs the plugin from Definition object created by limited parsing of
+ # Gemfile searching for plugins to be installed
+ #
+ # @param [Definition] definiton object
+ # @return [Hash] map of plugin names to thier paths
def install_definition(definition)
plugins = definition.dependencies.map(&:name)
@@ -30,7 +33,7 @@ module Bundler
paths = install_from_spec specs
- paths.select {|name, _| plugins.include? name}
+ paths.select {|name, _| plugins.include? name }
end
private
@@ -74,13 +77,12 @@ module Bundler
paths[name]
end
- # Installs the plugin from the provided spec and returns the path where the
- # plugin was installed.
+ # Installs the plugins and deps from the provided specs and returns map of
+ # gems to their paths
#
- # @param spec to fetch and install
- # @raise [ArgumentError] if the spec object has no remote set
+ # @param specs to install
#
- # @return [String] the path where the plugin was installed
+ # @return [Hash] map of names to path where the plugin was installed
def install_from_spec(specs)
paths = {}
diff --git a/lib/bundler/plugin/source_list.rb b/lib/bundler/plugin/source_list.rb
index 457b4ef7d5..c1903e9dd2 100644
--- a/lib/bundler/plugin/source_list.rb
+++ b/lib/bundler/plugin/source_list.rb
@@ -1,8 +1,9 @@
# frozen_string_literal: true
module Bundler
+ # SourceList object to be used while parsing the Gemfile, setting the
+ # approptiate options to be used with Source classes for plugin installation
class Plugin::SourceList < Bundler::SourceList
-
def initialize
@rubygems_aggregate = Source::Rubygems.new :plugin => true
super
@@ -15,6 +16,5 @@ module Bundler
def add_rubygems_source(options = {})
add_source_to_list Source::Rubygems.new(options.merge(:plugin => true)), @rubygems_sources
end
-
end
end
diff --git a/spec/plugins/install.rb b/spec/plugins/install.rb
index 33d3b58b9b..c5d0937d05 100644
--- a/spec/plugins/install.rb
+++ b/spec/plugins/install.rb
@@ -71,4 +71,53 @@ describe "bundler plugin install" do
expect(out).to include("Installed plugin foo")
end
end
+
+ context "Gemfile eval" do
+ it "installs plugins listed in gemfile" do
+ gemfile <<-G
+ source 'file://#{gem_repo2}'
+ plugin 'foo'
+ gem 'rack', "1.0.0"
+ G
+
+ bundle "install"
+
+ expect(out).to include("Installed plugin foo")
+
+ expect(out).to include("Bundle complete!")
+
+ should_be_installed("rack 1.0.0")
+ end
+
+ it "accepts plugin version" do
+ update_repo2 do
+ build_plugin "foo", "1.1.0"
+ end
+
+ install_gemfile <<-G
+ source 'file://#{gem_repo2}'
+ plugin 'foo', "1.0"
+ G
+
+ bundle "install"
+
+ expect(out).to include("Installing foo 1.0")
+
+ expect(out).to include("Installed plugin foo")
+
+ expect(out).to include("Bundle complete!")
+ end
+
+ it "accepts git sources" do
+ build_git "ga-plugin" do |s|
+ s.write "plugin.rb"
+ end
+
+ install_gemfile <<-G
+ plugin 'ga-plugin', :git => "#{lib_path("ga-plugin-1.0")}"
+ G
+
+ expect(out).to include("Installed plugin ga-plugin")
+ end
+ end
end