sashimi 0.1.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/CHANGELOG
CHANGED
@@ -1,3 +1,69 @@
|
|
1
|
+
* *v0.2.0*
|
2
|
+
|
3
|
+
* Tagged v0.2.0
|
4
|
+
|
5
|
+
* Prepare for v0.2.0
|
6
|
+
|
7
|
+
* Ignored flunked test cases
|
8
|
+
|
9
|
+
* Massive changelog
|
10
|
+
|
11
|
+
* rdoc formatting
|
12
|
+
|
13
|
+
* Using, where possible, @@class_variable and cattr_reader instead of class methods. Documentation improvements.
|
14
|
+
|
15
|
+
* Don't try to remove the gem from working copy at the beginning of Rake install
|
16
|
+
|
17
|
+
* Print plugin name when execute uninstall command
|
18
|
+
|
19
|
+
* Aliased #cache_content with #list in order to clean up AbstractRepository from stdout formattin code. The code was moved to Commands::List
|
20
|
+
|
21
|
+
* Clean up for #with_path in test_helper.rb
|
22
|
+
|
23
|
+
* Removed with_path from #files_scheduled_for_add and #files_scheduled_for_remove because #update_versioned_rails_plugins already works in vendor/plugins
|
24
|
+
|
25
|
+
* Removed unnecessary with_path statement from AbstractRepository#prepare_installation
|
26
|
+
|
27
|
+
* Removed unnecessary with_path statement from AbstractRepository#remove_temp_folder
|
28
|
+
|
29
|
+
* Removed unnecessary with_path statement from AbstractRepository#update_unversioned_rails_plugins
|
30
|
+
|
31
|
+
* Removed with_path from #update_rails_plugins, because update command should be always executed from the root of a Rails app
|
32
|
+
|
33
|
+
* Removed unnecessary with_path statement from AbstractRepository#copy_plugin_to_rails_app
|
34
|
+
|
35
|
+
* Removed unnecessary with_path statement for AbstractRepository#write_to_cache
|
36
|
+
|
37
|
+
* Remove builded gem from working copy, after rake install task
|
38
|
+
|
39
|
+
* Don't generate rdoc and ri on Rake install
|
40
|
+
|
41
|
+
* Fixed AbstractRepository#update_versioned_rails_plugins. Made AbstractRepository#temp_plugin_name public
|
42
|
+
|
43
|
+
* Created install Rake task
|
44
|
+
|
45
|
+
* Improved test coverage for AbstractRepository
|
46
|
+
|
47
|
+
* Added AbstractRepository#temp_plugin_name
|
48
|
+
|
49
|
+
* File#join -> Array#to_path or String#to_path. Code cleanup.
|
50
|
+
|
51
|
+
* Improved tests for AbstractRepository cache and instantiation
|
52
|
+
|
53
|
+
* Improved test coverage for AbstractRepository
|
54
|
+
|
55
|
+
* Added tests for uninstall. Re-enabled tests.
|
56
|
+
|
57
|
+
* Initial rewriting of test suite
|
58
|
+
|
59
|
+
* Added String#to_path and Array#to_path
|
60
|
+
|
61
|
+
* Added AbstractRepository#with_path in order to scopify current directory changes
|
62
|
+
|
63
|
+
* Added block support to Class#class_method_proxy
|
64
|
+
|
65
|
+
|
66
|
+
|
1
67
|
* *v0.1.7*
|
2
68
|
|
3
69
|
* Tagged v0.1.7
|
data/README
CHANGED
@@ -1,82 +1,80 @@
|
|
1
|
-
Sashimi
|
2
|
-
=======
|
1
|
+
= Sashimi
|
3
2
|
|
4
3
|
Sashimi is a Rails plugins manager.
|
4
|
+
|
5
5
|
It allows to install your favourite plugins in a local repository and add them to your Rails apps.
|
6
6
|
The main goal is to allow the plugins offline installation.
|
7
7
|
|
8
8
|
|
9
9
|
|
10
|
-
Installation
|
11
|
-
============
|
10
|
+
= Installation
|
12
11
|
|
13
|
-
$ (sudo) gem install sashimi
|
12
|
+
$ (sudo) gem install sashimi
|
14
13
|
|
15
14
|
or
|
16
15
|
|
17
|
-
$ (sudo) gem install jodosha-sashimi --source=http://gems.github.com
|
16
|
+
$ (sudo) gem install jodosha-sashimi --source=http://gems.github.com
|
18
17
|
|
19
18
|
|
20
19
|
|
21
|
-
Usage
|
22
|
-
=====
|
20
|
+
= Usage
|
23
21
|
|
24
22
|
Install a plugin from a subversion URL:
|
25
|
-
$ sashimi install http://dev.rubyonrails.com/svn/rails/plugins/continuous_builder
|
23
|
+
$ sashimi install http://dev.rubyonrails.com/svn/rails/plugins/continuous_builder
|
26
24
|
|
27
25
|
Install a plugin from a git URL:
|
28
|
-
$ sashimi install git://github.com/jodosha/click-to-globalize.git
|
26
|
+
$ sashimi install git://github.com/jodosha/click-to-globalize.git
|
29
27
|
|
30
28
|
Uninstall a plugin:
|
31
|
-
$ sashimi uninstall continuous_builder
|
29
|
+
$ sashimi uninstall continuous_builder
|
32
30
|
|
33
31
|
Update a plugin:
|
34
|
-
$ sashimi update click-to-globalize
|
32
|
+
$ sashimi update click-to-globalize
|
35
33
|
|
36
34
|
Update a plugin of a Rails app:
|
37
|
-
$ sashimi update --rails click-to-globalize
|
35
|
+
$ sashimi update --rails click-to-globalize
|
38
36
|
|
39
37
|
NOTE: If your application is versioned with Svn or Git, Sashimi will automatically schedules for add/remove the added/removed files.
|
40
38
|
|
41
39
|
List all installed plugins:
|
42
|
-
$ sashimi list
|
40
|
+
$ sashimi list
|
43
41
|
|
44
42
|
Add installed plugin(s) to a Rails app:
|
45
|
-
$ sashimi add click-to-globalize
|
46
|
-
|
43
|
+
$ sashimi add click-to-globalize
|
44
|
+
or
|
45
|
+
$ sashimi install --rails click-to-globalize
|
47
46
|
|
48
47
|
|
49
48
|
|
50
|
-
Known And Common Issues
|
51
|
-
=======================
|
49
|
+
= Known And Common Issues
|
52
50
|
|
53
51
|
* When add a plugin to an app, make sure your current directory is the rails root.
|
54
52
|
|
55
53
|
* Only Subversion and Git repositories are currently supported.
|
56
54
|
|
57
55
|
|
58
|
-
Contribute
|
59
|
-
==========
|
56
|
+
= Contribute
|
60
57
|
|
61
58
|
* Check out the code and test it:
|
59
|
+
|
62
60
|
$ git clone git://github.com/jodosha/sashimi.git
|
61
|
+
|
63
62
|
$ rake
|
64
63
|
|
65
|
-
* Create a ticket to
|
64
|
+
* Create a ticket to the {Sushistar Lighthouse page}[http://sushistar.lighthouseapp.com]
|
66
65
|
|
67
66
|
* Create a patch and add as attachement to the ticket.
|
68
67
|
|
69
68
|
|
70
|
-
Credits
|
71
|
-
=======
|
69
|
+
= Credits
|
72
70
|
|
73
71
|
Partially inspired to RaPT[http://rapt.rubyforge.org/].
|
74
72
|
|
75
73
|
|
76
74
|
|
77
|
-
Home Page
|
78
|
-
|
79
|
-
http://lucaguidi.com/pages/sashimi
|
75
|
+
= Home Page
|
76
|
+
|
77
|
+
The Sashimi homepage is http://lucaguidi.com/pages/sashimi
|
80
78
|
|
81
79
|
|
82
80
|
|
data/Rakefile
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
$:.unshift 'lib'
|
1
2
|
require 'rake'
|
2
3
|
require 'rake/testtask'
|
3
4
|
require 'rake/rdoctask'
|
@@ -20,3 +21,12 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
20
21
|
rdoc.rdoc_files.include('README')
|
21
22
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
23
|
end
|
24
|
+
|
25
|
+
desc 'Build and install the gem (useful for development purposes).'
|
26
|
+
task :install do
|
27
|
+
require 'sashimi'
|
28
|
+
system "gem build sashimi.gemspec"
|
29
|
+
system "sudo gem uninstall sashimi"
|
30
|
+
system "sudo gem install --local --no-rdoc --no-ri sashimi-#{Sashimi::VERSION::STRING}.gem"
|
31
|
+
system "rm sashimi-*.gem"
|
32
|
+
end
|
data/lib/sashimi/commands.rb
CHANGED
@@ -125,6 +125,7 @@ module Sashimi
|
|
125
125
|
def parse!(args)
|
126
126
|
options.parse!(args)
|
127
127
|
args.each do |name|
|
128
|
+
puts name.titleize + "\n"
|
128
129
|
Plugin.new(name).uninstall
|
129
130
|
end
|
130
131
|
end
|
@@ -179,7 +180,10 @@ module Sashimi
|
|
179
180
|
|
180
181
|
def parse!(args)
|
181
182
|
options.parse!(args)
|
182
|
-
|
183
|
+
output = Plugin.list.sort.collect do |plugin, contents|
|
184
|
+
"#{plugin}\t\t#{contents['summary']}"
|
185
|
+
end.join("\n")
|
186
|
+
puts output
|
183
187
|
end
|
184
188
|
end
|
185
189
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Array
|
2
|
+
# Transform the current +Array+ to a path.
|
3
|
+
#
|
4
|
+
# It's an alias for <tt>File#join</tt>.
|
5
|
+
#
|
6
|
+
# %w(path to app).to_path # => path/to/app+
|
7
|
+
# %w(path to app).to_path(true) # => /Users/luca/path/to/app
|
8
|
+
def to_path(absolute = false)
|
9
|
+
path = File.join(self)
|
10
|
+
path = File.expand_path(path) if absolute
|
11
|
+
path
|
12
|
+
end
|
13
|
+
|
14
|
+
# Transform the current +Array+ to an absolute path.
|
15
|
+
#
|
16
|
+
# %w(path to app).to_absolute_path # => /Users/luca/path/to/app
|
17
|
+
# %w(path to app).to_abs_path # => /Users/luca/path/to/app
|
18
|
+
def to_absolute_path
|
19
|
+
to_path(true)
|
20
|
+
end
|
21
|
+
alias_method :to_abs_path, :to_absolute_path
|
22
|
+
end
|
@@ -21,8 +21,8 @@ class Class
|
|
21
21
|
method_names.each do |m|
|
22
22
|
self.class_eval %{
|
23
23
|
# Proxy method for <tt>#{self.class.name}##{m}</tt>
|
24
|
-
def #{m}(*args)
|
25
|
-
self.class.#{m}(*args)
|
24
|
+
def #{m}(*args, &block)
|
25
|
+
self.class.#{m}(*args, &block)
|
26
26
|
end
|
27
27
|
private :#{m}
|
28
28
|
}, __FILE__, __LINE__
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class String
|
2
|
+
# Transform the current +String+ to a system path,
|
3
|
+
# according to the current platform file system.
|
4
|
+
#
|
5
|
+
# "path/to/app".to_path # => path/to/app (on *nix)
|
6
|
+
# "path/to/app".to_path # => path\to\app (on Windows)
|
7
|
+
#
|
8
|
+
# "path/to/app".to_path(true) # => /Users/luca/path/to/app (on *nix)
|
9
|
+
# "path/to/app".to_path(true) # => C:\path\to\app (on Windows)
|
10
|
+
def to_path(absolute = false)
|
11
|
+
self.split(/\/\\/).to_path(absolute)
|
12
|
+
end
|
13
|
+
end
|
data/lib/sashimi/plugin.rb
CHANGED
@@ -30,9 +30,8 @@ module Sashimi
|
|
30
30
|
def repository #:nodoc:
|
31
31
|
@repository ||= instantiate_repository
|
32
32
|
end
|
33
|
-
|
34
|
-
#
|
35
|
-
# New feature of Rails 2.1.x http:://dev.rubyonrails.org/changeset/9098
|
33
|
+
|
34
|
+
# Returns the informations about the plugin.
|
36
35
|
def about
|
37
36
|
@about ||= repository.about
|
38
37
|
end
|
@@ -52,7 +51,7 @@ module Sashimi
|
|
52
51
|
name
|
53
52
|
end
|
54
53
|
|
55
|
-
# Serialize the plugin to Hash format.
|
54
|
+
# Serialize the plugin to +Hash+ format.
|
56
55
|
def to_hash
|
57
56
|
{ self.guess_name =>
|
58
57
|
{ 'type' => repository.scm_type,
|
@@ -1,49 +1,63 @@
|
|
1
1
|
module Sashimi
|
2
2
|
class PluginNotFound < StandardError #:nodoc:
|
3
3
|
def initialize(plugin_name, message = nil)
|
4
|
-
@plugin_name = plugin_name
|
5
|
-
@message = message
|
4
|
+
@plugin_name, @message = plugin_name, message
|
6
5
|
end
|
7
6
|
|
8
7
|
def to_s
|
9
|
-
@message || @plugin_name + " isn't in the local repository."
|
8
|
+
@message || @plugin_name.to_s + " isn't in the local repository."
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
13
12
|
class AbstractRepository
|
14
|
-
|
13
|
+
TEMP_SUFFIX = '-tmp'
|
14
|
+
|
15
|
+
# It's the path where the plugins are stored.
|
16
|
+
@@plugins_path = ".rails/plugins".to_path
|
17
|
+
|
18
|
+
# Conventional path where Rails applications use to place their plugins.
|
19
|
+
@@rails_plugins_path = "vendor/plugins".to_path
|
20
|
+
cattr_reader :rails_plugins_path
|
21
|
+
|
22
|
+
# Cache file used to store informations about installed plugins.
|
15
23
|
@@cache_file = '.plugins'
|
16
24
|
cattr_accessor :cache_file
|
17
25
|
|
18
|
-
|
26
|
+
attr_reader :plugin
|
19
27
|
|
20
28
|
def initialize(plugin)
|
21
|
-
|
29
|
+
@plugin = plugin
|
22
30
|
end
|
23
31
|
|
24
|
-
#
|
32
|
+
# Uninstall the current plugin.
|
25
33
|
def uninstall
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
34
|
+
with_path local_repository_path do
|
35
|
+
raise PluginNotFound.new(plugin.name) unless File.exists?(plugin.name)
|
36
|
+
FileUtils.rm_rf(plugin.name)
|
37
|
+
remove_from_cache
|
38
|
+
end
|
30
39
|
end
|
31
40
|
|
32
|
-
# Add to a Rails app.
|
41
|
+
# Add the current plugin to a Rails app.
|
33
42
|
def add
|
43
|
+
raise PluginNotFound.new(plugin.name) unless cache_content.keys.include?(plugin.name)
|
34
44
|
puts plugin.name.titleize + "\n"
|
35
45
|
copy_plugin_and_remove_hidden_folders
|
36
46
|
rename_temp_folder
|
37
47
|
run_install_hook
|
38
48
|
end
|
39
49
|
|
40
|
-
# Copy a plugin to a Rails app and remove SCM hidden folders
|
50
|
+
# Copy a plugin to a Rails app and remove SCM hidden folders.
|
41
51
|
def copy_plugin_and_remove_hidden_folders
|
42
52
|
copy_plugin_to_rails_app
|
43
|
-
remove_hidden_folders
|
53
|
+
remove_hidden_folders
|
44
54
|
end
|
45
55
|
|
46
56
|
class << self
|
57
|
+
# Instantiate a repository (Svn or Git) for the given plugin.
|
58
|
+
#
|
59
|
+
# If the plugin was already installed it load from the cache,
|
60
|
+
# otherwise it try to guess information from its url.
|
47
61
|
def instantiate_repository(plugin)
|
48
62
|
unless plugin.name.nil?
|
49
63
|
instantiate_repository_by_cache(plugin)
|
@@ -52,21 +66,16 @@ module Sashimi
|
|
52
66
|
end.new(plugin)
|
53
67
|
end
|
54
68
|
|
55
|
-
# Return all installed plugin names and summary, formatted for stdout.
|
56
|
-
def list
|
57
|
-
cache_content.sort.collect do |plugin, contents|
|
58
|
-
"#{plugin}\t\t#{contents['summary']}"
|
59
|
-
end.join("\n")
|
60
|
-
end
|
61
|
-
|
62
69
|
# Return all installed plugins names.
|
63
70
|
def plugins_names
|
64
71
|
cache_content.keys.sort
|
65
72
|
end
|
66
73
|
|
67
74
|
# Update the plugins installed in a rails app.
|
75
|
+
#
|
76
|
+
# If the application is under version control, +Sashimi+ cares about to
|
77
|
+
# schedule add/remove plugin's files from/to your SCM of choice.
|
68
78
|
def update_rails_plugins(plugins_names)
|
69
|
-
change_dir(path_to_rails_app)
|
70
79
|
if under_version_control?
|
71
80
|
update_versioned_rails_plugins(plugins_names)
|
72
81
|
else
|
@@ -74,37 +83,39 @@ module Sashimi
|
|
74
83
|
end
|
75
84
|
end
|
76
85
|
|
77
|
-
# Update the plugins installed in a
|
86
|
+
# Update the plugins installed in a <b>not versioned</b> Rails app.
|
78
87
|
def update_unversioned_rails_plugins(plugins_names)
|
79
|
-
change_dir(plugins_dir)
|
80
88
|
plugins_names.each do |plugin_name|
|
81
|
-
FileUtils.rm_rf
|
89
|
+
FileUtils.rm_rf [ absolute_rails_plugins_path, plugin_name ].to_path
|
82
90
|
Plugin.new(plugin_name).add
|
83
91
|
end
|
84
92
|
end
|
85
93
|
|
86
|
-
# Update the plugins installed in a versioned
|
94
|
+
# Update the plugins installed in a <b>versioned</b> Rails app.
|
87
95
|
def update_versioned_rails_plugins(plugins_names)
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
96
|
+
with_path absolute_rails_plugins_path do
|
97
|
+
plugins_names.each do |plugin_name|
|
98
|
+
raise PluginNotFound.new(plugin_name) unless File.exists?(plugin_name)
|
99
|
+
repository = Plugin.new(plugin_name).repository
|
100
|
+
repository.copy_plugin_and_remove_hidden_folders
|
101
|
+
files_scheduled_for_remove = repository.files_scheduled_for_remove
|
102
|
+
files_scheduled_for_add = repository.files_scheduled_for_add
|
103
|
+
FileUtils.cp_r(repository.temp_plugin_name+'/.', plugin_name)
|
104
|
+
repository.remove_temp_folder
|
105
|
+
with_path plugin_name do
|
106
|
+
files_scheduled_for_remove.each {|file| scm_remove file}
|
107
|
+
files_scheduled_for_add.each {|file| scm_add file}
|
108
|
+
end
|
109
|
+
end
|
100
110
|
end
|
101
111
|
end
|
102
112
|
|
103
|
-
# Schedules an add for the given file on the current SCM system used by the Rails app.
|
113
|
+
# Schedules an <b>add</b> for the given file on the current SCM system used by the Rails app.
|
104
114
|
def scm_add(file)
|
105
115
|
scm_command(:add, file)
|
106
116
|
end
|
107
117
|
|
118
|
+
# Schedules a <b>remove</b> for the given file on the current SCM system used by the Rails app.
|
108
119
|
def scm_remove(file)
|
109
120
|
scm_command(:rm, file)
|
110
121
|
end
|
@@ -112,55 +123,51 @@ module Sashimi
|
|
112
123
|
# Execute the given command for the current SCM system used by the Rails app.
|
113
124
|
def scm_command(command, file)
|
114
125
|
scm = guess_version_control_system
|
115
|
-
system("#{scm} #{command} #{file}")
|
126
|
+
Kernel.system("#{scm} #{command} #{file}")
|
116
127
|
end
|
117
128
|
|
129
|
+
# It's the absolute path where the plugins are stored.
|
130
|
+
#
|
131
|
+
# Typically, it's under your home directory.
|
118
132
|
def local_repository_path #:nodoc:
|
119
|
-
@local_repository_path ||=
|
133
|
+
@local_repository_path ||= [ find_home, @@plugins_path ].to_path
|
120
134
|
end
|
121
135
|
|
122
|
-
# Return the path to the Rails app where the user launched sashimi command.
|
136
|
+
# Return the path to the Rails app where the user launched <tt>sashimi</tt> command.
|
123
137
|
def path_to_rails_app
|
124
138
|
$rails_app
|
125
139
|
end
|
126
140
|
|
127
141
|
# Read the cache file and return the content as an <tt>Hash</tt>.
|
128
142
|
def cache_content
|
129
|
-
|
130
|
-
|
143
|
+
with_path local_repository_path do
|
144
|
+
@@cache_content ||= (YAML::load_file(cache_file) || {}).to_hash
|
145
|
+
end
|
131
146
|
end
|
147
|
+
alias_method :list, :cache_content
|
132
148
|
|
149
|
+
# Istantiate a +Repository+ for the given +plugin+, guessing if its url
|
150
|
+
# refers to a Svn or Git repository.
|
133
151
|
def instantiate_repository_by_url(plugin)
|
134
152
|
git_url?(plugin.url) ? GitRepository : SvnRepository
|
135
153
|
end
|
136
154
|
|
155
|
+
# Instantiate a repository for the given +plugin+, loading informations
|
156
|
+
# from the cache.
|
137
157
|
def instantiate_repository_by_cache(plugin)
|
138
158
|
cached_plugin = cache_content[plugin.name]
|
139
159
|
raise PluginNotFound.new(plugin.name) if cached_plugin.nil?
|
140
160
|
cached_plugin['type'] == 'git' ? GitRepository : SvnRepository
|
141
161
|
end
|
142
|
-
|
143
|
-
#
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
def change_dir_to_local_repository
|
150
|
-
change_dir(local_repository_path)
|
151
|
-
end
|
152
|
-
|
153
|
-
# Change the current directory with the fully qualified
|
154
|
-
# path to Rails app and plugins_dir.
|
155
|
-
def change_dir_to_absolute_plugins_dir
|
156
|
-
change_dir(File.join(File.expand_path(path_to_rails_app), plugins_dir))
|
157
|
-
end
|
158
|
-
|
159
|
-
# Rails app plugins dir
|
160
|
-
def plugins_dir
|
161
|
-
@@plugins_dir ||= File.join('vendor', 'plugins')
|
162
|
+
|
163
|
+
# It's absolute path of plugins in your Rails app.
|
164
|
+
#
|
165
|
+
# path/to/rails_app # => /Users/luca/path/to/rails_app/vendor/plugins
|
166
|
+
def absolute_rails_plugins_path
|
167
|
+
@@absolute_rails_plugins_path = [ path_to_rails_app,
|
168
|
+
rails_plugins_path ].to_path(true)
|
162
169
|
end
|
163
|
-
|
170
|
+
|
164
171
|
# Check if the current working directory is under version control
|
165
172
|
def under_version_control?
|
166
173
|
!Dir.glob(".{git,svn}").empty?
|
@@ -194,6 +201,17 @@ module Sashimi
|
|
194
201
|
def git_url?(url)
|
195
202
|
url =~ /^git:\/\// || url =~ /\.git$/
|
196
203
|
end
|
204
|
+
|
205
|
+
# Yield the given block executing it in the specified path
|
206
|
+
def with_path(path, &block)
|
207
|
+
begin
|
208
|
+
old_path = Dir.pwd
|
209
|
+
FileUtils.cd(path)
|
210
|
+
yield
|
211
|
+
ensure
|
212
|
+
FileUtils.cd(old_path)
|
213
|
+
end
|
214
|
+
end
|
197
215
|
end
|
198
216
|
|
199
217
|
# Return the SCM type
|
@@ -205,48 +223,50 @@ module Sashimi
|
|
205
223
|
end
|
206
224
|
|
207
225
|
# Read the content of the <tt>about.yml</tt>.
|
208
|
-
#
|
226
|
+
#
|
227
|
+
# New feature of Rails 2.1.0 http://github.com/rails/rails/commit/f5b991d76dc5d21f1870da067fb3101440256fba
|
209
228
|
def about
|
210
|
-
|
211
|
-
|
212
|
-
|
229
|
+
with_path plugin_path do
|
230
|
+
(YAML::load_file('about.yml') rescue {}).to_hash
|
231
|
+
end
|
213
232
|
end
|
214
233
|
|
215
234
|
# Returns a list of files that should be scheduled for SCM add.
|
216
235
|
def files_scheduled_for_add
|
217
|
-
|
218
|
-
Dir[plugin.name+"-tmp/**/*"].collect {|fn| fn.gsub(plugin.name+'-tmp', '.')} -
|
236
|
+
Dir[temp_plugin_name+"/**/*"].collect {|fn| fn.gsub(temp_plugin_name, '.')} -
|
219
237
|
Dir[plugin.name+"/**/*"].collect{|fn| fn.gsub(plugin.name, '.')}
|
220
238
|
end
|
221
239
|
|
222
240
|
# Returns a list of files that should be scheduled for SCM remove.
|
223
241
|
def files_scheduled_for_remove
|
224
|
-
change_dir_to_absolute_plugins_dir
|
225
242
|
Dir[plugin.name+"/**/*"].collect {|fn| fn.gsub(plugin.name, '.')} -
|
226
|
-
Dir[
|
243
|
+
Dir[temp_plugin_name+"/**/*"].collect {|fn| fn.gsub(temp_plugin_name, '.')}
|
227
244
|
end
|
228
245
|
|
229
246
|
# Remove the temp folder, used by update process.
|
230
247
|
def remove_temp_folder
|
231
|
-
|
232
|
-
FileUtils.rm_rf(plugin.name+'-tmp')
|
248
|
+
FileUtils.rm_rf [ absolute_rails_plugins_path, temp_plugin_name ].to_path
|
233
249
|
end
|
234
250
|
|
235
|
-
|
236
|
-
|
237
|
-
|
251
|
+
# Returns the name used for temporary plugin folder.
|
252
|
+
def temp_plugin_name
|
253
|
+
plugin.name + TEMP_SUFFIX
|
254
|
+
end
|
255
|
+
|
256
|
+
class_method_proxy :local_repository_path, :cache_file,
|
257
|
+
:cache_content, :path_to_rails_app, :rails_plugins_path,
|
258
|
+
:with_path, :absolute_rails_plugins_path
|
238
259
|
|
239
260
|
private
|
240
|
-
#
|
241
|
-
def
|
242
|
-
|
261
|
+
# Returns the path to the plugin
|
262
|
+
def plugin_path
|
263
|
+
[ local_repository_path, plugin.name || plugin.guess_name ].to_path
|
243
264
|
end
|
244
265
|
|
245
266
|
# Prepare the plugin installation
|
246
267
|
def prepare_installation
|
247
|
-
FileUtils.mkdir_p
|
248
|
-
|
249
|
-
FileUtils.touch(cache_file)
|
268
|
+
FileUtils.mkdir_p local_repository_path
|
269
|
+
FileUtils.touch [ local_repository_path, cache_file ].to_path
|
250
270
|
end
|
251
271
|
|
252
272
|
# Add a plugin into the cache
|
@@ -262,17 +282,16 @@ module Sashimi
|
|
262
282
|
|
263
283
|
# Write all the plugins into the cache
|
264
284
|
def write_to_cache(plugins)
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
FileUtils.rm("#{cache_file}-backup")
|
285
|
+
File.atomic_write(cache_file) do |file|
|
286
|
+
file.write(plugins.to_yaml)
|
287
|
+
end
|
269
288
|
end
|
270
289
|
|
271
290
|
# Copy a plugin to a Rails app.
|
272
291
|
def copy_plugin_to_rails_app
|
273
|
-
|
274
|
-
FileUtils.
|
275
|
-
|
292
|
+
FileUtils.mkdir_p absolute_rails_plugins_path
|
293
|
+
FileUtils.cp_r [ local_repository_path, plugin.name ].to_path,
|
294
|
+
[ absolute_rails_plugins_path, temp_plugin_name ].to_path
|
276
295
|
end
|
277
296
|
|
278
297
|
# Rename the *-tmp folder used by the installation process.
|
@@ -280,26 +299,27 @@ module Sashimi
|
|
280
299
|
# Example:
|
281
300
|
# click-to-globalize-tmp # => click-to-globalize
|
282
301
|
def rename_temp_folder
|
283
|
-
|
284
|
-
|
302
|
+
FileUtils.mv [ rails_plugins_path, temp_plugin_name ].to_path,
|
303
|
+
[ rails_plugins_path, plugin.name ].to_path
|
285
304
|
end
|
286
305
|
|
287
306
|
# Remove SCM hidden folders.
|
288
307
|
def remove_hidden_folders
|
289
308
|
require 'find'
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
309
|
+
with_path [ absolute_rails_plugins_path, temp_plugin_name ].to_path do
|
310
|
+
Find.find('./') do |path|
|
311
|
+
if File.basename(path) == '.'+scm_type
|
312
|
+
FileUtils.remove_dir(path, true)
|
313
|
+
Find.prune
|
314
|
+
end
|
295
315
|
end
|
296
316
|
end
|
297
317
|
end
|
298
|
-
|
318
|
+
|
299
319
|
# Run the plugin install hook.
|
300
320
|
def run_install_hook
|
301
|
-
install_hook_file =
|
302
|
-
load install_hook_file if File.
|
321
|
+
install_hook_file = [ rails_plugins_path, plugin.name, 'install.rb' ].to_path
|
322
|
+
Kernel.load install_hook_file if File.exists? install_hook_file
|
303
323
|
end
|
304
324
|
end
|
305
325
|
end
|