sashimi 0.1.0 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,23 @@
1
+ * *v0.1.5*
2
+
3
+ * Tagged v0.1.5
4
+
5
+ * Prepare for v0.1.5
6
+
7
+ * Raise a PluginNotFound exception if try to update a not existent plugin for the current Rails app
8
+
9
+ * Updated command line syntax reference in README
10
+
11
+ * Automatically schedule for SCM add and remove on plugin update, for Rails apps versioned with Svn and Git
12
+
13
+ * Added --rails option to the Update command in order to update plugins already added to a Rails app [#12 state:resolved]
14
+
15
+ * Added --rails option to the Install command as alias for the Add command [#11 state:resolved]
16
+
17
+ * Added --all option to the Update command in order to update all installed plugins with one command [#2 state:resolved]
18
+
19
+
20
+
1
21
  * *v0.1.0*
2
22
 
3
23
  * Print on the stdout the plugin name on each command execution
data/README CHANGED
@@ -29,11 +29,17 @@ $ sashimi uninstall continuous_builder
29
29
  Update a plugin:
30
30
  $ sashimi update click-to-globalize
31
31
 
32
+ Update a plugin of a Rails app:
33
+ $ sashimi update --rails click-to-globalize
34
+
35
+ NOTE: If your application is versioned with Svn or Git, Sashimi will automatically schedules for add/remove the added/removed files.
36
+
32
37
  List all installed plugins:
33
38
  $ sashimi list
34
39
 
35
40
  Add installed plugin(s) to a Rails app:
36
41
  $ sashimi add click-to-globalize
42
+ $ sashimi install --rails click-to-globalize
37
43
 
38
44
 
39
45
 
@@ -40,10 +40,16 @@ module Sashimi
40
40
  o.separator " #{@script_name} uninstall continuous_builder\n"
41
41
  o.separator " Update a plugin:"
42
42
  o.separator " #{@script_name} update click-to-globalize\n"
43
+ o.separator " Update all installed plugins:"
44
+ o.separator " #{@script_name} update --all\n"
45
+ o.separator " Update plugin(s) already added to a Rails app:"
46
+ o.separator " #{@script_name} update --rails click-to-globalize\n"
43
47
  o.separator " List all installed plugins:"
44
48
  o.separator " #{@script_name} list\n"
45
49
  o.separator " Add installed plugin(s) to a Rails app:"
46
50
  o.separator " #{@script_name} add click-to-globalize\n"
51
+ o.separator " Add installed plugin(s) to a Rails app:"
52
+ o.separator " #{@script_name} install --rails click-to-globalize\n"
47
53
  end
48
54
  end
49
55
 
@@ -79,28 +85,33 @@ module Sashimi
79
85
 
80
86
  class Install
81
87
  def initialize(base_command)
82
- @base_command = base_command
88
+ @base_command = base_command
83
89
  end
84
90
 
85
91
  def options
86
92
  OptionParser.new do |o|
87
93
  o.set_summary_indent(' ')
88
- o.banner = "Usage: #{@base_command.script_name} install URL [URL2, URL3]"
94
+ o.banner = "Usage: #{@base_command.script_name} install [OPTIONS] URL [URL2, URL3]"
89
95
  o.define_head "Install plugin(s) from known URL(s)."
96
+ o.on("-r", "--rails", "Install the plugin(s) in a Rails app.") { |@rails| }
90
97
  end
91
98
  end
92
99
 
93
100
  def parse!(args)
94
101
  options.parse!(args)
95
- args.each do |url|
96
- Plugin.new(nil, url).install
102
+ args.each do |url_or_name|
103
+ if @rails
104
+ Plugin.new(url_or_name).add
105
+ else
106
+ Plugin.new(nil, url_or_name).install
107
+ end
97
108
  end
98
109
  end
99
110
  end
100
111
 
101
112
  class Uninstall
102
113
  def initialize(base_command)
103
- @base_command = base_command
114
+ @base_command = base_command
104
115
  end
105
116
 
106
117
  def options
@@ -121,21 +132,34 @@ module Sashimi
121
132
 
122
133
  class Update
123
134
  def initialize(base_command)
124
- @base_command = base_command
135
+ @base_command = base_command
125
136
  end
126
137
 
127
138
  def options
128
139
  OptionParser.new do |o|
129
140
  o.set_summary_indent(' ')
130
- o.banner = "Usage: #{@base_command.script_name} update PLUGIN [PLUGIN2, PLUGIN3]"
141
+ o.banner = "Usage: #{@base_command.script_name} update [OPTIONS] PLUGIN [PLUGIN2, PLUGIN3]"
131
142
  o.define_head "Update installed plugin(s)."
143
+ o.on("-a", "--all", "Update all installed plugins.") { |@all| }
144
+ o.on("-r", "--rails", "Install the plugin(s) in a Rails app.") { |@rails| }
132
145
  end
133
146
  end
134
147
 
135
148
  def parse!(args)
136
149
  options.parse!(args)
137
- args.each do |name|
138
- Plugin.new(name).update
150
+ raise "Can't use both --all and --rails arguments." if @all and @rails
151
+ if @all
152
+ update_plugins(AbstractRepository.plugins_names)
153
+ elsif @rails
154
+ AbstractRepository.update_rails_plugins(args)
155
+ else
156
+ update_plugins(args)
157
+ end
158
+ end
159
+
160
+ def update_plugins(plugins)
161
+ plugins.each do |plugin|
162
+ Plugin.new(plugin).update
139
163
  end
140
164
  end
141
165
  end
@@ -30,11 +30,17 @@ module Sashimi
30
30
  # Add to a Rails app.
31
31
  def add
32
32
  puts plugin.name.titleize + "\n"
33
- copy_plugin_to_rails_app
34
- remove_hidden_folders
33
+ copy_plugin_and_remove_hidden_folders
34
+ rename_temp_folder
35
35
  run_install_hook
36
36
  end
37
-
37
+
38
+ # Copy a plugin to a Rails app and remove SCM hidden folders
39
+ def copy_plugin_and_remove_hidden_folders
40
+ copy_plugin_to_rails_app
41
+ remove_hidden_folders
42
+ end
43
+
38
44
  class << self
39
45
  def instantiate_repository(plugin)
40
46
  unless plugin.name.nil?
@@ -44,13 +50,69 @@ module Sashimi
44
50
  end.new(plugin)
45
51
  end
46
52
 
47
- # Return all installed plugin names
53
+ # Return all installed plugin names and summary, formatted for stdout.
48
54
  def list
49
55
  cache_content.sort.collect do |plugin, contents|
50
56
  "#{plugin}\t\t#{contents['summary']}"
51
57
  end.join("\n")
52
58
  end
53
59
 
60
+ # Return all installed plugins names.
61
+ def plugins_names
62
+ cache_content.keys.sort
63
+ end
64
+
65
+ # Update the plugins installed in a rails app.
66
+ def update_rails_plugins(plugins_names)
67
+ change_dir(path_to_rails_app)
68
+ if under_version_control?
69
+ update_versioned_rails_plugins(plugins_names)
70
+ else
71
+ update_unversioned_rails_plugins(plugins_names)
72
+ end
73
+ end
74
+
75
+ # Update the plugins installed in a non versioned rails app.
76
+ def update_unversioned_rails_plugins(plugins_names)
77
+ change_dir(plugins_dir)
78
+ plugins_names.each do |plugin_name|
79
+ FileUtils.rm_rf(plugin_name)
80
+ Plugin.new(plugin_name).add
81
+ end
82
+ end
83
+
84
+ # Update the plugins installed in a versioned rails app.
85
+ def update_versioned_rails_plugins(plugins_names)
86
+ change_dir(plugins_dir)
87
+ plugins_names.each do |plugin_name|
88
+ raise PluginNotFound.new(plugin_name) unless File.exists?(plugin_name)
89
+ repository = Plugin.new(plugin_name).repository
90
+ repository.copy_plugin_and_remove_hidden_folders
91
+ files_scheduled_for_remove = repository.files_scheduled_for_remove
92
+ files_scheduled_for_add = repository.files_scheduled_for_add
93
+ FileUtils.cp_r(plugin_name+'-tmp/.', plugin_name)
94
+ repository.remove_temp_folder
95
+ change_dir(plugin_name)
96
+ files_scheduled_for_remove.each {|file| scm_remove file}
97
+ files_scheduled_for_add.each {|file| scm_add file}
98
+ end
99
+ end
100
+
101
+ # Schedules an add for the given file on the current SCM system used by the Rails app.
102
+ def scm_add(file)
103
+ scm_command(:add, file)
104
+ end
105
+
106
+ def scm_remove(file)
107
+ scm_command(:rm, file)
108
+ end
109
+
110
+ # Execute the given command for the current SCM system used by the Rails app.
111
+ def scm_command(command, file)
112
+ scm = guess_version_control_system
113
+ system("#{scm} #{command} #{file}")
114
+ end
115
+
54
116
  def local_repository_path #:nodoc:
55
117
  @local_repository_path ||= File.join(find_home, @@local_repository_sub_path)
56
118
  end
@@ -90,11 +152,27 @@ module Sashimi
90
152
  change_dir(local_repository_path)
91
153
  end
92
154
 
155
+ # Change the current directory with the fully qualified
156
+ # path to Rails app and plugins_dir.
157
+ def change_dir_to_absolute_plugins_dir
158
+ change_dir(File.join(File.expand_path(path_to_rails_app), plugins_dir))
159
+ end
160
+
93
161
  # Rails app plugins dir
94
162
  def plugins_dir
95
163
  @@plugins_dir ||= File.join('vendor', 'plugins')
96
164
  end
97
165
 
166
+ # Check if the current working directory is under version control
167
+ def under_version_control?
168
+ !Dir.glob(".{git,svn}").empty?
169
+ end
170
+
171
+ # Guess the version control system for the current working directory.
172
+ def guess_version_control_system
173
+ File.exists?('.git') ? :git : :svn
174
+ end
175
+
98
176
  # Find the user home directory
99
177
  def find_home
100
178
  ['HOME', 'USERPROFILE'].each do |homekey|
@@ -135,6 +213,26 @@ module Sashimi
135
213
  return {} unless File.exists?('about.yml')
136
214
  (YAML::load_file('about.yml') || {}).to_hash
137
215
  end
216
+
217
+ # Returns a list of files that should be scheduled for SCM add.
218
+ def files_scheduled_for_add
219
+ change_dir_to_absolute_plugins_dir
220
+ Dir[plugin.name+"-tmp/**/*"].collect {|fn| fn.gsub(plugin.name+'-tmp', '.')} -
221
+ Dir[plugin.name+"/**/*"].collect{|fn| fn.gsub(plugin.name, '.')}
222
+ end
223
+
224
+ # Returns a list of files that should be scheduled for SCM remove.
225
+ def files_scheduled_for_remove
226
+ change_dir_to_absolute_plugins_dir
227
+ Dir[plugin.name+"/**/*"].collect {|fn| fn.gsub(plugin.name, '.')} -
228
+ Dir[plugin.name+"-tmp/**/*"].collect {|fn| fn.gsub(plugin.name+"-tmp", '.')}
229
+ end
230
+
231
+ # Remove the temp folder, used by update process.
232
+ def remove_temp_folder
233
+ change_dir_to_absolute_plugins_dir
234
+ FileUtils.rm_rf(plugin.name+'-tmp')
235
+ end
138
236
 
139
237
  private
140
238
  # Proxy for <tt>AbstractRepository#change_dir</tt>
@@ -147,6 +245,11 @@ module Sashimi
147
245
  self.class.change_dir_to_local_repository
148
246
  end
149
247
 
248
+ # Proxy for <tt>AbstractRepository#change_dir_to_absolute_plugins_dir</tt>
249
+ def change_dir_to_absolute_plugins_dir
250
+ self.class.change_dir_to_absolute_plugins_dir
251
+ end
252
+
150
253
  # Change the current directory with the plugin one
151
254
  def change_dir_to_plugin_path
152
255
  change_dir(File.join(local_repository_path, plugin.name || plugin.guess_name))
@@ -207,13 +310,22 @@ module Sashimi
207
310
  def copy_plugin_to_rails_app
208
311
  change_dir(path_to_rails_app)
209
312
  FileUtils.mkdir_p(plugins_dir)
210
- FileUtils.cp_r(File.join(local_repository_path, plugin.name), File.join(plugins_dir, plugin.name))
313
+ FileUtils.cp_r(File.join(local_repository_path, plugin.name), File.join(plugins_dir, plugin.name+'-tmp'))
314
+ end
315
+
316
+ # Rename the *-tmp folder used by the installation process.
317
+ #
318
+ # Example:
319
+ # click-to-globalize-tmp # => click-to-globalize
320
+ def rename_temp_folder
321
+ change_dir(path_to_rails_app)
322
+ FileUtils.mv(File.join(plugins_dir, plugin.name+'-tmp'), File.join(plugins_dir, plugin.name))
211
323
  end
212
324
 
213
325
  # Remove SCM hidden folders.
214
326
  def remove_hidden_folders
215
327
  require 'find'
216
- change_dir(File.join(path_to_rails_app, plugins_dir, plugin.name))
328
+ change_dir(File.join(path_to_rails_app, plugins_dir, plugin.name+'-tmp'))
217
329
  Find.find('./') do |path|
218
330
  if File.basename(path) == '.'+scm_type
219
331
  FileUtils.remove_dir(path, true)
data/sashimi.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "sashimi"
3
- s.version = "0.1.0"
4
- s.date = "2008-05-19"
3
+ s.version = "0.1.5"
4
+ s.date = "2008-05-20"
5
5
  s.summary = "Rails plugins manager"
6
6
  s.author = "Luca Guidi"
7
7
  s.email = "guidi.luca@gmail.com"
@@ -44,6 +44,12 @@ class AbstractRepositoryTest < Test::Unit::TestCase
44
44
  end
45
45
  end
46
46
 
47
+ def test_should_return_all_installed_plugins_names
48
+ initialize_repository_for_test do
49
+ assert_equal(['plug-in', 'plugin'], AbstractRepository.plugins_names)
50
+ end
51
+ end
52
+
47
53
  # DIRECTORIES
48
54
  def test_should_change_current_dir
49
55
  repository.change_dir(repository.class.find_home)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sashimi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-19 00:00:00 +02:00
12
+ date: 2008-05-20 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency