jodosha-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,25 @@
1
+ * Prepare for v0.1.5
2
+
3
+ * Raise a PluginNotFound exception if try to update a not existent plugin for the current Rails app
4
+
5
+ * Updated command line syntax reference in README
6
+
7
+ * Automatically schedule for SCM add and remove on plugin update, for Rails apps versioned with Svn and Git
8
+
9
+ * Added --rails option to the Update command in order to update plugins already added to a Rails app [#12 state:resolved]
10
+
11
+ * Added --rails option to the Install command as alias for the Add command [#11 state:resolved]
12
+
13
+ * Added --all option to the Update command in order to update all installed plugins with one command [#2 state:resolved]
14
+
15
+
16
+
17
+ * *v0.1.0*
18
+
19
+ * Print on the stdout the plugin name on each command execution
20
+
21
+ * Fixed shell help output in commands.rb: make clear each command accepts multiple params. Deleted duplicated Update class from commands.rb.
22
+
1
23
  * Fixed sashimi.gemspec: sashimi executable is now available after gem setup
2
24
 
3
25
  * Made AbstractRepository#remove_hidden_folders platform independent
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
 
@@ -24,9 +24,9 @@ module Sashimi
24
24
  o.separator ""
25
25
  o.separator "COMMANDS"
26
26
 
27
- o.separator " install Install plugin from known URL."
28
- o.separator " uninstall Uninstall plugin from local repository."
29
- o.separator " update Update an installed plugin."
27
+ o.separator " install Install plugin(s) from known URL(s)."
28
+ o.separator " uninstall Uninstall plugin(s) from local repository."
29
+ o.separator " update Update installed plugin(s)."
30
30
  o.separator " list List all installed plugins."
31
31
  o.separator " add Add installed plugin(s) to a Rails app."
32
32
 
@@ -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,35 +85,40 @@ 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"
89
- o.define_head "Install a plugin."
94
+ o.banner = "Usage: #{@base_command.script_name} install [OPTIONS] URL [URL2, URL3]"
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
107
118
  OptionParser.new do |o|
108
119
  o.set_summary_indent(' ')
109
- o.banner = "Usage: #{@base_command.script_name} uninstall PLUGIN"
110
- o.define_head "Remove an installed plugin."
120
+ o.banner = "Usage: #{@base_command.script_name} uninstall PLUGIN [PLUGIN2, PLUGIN3]"
121
+ o.define_head "Uninstall plugin(s) from local repository."
111
122
  end
112
123
  end
113
124
 
@@ -121,42 +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"
131
- o.define_head "Update an installed plugin."
141
+ o.banner = "Usage: #{@base_command.script_name} update [OPTIONS] PLUGIN [PLUGIN2, PLUGIN3]"
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
139
- end
140
- end
141
- end
142
-
143
- class Uninstall
144
- def initialize(base_command)
145
- @base_command = base_command
146
- end
147
-
148
- def options
149
- OptionParser.new do |o|
150
- o.set_summary_indent(' ')
151
- o.banner = "Usage: #{@base_command.script_name} uninstall PLUGIN"
152
- o.define_head "Remove an installed plugin."
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)
153
157
  end
154
158
  end
155
159
 
156
- def parse!(args)
157
- options.parse!(args)
158
- args.each do |name|
159
- Plugin.new(name).uninstall
160
+ def update_plugins(plugins)
161
+ plugins.each do |plugin|
162
+ Plugin.new(plugin).update
160
163
  end
161
164
  end
162
165
  end
@@ -29,11 +29,18 @@ module Sashimi
29
29
 
30
30
  # Add to a Rails app.
31
31
  def add
32
- copy_plugin_to_rails_app
33
- remove_hidden_folders
32
+ puts plugin.name.titleize + "\n"
33
+ copy_plugin_and_remove_hidden_folders
34
+ rename_temp_folder
34
35
  run_install_hook
35
36
  end
36
-
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
+
37
44
  class << self
38
45
  def instantiate_repository(plugin)
39
46
  unless plugin.name.nil?
@@ -43,13 +50,69 @@ module Sashimi
43
50
  end.new(plugin)
44
51
  end
45
52
 
46
- # Return all installed plugin names
53
+ # Return all installed plugin names and summary, formatted for stdout.
47
54
  def list
48
55
  cache_content.sort.collect do |plugin, contents|
49
56
  "#{plugin}\t\t#{contents['summary']}"
50
57
  end.join("\n")
51
58
  end
52
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
+
53
116
  def local_repository_path #:nodoc:
54
117
  @local_repository_path ||= File.join(find_home, @@local_repository_sub_path)
55
118
  end
@@ -89,11 +152,27 @@ module Sashimi
89
152
  change_dir(local_repository_path)
90
153
  end
91
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
+
92
161
  # Rails app plugins dir
93
162
  def plugins_dir
94
163
  @@plugins_dir ||= File.join('vendor', 'plugins')
95
164
  end
96
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
+
97
176
  # Find the user home directory
98
177
  def find_home
99
178
  ['HOME', 'USERPROFILE'].each do |homekey|
@@ -134,6 +213,26 @@ module Sashimi
134
213
  return {} unless File.exists?('about.yml')
135
214
  (YAML::load_file('about.yml') || {}).to_hash
136
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
137
236
 
138
237
  private
139
238
  # Proxy for <tt>AbstractRepository#change_dir</tt>
@@ -146,6 +245,11 @@ module Sashimi
146
245
  self.class.change_dir_to_local_repository
147
246
  end
148
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
+
149
253
  # Change the current directory with the plugin one
150
254
  def change_dir_to_plugin_path
151
255
  change_dir(File.join(local_repository_path, plugin.name || plugin.guess_name))
@@ -206,13 +310,22 @@ module Sashimi
206
310
  def copy_plugin_to_rails_app
207
311
  change_dir(path_to_rails_app)
208
312
  FileUtils.mkdir_p(plugins_dir)
209
- 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))
210
323
  end
211
324
 
212
325
  # Remove SCM hidden folders.
213
326
  def remove_hidden_folders
214
327
  require 'find'
215
- 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'))
216
329
  Find.find('./') do |path|
217
330
  if File.basename(path) == '.'+scm_type
218
331
  FileUtils.remove_dir(path, true)
@@ -2,11 +2,13 @@ module Sashimi
2
2
  class GitRepository < AbstractRepository
3
3
  def install
4
4
  prepare_installation
5
+ puts plugin.guess_name.titleize + "\n\n"
5
6
  system("git clone #{plugin.url}")
6
7
  add_to_cache(plugin.to_hash)
7
8
  end
8
9
 
9
10
  def update
11
+ puts plugin.name.titleize + "\n\n"
10
12
  change_dir_to_plugin_path
11
13
  system('git pull')
12
14
  end
@@ -2,11 +2,13 @@ module Sashimi
2
2
  class SvnRepository < AbstractRepository
3
3
  def install
4
4
  prepare_installation
5
+ puts plugin.guess_name.titleize + "\n\n"
5
6
  system("svn co #{plugin.url} #{plugin.guess_name}")
6
7
  add_to_cache(plugin.to_hash)
7
8
  end
8
9
 
9
10
  def update
11
+ puts plugin.name.titleize + "\n\n"
10
12
  change_dir_to_plugin_path
11
13
  system("svn up")
12
14
  end
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: jodosha-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 -07:00
12
+ date: 2008-05-20 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency