Skip to content

Commit

Permalink
Added AbstractRepository#temp_plugin_name
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Guidi committed Jul 10, 2008
1 parent ac79561 commit 968aa69
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
20 changes: 13 additions & 7 deletions lib/sashimi/repositories/abstract_repository.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -283,22 +284,22 @@ 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.
#
# 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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions test/unit/repositories/abstract_repository_test.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 968aa69

Please sign in to comment.