summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-11-16 15:38:37 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-11-16 15:38:37 +0000
commitfefc6e6bec617fe4e6b438beedf1ca78f722ce45 (patch)
tree1af057922516131d69c388775703fa6b93fdf3f7
parent97252c26eefe3dfa5e0c3cb059fe66cb21b2e34d (diff)
downloadredmine-fefc6e6bec617fe4e6b438beedf1ca78f722ce45.tar.gz
redmine-fefc6e6bec617fe4e6b438beedf1ca78f722ce45.zip
Adds .find and .all Plugin class methods.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2039 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/admin_controller.rb2
-rw-r--r--app/controllers/settings_controller.rb11
-rw-r--r--app/models/setting.rb4
-rw-r--r--lib/redmine/plugin.rb14
4 files changed, 22 insertions, 9 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index 119e2b922..d3afeeea1 100644
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -50,7 +50,7 @@ class AdminController < ApplicationController
end
def plugins
- @plugins = Redmine::Plugin.registered_plugins.values.sort
+ @plugins = Redmine::Plugin.all
end
# Loads the default configuration
diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb
index 7f9c9d5cc..99f7bcf08 100644
--- a/app/controllers/settings_controller.rb
+++ b/app/controllers/settings_controller.rb
@@ -45,14 +45,15 @@ class SettingsController < ApplicationController
end
def plugin
- plugin_id = params[:id].to_sym
- @plugin = Redmine::Plugin.registered_plugins[plugin_id]
+ @plugin = Redmine::Plugin.find(params[:id])
if request.post?
- Setting["plugin_#{plugin_id}"] = params[:settings]
+ Setting["plugin_#{@plugin.id}"] = params[:settings]
flash[:notice] = l(:notice_successful_update)
- redirect_to :action => 'plugin', :id => params[:id]
+ redirect_to :action => 'plugin', :id => @plugin.id
end
@partial = @plugin.settings[:partial]
- @settings = Setting["plugin_#{plugin_id}"]
+ @settings = Setting["plugin_#{@plugin.id}"]
+ rescue Redmine::PluginNotFound
+ render_404
end
end
diff --git a/app/models/setting.rb b/app/models/setting.rb
index 072afa0db..187347d64 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -75,9 +75,9 @@ class Setting < ActiveRecord::Base
cattr_accessor :available_settings
@@available_settings = YAML::load(File.open("#{RAILS_ROOT}/config/settings.yml"))
- Redmine::Plugin.registered_plugins.each do |id, plugin|
+ Redmine::Plugin.all.each do |plugin|
next unless plugin.settings
- @@available_settings["plugin_#{id}"] = {'default' => plugin.settings[:default], 'serialized' => true}
+ @@available_settings["plugin_#{plugin.id}"] = {'default' => plugin.settings[:default], 'serialized' => true}
end
validates_uniqueness_of :name
diff --git a/lib/redmine/plugin.rb b/lib/redmine/plugin.rb
index 17953ef8c..80c638b28 100644
--- a/lib/redmine/plugin.rb
+++ b/lib/redmine/plugin.rb
@@ -17,6 +17,8 @@
module Redmine #:nodoc:
+ class PluginNotFound < StandardError; end
+
# Base class for Redmine plugins.
# Plugins are registered using the <tt>register</tt> class method that acts as the public constructor.
#
@@ -62,7 +64,17 @@ module Redmine #:nodoc:
def self.register(id, &block)
p = new(id)
p.instance_eval(&block)
- Plugin.registered_plugins[id] = p
+ registered_plugins[id] = p
+ end
+
+ # Returns an array off all registered plugins
+ def self.all
+ registered_plugins.values.sort
+ end
+
+ # Finds a plugin by its id
+ def self.find(id)
+ registered_plugins[id.to_sym] || raise(PluginNotFound)
end
def initialize(id)