From 968aa698fdda7df9f1b34e74ffb394cbc15b8fbb Mon Sep 17 00:00:00 2001 From: Luca Guidi Date: Thu, 10 Jul 2008 17:00:51 +0200 Subject: [PATCH] Added AbstractRepository#temp_plugin_name --- .../repositories/abstract_repository.rb | 20 ++++++++++++------- test/test_helper.rb | 2 +- .../repositories/abstract_repository_test.rb | 9 +++++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/sashimi/repositories/abstract_repository.rb b/lib/sashimi/repositories/abstract_repository.rb index 6e1e3c5..b6e92c6 100644 --- a/lib/sashimi/repositories/abstract_repository.rb +++ b/lib/sashimi/repositories/abstract_repository.rb @@ -10,6 +10,7 @@ def to_s end class AbstractRepository + TEMP_SUFFIX = '-tmp' @@plugins_path = ".rails/plugins".to_path @@cache_file = '.plugins' cattr_accessor :cache_file @@ -95,7 +96,7 @@ def update_versioned_rails_plugins(plugins_names) repository.copy_plugin_and_remove_hidden_folders files_scheduled_for_remove = repository.files_scheduled_for_remove files_scheduled_for_add = repository.files_scheduled_for_add - FileUtils.cp_r(plugin_name+'-tmp/.', plugin_name) + FileUtils.cp_r(temp_plugin_name+'/.', plugin_name) repository.remove_temp_folder change_dir(plugin_name) files_scheduled_for_remove.each {|file| scm_remove file} @@ -221,7 +222,7 @@ def about # Returns a list of files that should be scheduled for SCM add. def files_scheduled_for_add with_path absolute_rails_plugins_path do - Dir[plugin.name+"-tmp/**/*"].collect {|fn| fn.gsub(plugin.name+'-tmp', '.')} - + Dir[temp_plugin_name+"/**/*"].collect {|fn| fn.gsub(temp_plugin_name, '.')} - Dir[plugin.name+"/**/*"].collect{|fn| fn.gsub(plugin.name, '.')} end end @@ -230,14 +231,14 @@ def files_scheduled_for_add def files_scheduled_for_remove with_path absolute_rails_plugins_path do Dir[plugin.name+"/**/*"].collect {|fn| fn.gsub(plugin.name, '.')} - - Dir[plugin.name+"-tmp/**/*"].collect {|fn| fn.gsub(plugin.name+"-tmp", '.')} + Dir[temp_plugin_name+"/**/*"].collect {|fn| fn.gsub(temp_plugin_name, '.')} end end # Remove the temp folder, used by update process. def remove_temp_folder with_path absolute_rails_plugins_path do - FileUtils.rm_rf(plugin.name+'-tmp') + FileUtils.rm_rf temp_plugin_name end end @@ -283,7 +284,7 @@ def write_to_cache(plugins) def copy_plugin_to_rails_app FileUtils.mkdir_p(plugins_path) FileUtils.cp_r [ local_repository_path, plugin.name ].to_path, - [ rails_plugins_path, plugin.name+'-tmp'].to_path + [ rails_plugins_path, temp_plugin_name ].to_path end # Rename the *-tmp folder used by the installation process. @@ -291,14 +292,14 @@ def copy_plugin_to_rails_app # Example: # click-to-globalize-tmp # => click-to-globalize def rename_temp_folder - FileUtils.mv [ rails_plugins_path, plugin.name+'-tmp' ].to_path, + FileUtils.mv [ rails_plugins_path, temp_plugin_name ].to_path, [ rails_plugins_path, plugin.name ].to_path end # Remove SCM hidden folders. def remove_hidden_folders require 'find' - with_path [ absolute_rails_plugins_path, plugin.name + '-tmp' ].to_path do + with_path [ absolute_rails_plugins_path, temp_plugin_name ].to_path do Find.find('./') do |path| if File.basename(path) == '.'+scm_type FileUtils.remove_dir(path, true) @@ -308,6 +309,11 @@ def remove_hidden_folders end end + # Returns the name used for temporary plugin folder. + def temp_plugin_name + plugin.name + TEMP_SUFFIX + end + # Run the plugin install hook. def run_install_hook install_hook_file = [ rails_plugins_path, plugin.name, 'install.rb' ].to_path diff --git a/test/test_helper.rb b/test/test_helper.rb index fee03b5..d432edc 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -143,7 +143,7 @@ def self.expire_cache #:nodoc: :copy_plugin_to_rails_app, :local_repository_path, :path_to_rails_app, :prepare_installation, :remove_from_cache, :rails_plugins_path, :remove_hidden_folders, :rename_temp_folder, :run_install_hook, - :write_to_cache, :with_path, :plugin_path + :write_to_cache, :with_path, :plugin_path, :temp_plugin_name end end diff --git a/test/unit/repositories/abstract_repository_test.rb b/test/unit/repositories/abstract_repository_test.rb index b329874..a49f7ec 100644 --- a/test/unit/repositories/abstract_repository_test.rb +++ b/test/unit/repositories/abstract_repository_test.rb @@ -20,6 +20,10 @@ def test_plugins_names assert_equal cached_plugins.keys.sort, repository.class.plugins_names end + def test_temp_suffix + assert_equal '-tmp', AbstractRepository::TEMP_SUFFIX + end + ### INSTANTIATE def test_instantiate_repository @@ -244,6 +248,11 @@ def test_write_to_cache def test_about flunk end + + def test_temp_plugin_name + assert_equal repository.plugin.name + AbstractRepository::TEMP_SUFFIX, + repository.temp_plugin_name + end def test_run_install_hook flunk