noosfero | 2 new commits pushed to repository

Bráulio Bhavamitra gitlab at gitlab.com
Sun Feb 22 20:18:18 BRT 2015


Bráulio Bhavamitra pushed to refs/heads/master at <a href="https://gitlab.com/noosfero/noosfero">Noosfero / noosfero</a>

Commits:
<a href="https://gitlab.com/noosfero/noosfero/commit/afdae5a97e1696823ba24b76826dada70bc45274">afdae5a9</a> by Braulio Bhavamitra
plugins: reload extensions before request when needed

Use ActionDispatch::Reloader.to_prepare instead of
Rails.configuration.to_prepare. The latter runs the block only once and
is not adequate for code that are reloaded upon files changes on each
request. As extensions may touch on helpers and controllers, the former
suits well.

Besides, filters must be loaded after all plugins' extensions, as controllers
and helpers needs the "final" code to execute properly.

The production behaviour don't change as the code is not reloaded.

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/c6f5b48462925a16493db0d865bef4def009e29b">c6f5b484</a> by Bráulio Bhavamitra
Merge branch 'plugins-fix-extensions-filters-reload' into 'master'

Plugins: fix extensions and filters reload

See commit description.

This is needed for the responsive plugin.

See merge request !457

- - - - -


Changes:

=====================================
lib/noosfero/plugin.rb
=====================================
--- a/lib/noosfero/plugin.rb
+++ b/lib/noosfero/plugin.rb
@@ -24,11 +24,17 @@ class Noosfero::Plugin
 
     def initialize!
       return if !should_load
-      available_plugins.each do |plugin_dir|
+
+      klasses = available_plugins.map do |plugin_dir|
         plugin_name = File.basename(plugin_dir)
-        plugin = load_plugin(plugin_name)
-        load_plugin_extensions(plugin_dir)
-        load_plugin_filters(plugin)
+        load_plugin plugin_name
+      end
+      available_plugins.each do |plugin_dir|
+        load_plugin_extensions plugin_dir
+      end
+      # filters must be loaded after all extensions
+      klasses.each do |plugin|
+        load_plugin_filters plugin
       end
     end
 
@@ -88,7 +94,7 @@ class Noosfero::Plugin
     # This is a generic method that initialize any possible filter defined by a
     # plugin to a specific controller
     def load_plugin_filters(plugin)
-      Rails.configuration.to_prepare do
+      ActionDispatch::Reloader.to_prepare do
         filters = plugin.new.send 'application_controller_filters' rescue []
         Noosfero::Plugin.add_controller_filters ApplicationController, plugin, filters
 
@@ -116,7 +122,7 @@ class Noosfero::Plugin
     end
 
     def load_plugin_extensions(dir)
-      Rails.configuration.to_prepare do
+      ActionDispatch::Reloader.to_prepare do
         Dir[File.join(dir, 'lib', 'ext', '*.rb')].each {|file| require_dependency file }
       end
     end

=====================================
lib/noosfero/plugin/spammable.rb
=====================================
--- a/lib/noosfero/plugin/spammable.rb
+++ b/lib/noosfero/plugin/spammable.rb
@@ -1,4 +1,4 @@
-Rails.configuration.to_prepare do
+ActionDispatch::Reloader.to_prepare do
   Spammable.module_eval do
     def marked_as_spam
       plugins.dispatch(:marked_as_spam, self)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150222/2b74267d/attachment.html>


More information about the Noosfero-dev mailing list