Skip to content

Commit

Permalink
Added --rails option to the Update command in order to update plugins…
Browse files Browse the repository at this point in the history
… already added to a Rails app [#12 state:resolved]
  • Loading branch information
Luca Guidi committed May 20, 2008
1 parent 92b6a84 commit aa737fe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,3 +1,5 @@
* Added --rails option to the Update command in order to update plugins already added to a Rails app [#12 state:resolved]

* Added --rails option to the Install command as alias for the Add command [#11 state:resolved]

* Added --all option to the Update command in order to update all installed plugins with one command [#2 state:resolved]
Expand Down
6 changes: 6 additions & 0 deletions lib/sashimi/commands.rb
Expand Up @@ -42,6 +42,8 @@ def options
o.separator " #{@script_name} update click-to-globalize\n"
o.separator " Update all installed plugins:"
o.separator " #{@script_name} update --all\n"
o.separator " Update plugin(s) already added to a Rails app:"
o.separator " #{@script_name} update --rails click-to-globalize\n"
o.separator " List all installed plugins:"
o.separator " #{@script_name} list\n"
o.separator " Add installed plugin(s) to a Rails app:"
Expand Down Expand Up @@ -139,13 +141,17 @@ def options
o.banner = "Usage: #{@base_command.script_name} update [OPTIONS] PLUGIN [PLUGIN2, PLUGIN3]"
o.define_head "Update installed plugin(s)."
o.on("-a", "--all", "Update all installed plugins.") { |@all| }
o.on("-r", "--rails", "Install the plugin(s) in a Rails app.") { |@rails| }
end
end

def parse!(args)
options.parse!(args)
raise "Can't use both --all and --rails arguments." if @all and @rails
if @all
update_plugins(AbstractRepository.plugins_names)
elsif @rails
AbstractRepository.update_rails_plugins(args)
else
update_plugins(args)
end
Expand Down
20 changes: 20 additions & 0 deletions lib/sashimi/repositories/abstract_repository.rb
Expand Up @@ -56,6 +56,21 @@ def plugins_names
cache_content.keys.sort
end

# Update the plugins installed in a rails app.
def update_rails_plugins(plugins_names)
change_dir(path_to_rails_app)
update_unversioned_rails_plugins(plugins_names) unless under_version_control?
end

# Update the plugins installed in a non versioned rails app.
def update_unversioned_rails_plugins(plugins_names)
change_dir(plugins_dir)
plugins_names.each do |plugin_name|
FileUtils.rm_rf(plugin_name)
Plugin.new(plugin_name).add
end
end

def local_repository_path #:nodoc:
@local_repository_path ||= File.join(find_home, @@local_repository_sub_path)
end
Expand Down Expand Up @@ -100,6 +115,11 @@ def plugins_dir
@@plugins_dir ||= File.join('vendor', 'plugins')
end

# Check if the current working directory is under version control
def under_version_control?
!Dir.glob("{.git, .svn}").empty?
end

# Find the user home directory
def find_home
['HOME', 'USERPROFILE'].each do |homekey|
Expand Down

0 comments on commit aa737fe

Please sign in to comment.