diff options
author | Asutosh Palai <asupalai@gmail.com> | 2016-05-24 20:34:00 +0530 |
---|---|---|
committer | Asutosh Palai <asupalai@gmail.com> | 2016-05-24 21:15:01 +0530 |
commit | cb66151d1f8ebe788ed4a605e9bfc13f451dbe1f (patch) | |
tree | 51bd2c61fb7e84dda5599a32f44e61ab34da4a77 | |
parent | c34633e591f35c3506bbec6515ee2ba33e7ee024 (diff) | |
download | bundler-cb66151d1f8ebe788ed4a605e9bfc13f451dbe1f.tar.gz |
Structured the classes with private methods
-rw-r--r-- | lib/bundler/plugin.rb | 34 | ||||
-rw-r--r-- | lib/bundler/plugin/index.rb | 34 | ||||
-rw-r--r-- | lib/bundler/plugin/installer.rb | 10 |
3 files changed, 42 insertions, 36 deletions
diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb index 5c6ba5dd00..b32d3d879d 100644 --- a/lib/bundler/plugin.rb +++ b/lib/bundler/plugin.rb @@ -14,7 +14,7 @@ module Bundler # @option options [String] :version (optional) the version of the plugin to install def install(name, options) require "bundler/plugin/installer.rb" - plugin_path = Pathname.new Installer.install(name, options) + plugin_path = Pathname.new Installer.new.install(name, options) validate_plugin! plugin_path @@ -26,6 +26,23 @@ module Bundler Bundler.ui.error "Failed to install plugin #{name}: #{e.message}\n #{e.backtrace.join("\n ")}" end + # The index object used to store the details about the plugin + def index + @index ||= Index.new + end + + # The directory root to all plugin related data + def root + @root ||= Bundler.user_bundle_path.join("plugin") + end + + # The cache directory for plugin stuffs + def cache + @cache ||= root.join("cache") + end + + private + # Checks if the gem is good to be a plugin # # At present it only checks whether it contains plugin.rb file @@ -48,21 +65,6 @@ module Bundler index.register_plugin name, path.to_s end - - # The index object used to store the details about the plugin - def index - @index ||= Index.new - end - - # The directory root to all plugin related data - def root - @root ||= Bundler.user_bundle_path.join("plugin") - end - - # The cache directory for plugin stuffs - def cache - @cache ||= root.join("cache") - end end end end diff --git a/lib/bundler/plugin/index.rb b/lib/bundler/plugin/index.rb index 87a9de9acb..0fc70af27a 100644 --- a/lib/bundler/plugin/index.rb +++ b/lib/bundler/plugin/index.rb @@ -12,6 +12,24 @@ module Bundler load_index end + # This function is to be called when a new plugin is installed. This function shall add + # the functions of the plugin to existing maps and also the name to source location. + # + # @param [String] name of the plugin to be registered + # @param [String] path where the plugin is installed + def register_plugin(name, path) + @plugin_sources[name] = path + + save_index + end + + # Path where the index file is stored + def index_file + Plugin.root.join("index") + end + + private + # Reads the index file from the directory and initializes the instance variables. def load_index SharedHelpers.filesystem_access(index_file, :read) do |index_f| @@ -34,21 +52,5 @@ module Bundler File.open(index_f, "w") {|f| f.puts YAML.dump(index) } end end - - # This function is to be called when a new plugin is installed. This function shall add - # the functions of the plugin to existing maps and also the name to source location. - # - # @param [String] name of the plugin to be registered - # @param [String] path where the plugin is installed - def register_plugin(name, path) - @plugin_sources[name] = path - - save_index - end - - # Path where the index file is stored - def index_file - Plugin.root.join("index") - end end end diff --git a/lib/bundler/plugin/installer.rb b/lib/bundler/plugin/installer.rb index fbbde807ac..49d2f12f35 100644 --- a/lib/bundler/plugin/installer.rb +++ b/lib/bundler/plugin/installer.rb @@ -9,7 +9,7 @@ module Bundler # # @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 self.install(name, options) + def install(name, options) if options[:git] install_git(name, options) elsif options[:source] @@ -22,7 +22,9 @@ module Bundler end end - def self.install_git(name, options) + private + + def install_git(name, options) uri = options.delete(:git) options[:name] = name @@ -45,7 +47,7 @@ module Bundler # @param [Array, String] version (optional) of the gem to install # # @return [String] the path where the plugin was installed - def self.install_rubygems(name, source, version = [">= 0"]) + def install_rubygems(name, source, version = [">= 0"]) rg_source = Source::Rubygems.new "remotes" => source, :ignore_app_cache => true rg_source.remote! rg_source.dependency_names << name @@ -69,7 +71,7 @@ module Bundler # @raise [ArgumentError] if the spec object has no remote set # # @return [String] the path where the plugin was installed - def self.install_from_spec(spec) + def install_from_spec(spec) raise ArgumentError, "Spec #{spec.name} doesn't have remote set" unless spec.remote uri = spec.remote.uri |