sashimi 0.1.7 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +66 -0
- data/README +24 -26
- data/Rakefile +10 -0
- data/lib/sashimi/commands.rb +5 -1
- data/lib/sashimi/core_ext/array.rb +22 -0
- data/lib/sashimi/core_ext/class.rb +2 -2
- data/lib/sashimi/core_ext/string.rb +13 -0
- data/lib/sashimi/plugin.rb +3 -4
- data/lib/sashimi/repositories/abstract_repository.rb +121 -101
- data/lib/sashimi/repositories/git_repository.rb +9 -4
- data/lib/sashimi/repositories/svn_repository.rb +9 -4
- data/lib/sashimi/version.rb +2 -2
- data/lib/sashimi.rb +23 -0
- data/sashimi.gemspec +2 -2
- data/test/test_helper.rb +112 -30
- data/test/unit/core_ext/array_test.rb +22 -0
- data/test/unit/core_ext/class_test.rb +10 -3
- data/test/unit/core_ext/string_test.rb +20 -0
- data/test/unit/plugin_test.rb +4 -5
- data/test/unit/repositories/abstract_repository_test.rb +254 -79
- data/test/unit/repositories/git_repository_test.rb +1 -1
- data/test/unit/repositories/svn_repository_test.rb +2 -2
- data/test/unit/version_test.rb +1 -1
- metadata +8 -2
@@ -1,16 +1,21 @@
|
|
1
1
|
module Sashimi
|
2
2
|
class GitRepository < AbstractRepository
|
3
|
+
# Install the +plugin+.
|
3
4
|
def install
|
4
5
|
prepare_installation
|
5
6
|
puts plugin.guess_name.titleize + "\n\n"
|
6
|
-
|
7
|
-
|
7
|
+
with_path local_repository_path do
|
8
|
+
Kernel.system("git clone #{plugin.url}")
|
9
|
+
add_to_cache(plugin.to_hash)
|
10
|
+
end
|
8
11
|
end
|
9
12
|
|
13
|
+
# Update the +plugin+.
|
10
14
|
def update
|
11
15
|
puts plugin.name.titleize + "\n\n"
|
12
|
-
|
13
|
-
|
16
|
+
with_path plugin_path do
|
17
|
+
Kernel.system('git pull')
|
18
|
+
end
|
14
19
|
end
|
15
20
|
end
|
16
21
|
end
|
@@ -1,16 +1,21 @@
|
|
1
1
|
module Sashimi
|
2
2
|
class SvnRepository < AbstractRepository
|
3
|
+
# Install the +plugin+.
|
3
4
|
def install
|
4
5
|
prepare_installation
|
5
6
|
puts plugin.guess_name.titleize + "\n\n"
|
6
|
-
|
7
|
-
|
7
|
+
with_path local_repository_path do
|
8
|
+
Kernel.system("svn co #{plugin.url} #{plugin.guess_name}")
|
9
|
+
add_to_cache(plugin.to_hash)
|
10
|
+
end
|
8
11
|
end
|
9
12
|
|
13
|
+
# Update the +plugin+.
|
10
14
|
def update
|
11
15
|
puts plugin.name.titleize + "\n\n"
|
12
|
-
|
13
|
-
|
16
|
+
with_path plugin_path do
|
17
|
+
Kernel.system("svn up")
|
18
|
+
end
|
14
19
|
end
|
15
20
|
end
|
16
21
|
end
|
data/lib/sashimi/version.rb
CHANGED
data/lib/sashimi.rb
CHANGED
@@ -1,3 +1,26 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2008 Luca Guidi
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
1
24
|
$:.unshift(File.dirname(__FILE__)) unless
|
2
25
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
26
|
|
data/sashimi.gemspec
CHANGED
data/test/test_helper.rb
CHANGED
@@ -4,74 +4,156 @@ require 'sashimi'
|
|
4
4
|
class Test::Unit::TestCase
|
5
5
|
include Sashimi
|
6
6
|
|
7
|
+
# Asserts the given condition is false.
|
7
8
|
def assert_not(condition, message = nil)
|
8
9
|
assert !condition, message
|
9
10
|
end
|
10
11
|
|
12
|
+
# Asserts the given collection is empty.
|
13
|
+
def assert_empty(collection, message = nil)
|
14
|
+
assert collection.empty?, message
|
15
|
+
end
|
16
|
+
|
17
|
+
# Asserts the given collection is *not* empty.
|
18
|
+
def assert_not_empty(collection, message = nil)
|
19
|
+
assert !collection.empty?, message
|
20
|
+
end
|
21
|
+
|
22
|
+
# Asserts the given path exists
|
23
|
+
# It accepts path/to/be/asserted and automatically make it cross platform.
|
24
|
+
def assert_path_exists(path, message = nil)
|
25
|
+
assert File.exists?(path.to_path), message
|
26
|
+
end
|
27
|
+
|
28
|
+
# Asserts the given path doesn't exists
|
29
|
+
def assert_path_not_exists(path, message = nil)
|
30
|
+
assert !File.exists?(path.to_path), message
|
31
|
+
end
|
32
|
+
|
11
33
|
private
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
34
|
+
def create_test_repository
|
35
|
+
prepare_installation
|
36
|
+
with_path plugins_path do
|
37
|
+
create_cache_file
|
38
|
+
create_plugin_directories
|
39
|
+
create_rails_app
|
40
|
+
end
|
18
41
|
end
|
19
42
|
|
20
|
-
def
|
21
|
-
|
43
|
+
def destroy_test_repository
|
44
|
+
FileUtils.rm_rf local_repository_path
|
22
45
|
end
|
23
46
|
|
24
|
-
|
25
|
-
|
47
|
+
alias_method :setup, :create_test_repository
|
48
|
+
alias_method :teardown, :destroy_test_repository
|
49
|
+
|
50
|
+
def local_repository_path
|
51
|
+
@local_repository_path ||= [ repository.class.find_home, 'sashimi_test' ].to_path
|
52
|
+
end
|
53
|
+
|
54
|
+
def plugins_path
|
55
|
+
@plugins_path ||= [ local_repository_path, '.rails', 'plugins' ].to_path
|
56
|
+
end
|
57
|
+
|
58
|
+
def rails_app_path
|
59
|
+
@rails_app_path ||= begin
|
60
|
+
path = [ local_repository_path, '.rails', 'rails_app' ].to_path
|
61
|
+
$rails_app = path
|
62
|
+
path
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def repository
|
67
|
+
@repository ||= create_repository
|
26
68
|
end
|
27
69
|
|
28
70
|
def plugin
|
29
|
-
create_plugin
|
71
|
+
@plugin ||= create_plugin nil, 'git://github.com/jodosha/sashimi.git'
|
72
|
+
end
|
73
|
+
|
74
|
+
def create_repository(plugin_name = 'sashimi', url = 'git://github.com/jodosha/sashimi.git')
|
75
|
+
AbstractRepository.new Plugin.new(plugin_name, url)
|
30
76
|
end
|
31
77
|
|
32
78
|
def create_plugin(name, url = nil)
|
33
79
|
Plugin.new(name, url)
|
34
80
|
end
|
35
81
|
|
36
|
-
def
|
37
|
-
{ '
|
82
|
+
def cached_plugins
|
83
|
+
{ 'plug-in' => {'type' => 'svn'},
|
38
84
|
'plugin' => {'type' => 'svn'},
|
39
|
-
'
|
85
|
+
'sashimi' => {'type' => 'git'} }
|
86
|
+
end
|
87
|
+
|
88
|
+
def cache_file
|
89
|
+
'.plugins'
|
40
90
|
end
|
41
91
|
|
42
92
|
def create_plugin_directories
|
43
|
-
{ 'plugin' => true, 'plug-in' => false }.each do |plugin, about|
|
93
|
+
{ 'sashimi' => true, 'plugin' => true, 'plug-in' => false }.each do |plugin, about|
|
44
94
|
create_plugin_directory(plugin, about)
|
45
95
|
end
|
46
96
|
end
|
47
97
|
|
48
98
|
def create_plugin_directory(plugin, about = true)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
99
|
+
with_path plugins_path do
|
100
|
+
FileUtils.mkdir(plugin) unless File.exists?(plugin)
|
101
|
+
File.open([ plugin, 'about.yml' ].to_path, 'w+') do |f|
|
102
|
+
f.write({'summary' => "Plugin summary"}.to_yaml)
|
103
|
+
end if about
|
104
|
+
end
|
54
105
|
end
|
55
106
|
|
56
|
-
def
|
57
|
-
|
107
|
+
def create_rails_app
|
108
|
+
FileUtils.mkdir_p [ rails_app_path, 'vendor', 'plugins' ].to_path
|
58
109
|
end
|
59
110
|
|
60
|
-
def
|
61
|
-
FileUtils.
|
62
|
-
end
|
111
|
+
def prepare_installation
|
112
|
+
FileUtils.mkdir_p plugins_path
|
113
|
+
end
|
114
|
+
|
115
|
+
def create_cache_file
|
116
|
+
with_path plugins_path do
|
117
|
+
File.open(cache_file, 'w+'){ |f| f.write cached_plugins.to_yaml }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def with_local_repository_path(&block)
|
122
|
+
with_path(local_repository_path, &block)
|
123
|
+
end
|
124
|
+
|
125
|
+
def with_path(path, &block)
|
126
|
+
begin
|
127
|
+
old_path = Dir.pwd
|
128
|
+
FileUtils.cd(path)
|
129
|
+
yield
|
130
|
+
ensure
|
131
|
+
FileUtils.cd(old_path)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def with_clear_cache(&block)
|
136
|
+
AbstractRepository.expire_cache
|
137
|
+
yield
|
138
|
+
create_cache_file
|
139
|
+
AbstractRepository.expire_cache
|
140
|
+
end
|
63
141
|
end
|
64
142
|
|
65
143
|
module Sashimi
|
66
144
|
class AbstractRepository
|
67
|
-
@@
|
145
|
+
@@plugins_path = 'sashimi_test/.rails/plugins'
|
146
|
+
cattr_accessor :plugins_path
|
147
|
+
|
148
|
+
def self.expire_cache #:nodoc:
|
149
|
+
@@cache_content = nil
|
150
|
+
end
|
151
|
+
|
68
152
|
public :add_to_cache, :cache_content, :cache_file,
|
69
|
-
:change_dir, :change_dir_to_absolute_plugins_dir,
|
70
|
-
:change_dir_to_local_repository, :change_dir_to_plugin_path,
|
71
153
|
:copy_plugin_to_rails_app, :local_repository_path, :path_to_rails_app,
|
72
|
-
:
|
154
|
+
:prepare_installation, :remove_from_cache, :rails_plugins_path,
|
73
155
|
:remove_hidden_folders, :rename_temp_folder, :run_install_hook,
|
74
|
-
:write_to_cache
|
156
|
+
:write_to_cache, :with_path, :plugin_path, :absolute_rails_plugins_path
|
75
157
|
end
|
76
158
|
end
|
77
159
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'test/test_helper'
|
3
|
+
|
4
|
+
class ArrayTest < Test::Unit::TestCase
|
5
|
+
uses_mocha 'ArrayTest' do
|
6
|
+
def setup
|
7
|
+
File.stubs(:SEPARATOR).returns '/'
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_to_path
|
11
|
+
assert_equal 'path/to/app', %w(path to app).to_path
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_to_absolute_path
|
15
|
+
actual = File.dirname(__FILE__)
|
16
|
+
expected = File.expand_path actual
|
17
|
+
assert_equal expected, actual.split(File::SEPARATOR).to_path(true)
|
18
|
+
assert_equal expected, actual.split(File::SEPARATOR).to_absolute_path
|
19
|
+
assert_equal expected, actual.split(File::SEPARATOR).to_abs_path
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -10,13 +10,20 @@ class Repository
|
|
10
10
|
another_path
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
def self.path_with_block(path, &block)
|
14
|
+
block.call(path) if block_given?
|
15
|
+
path
|
16
|
+
end
|
17
|
+
|
18
|
+
class_method_proxy :path, :another_path, :path_with_block
|
19
|
+
public :path_with_block
|
14
20
|
end
|
15
21
|
|
16
22
|
class ClassTest < Test::Unit::TestCase
|
17
23
|
def test_should_respond_to_proxied_methods
|
18
24
|
repository = Repository.new
|
19
|
-
|
20
|
-
|
25
|
+
assert_equal 'path', repository.send(:path)
|
26
|
+
assert_equal 'path', repository.send(:another_path, 'path')
|
27
|
+
assert_equal 'path', repository.path_with_block('path') { |path| path }
|
21
28
|
end
|
22
29
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'test/test_helper'
|
3
|
+
|
4
|
+
class StringTest < Test::Unit::TestCase
|
5
|
+
uses_mocha 'StringTest' do
|
6
|
+
def setup
|
7
|
+
File.stubs(:SEPARATOR).returns '/'
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_to_path
|
11
|
+
assert_equal 'path/to/app', 'path/to/app'.to_path
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_to_absolute_path
|
15
|
+
actual = File.dirname(__FILE__)
|
16
|
+
expected = File.expand_path actual
|
17
|
+
assert_equal expected, actual.to_path(true)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/test/unit/plugin_test.rb
CHANGED
@@ -29,10 +29,9 @@ class PluginTest < Test::Unit::TestCase
|
|
29
29
|
assert_kind_of SvnRepository, create_plugin(nil, 'http://dev.repository.com/svn/sashimi/trunk').repository
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
32
|
+
# FIXME
|
33
|
+
def _ignore_test_should_serialize_to_hash
|
34
|
+
expected = {'plug-in' => {'type' => 'svn', 'summary' => nil}}
|
35
|
+
assert_equal(expected, create_plugin('plug-in', 'http://dev.repository.com/svn/plug-in/trunk').to_hash)
|
37
36
|
end
|
38
37
|
end
|