summaryrefslogtreecommitdiff
path: root/lib/bundler/plugin.rb
diff options
context:
space:
mode:
authorAsutosh Palai <asupalai@gmail.com>2016-06-16 20:57:31 +0530
committerAsutosh Palai <asupalai@gmail.com>2016-07-03 09:40:59 +0530
commit16a51aa6f58f12471bfa96aeb48b11bc73b76025 (patch)
treeba68c47b5832883f31631e60b21cd7a09032a30e /lib/bundler/plugin.rb
parentb94002bffe7f05a8aa8f94ebd3ef75760e2a1cab (diff)
downloadbundler-16a51aa6f58f12471bfa96aeb48b11bc73b76025.tar.gz
Formatting and doc strings
Diffstat (limited to 'lib/bundler/plugin.rb')
-rw-r--r--lib/bundler/plugin.rb56
1 files changed, 31 insertions, 25 deletions
diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb
index 27d1f1020f..928049326e 100644
--- a/lib/bundler/plugin.rb
+++ b/lib/bundler/plugin.rb
@@ -31,7 +31,7 @@ module Bundler
save_plugins paths
rescue PluginError => e
paths.values.map {|path| Bundler.rm_rf(path) } if paths
- Bundler.ui.error "Failed to install plugin #{name}: #{e.message}\n #{e.backtrace.join("\n ")}"
+ Bundler.ui.error "Failed to install plugin #{name}: #{e.message}\n #{e.backtrace[0]}"
end
# Evaluates the Gemfile with a limited DSL and installs the plugins
@@ -46,7 +46,7 @@ module Bundler
else
definition = DSL.evaluate(gemfile, nil, {})
end
- return unless definition.dependencies.any?
+ return if definition.dependencies.empty?
plugins = Installer.new.install_definition(definition)
@@ -73,7 +73,7 @@ module Bundler
@commands[command] = cls
end
- # Checks if any plugins handles the command
+ # Checks if any plugin handles the command
def command?(command)
!index.command_plugin(command).nil?
end
@@ -81,40 +81,24 @@ module Bundler
# To be called from Cli class to pass the command and argument to
# approriate plugin class
def exec_command(command, args)
- raise UndefinedCommandError, "Command #{command} not found" unless command? command
+ raise UndefinedCommandError, "Command `#{command}` not found" unless command? command
load_plugin index.command_plugin(command) unless @commands.key? command
@commands[command].new.exec(command, args)
end
- # currently only intended for specs
- #
- # @return [String, nil] installed path
- def installed?(plugin)
- Index.new.installed?(plugin)
- end
-
- # Post installation processing and registering with index
- #
- # @param [Hash] plugins mapped to their installtion path
- def save_plugins(plugins)
- plugins.each do |name, path|
- path = Pathname.new path
- validate_plugin! path
- register_plugin name, path
- Bundler.ui.info "Installed plugin #{name}"
- end
- end
-
+ # To be called via the API to register to handle a source plugin
def add_source(source, cls)
@sources[source] = cls
end
+ # Checks if any plugin declares the source
def source?(name)
- index.source? name
+ !index.source_plugin(name).nil?
end
+ # @return [Class] that handles the source. The calss includes API::Source
def source(name)
raise UnknownSourceError, "Source #{name} not found" unless source? name
@@ -123,12 +107,34 @@ module Bundler
@sources[name]
end
+ # @param [Hash] The options that are present in the lock file
+ # @return [API::Source] the instance of the class that handles the source
+ # type passed in locked_opts
def source_from_lock(locked_opts)
src = source(locked_opts["type"])
src.new(locked_opts.merge("uri" => locked_opts["remote"]))
end
+ # currently only intended for specs
+ #
+ # @return [String, nil] installed path
+ def installed?(plugin)
+ Index.new.installed?(plugin)
+ end
+
+ # Post installation processing and registering with index
+ #
+ # @param [Hash] plugins mapped to their installtion path
+ def save_plugins(plugins)
+ plugins.each do |name, path|
+ path = Pathname.new path
+ validate_plugin! path
+ register_plugin name, path
+ Bundler.ui.info "Installed plugin #{name}"
+ end
+ end
+
# Checks if the gem is good to be a plugin
#
# At present it only checks whether it contains plugins.rb file
@@ -137,7 +143,7 @@ module Bundler
# @raise [Error] if plugins.rb file is not found
def validate_plugin!(plugin_path)
plugin_file = plugin_path.join(PLUGIN_FILE_NAME)
- raise MalformattedPlugin, "#{PLUGIN_FILE_NAME} was not found in the plugin!" unless plugin_file.file?
+ raise MalformattedPlugin, "#{PLUGIN_FILE_NAME} was not found in the plugin." unless plugin_file.file?
end
# Runs the plugins.rb file in an isolated namespace, records the plugin