Skip to content

Commit

Permalink
Cache summary stored in plugin about.yml [#5 state:resolved]
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Guidi committed May 16, 2008
1 parent 3b2e90f commit 1d12e4a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,3 +1,5 @@
* Cache summary stored in plugin about.yml [#5 state:resolved]

* Plugin serialization [#4 state:resolved]

* List all installed plugins [#3 state:resolved]
Expand Down
15 changes: 14 additions & 1 deletion lib/sashimi/plugin.rb
Expand Up @@ -26,6 +26,17 @@ def repository #:nodoc:
@repository ||= instantiate_repository
end

# Read the content of the <tt>about.yml</tt>.
# New feature of Rails 2.1.x http:://dev.rubyonrails.org/changeset/9098
def about
repository.about
end

# Return the plugin summary.
def summary
about['summary']
end

# Try to guess the plugin name.
def guess_name
name = File.basename(@url)
Expand All @@ -38,7 +49,9 @@ def guess_name

# Serialize the plugin to Hash format.
def to_hash
{self.guess_name => {'type' => repository.scm_type}}
{ self.guess_name =>
{ 'type' => repository.scm_type,
'summary' => self.summary } }
end

class << self
Expand Down
11 changes: 10 additions & 1 deletion lib/sashimi/repositories/abstract_repository.rb
Expand Up @@ -97,6 +97,14 @@ def scm_type
self.class.name.demodulize.gsub(/Repository$/, '').downcase
end

# Read the content of the <tt>about.yml</tt>.
# New feature of Rails 2.1.x http:://dev.rubyonrails.org/changeset/9098
def about
change_dir_to_plugin_path
return {} unless File.exists?('about.yml')
(YAML::load_file('about.yml') || {}).to_hash
end

private
# Proxy for <tt>AbstractRepository#change_dir</tt>
def change_dir(dir)
Expand All @@ -110,7 +118,7 @@ def change_dir_to_local_repository

# Change the current directory with the plugin one
def change_dir_to_plugin_path
change_dir(File.join(local_repository_path, plugin.name))
change_dir(File.join(local_repository_path, plugin.name || plugin.guess_name))
end

# Proxy for <tt>AbstractRepository#local_repository_path</tt>
Expand Down Expand Up @@ -148,6 +156,7 @@ def remove_from_cache

# Write all the plugins into the cache
def write_to_cache(plugins)
change_dir_to_local_repository
FileUtils.mv(cache_file, "#{cache_file}-backup")
File.open(cache_file, 'w'){|f| f.write(plugins.to_yaml)}
FileUtils.rm("#{cache_file}-backup")
Expand Down
13 changes: 11 additions & 2 deletions test/test_helper.rb
Expand Up @@ -12,6 +12,7 @@ def assert_not(condition, message = nil)
def initialize_repository_for_test(&block)
repository.prepare_installation
create_cache_file
create_plugins_directories
yield
remove_local_repository_path # make sure of clean up tmp dirs
end
Expand All @@ -33,7 +34,15 @@ def create_plugin(name, url = nil)
end

def cached_plugin
{'sashimi' => {'type' => 'git'}}
{'sashimi' => {'type' => 'git'}, 'plugin' => {'type' => 'svn'}}
end

def create_plugins_directories
AbstractRepository.change_dir_to_local_repository
FileUtils.mkdir('plugin') unless File.exists?('plugin')
FileUtils.cd('plugin')
File.open('about.yml', 'w+'){|f| f.write({'summary' => "Plugin summary"}.to_yaml)}
AbstractRepository.change_dir_to_local_repository
end

def create_cache_file
Expand All @@ -42,7 +51,7 @@ def create_cache_file

def remove_local_repository_path
FileUtils.rm_rf(File.join(repository.class.find_home, 'sashimi_test'))
end
end
end

module Sashimi
Expand Down
5 changes: 4 additions & 1 deletion test/unit/plugin_test.rb
Expand Up @@ -30,6 +30,9 @@ def test_should_instantiate_svn_repository_for_not_git_url
end

def test_should_serialize_to_hash
assert_equal({'sashimi' => {'type' => 'git'}}, plugin.to_hash)
initialize_repository_for_test do
expected = {'plugin' => {'type' => 'svn', 'summary' => 'Plugin summary'}}
assert_equal(expected, create_plugin('plugin', 'http://dev.repository.com/svn/plugin/trunk').to_hash)
end
end
end
4 changes: 2 additions & 2 deletions test/unit/repositories/abstract_repository_test.rb
Expand Up @@ -36,7 +36,7 @@ def test_should_recognize_git_url
# COMMANDS
def test_should_list_all_installed_plugins
initialize_repository_for_test do
assert_equal(['sashimi'], AbstractRepository.list)
assert_equal(['plugin', 'sashimi'], AbstractRepository.list)
end
end

Expand Down Expand Up @@ -88,7 +88,7 @@ def test_should_add_plugin_to_the_cache
def test_should_remove_plugin_from_cache
initialize_repository_for_test do
AbstractRepository.new(create_plugin('sashimi', '')).remove_from_cache
assert_equal({}, cache_content)
assert_equal({"plugin"=>{"type"=>"svn"}}, cache_content)
end
end

Expand Down

0 comments on commit 1d12e4a

Please sign in to comment.