[Git][noosfero/noosfero][master] 4 commits: plugins: fix hotspot for around_filter

Bráulio Bhavamitra gitlab at gitlab.com
Wed Jul 22 23:12:19 BRT 2015


Bráulio Bhavamitra pushed to branch master at Noosfero / noosfero


Commits:
2572302a by Braulio Bhavamitra at 2015-07-22T14:13:25Z
plugins: fix hotspot for around_filter

Around filter need to yield if the plugin is not enabled and need to
receive a block from the controller

- - - - -
661c197c by Braulio Bhavamitra at 2015-07-22T19:59:00Z
analytics: add missing gem

- - - - -
69c9f5e5 by Braulio Bhavamitra at 2015-07-22T22:50:22Z
Fix dependencies load on spaminator and stoa

- - - - -
059e63bf by Braulio Bhavamitra at 2015-07-22T23:07:32Z
CI: test plugins with Gemfiles on travis/gitlab

- - - - -


7 changed files:

- .gitlab-ci.yml
- .travis.yml
- lib/noosfero/plugin.rb
- lib/noosfero/plugin/parent_methods.rb
- + plugins/analytics/Gemfile
- plugins/spaminator/dependencies.rb
- plugins/stoa/Gemfile


Changes:

=====================================
.gitlab-ci.yml
=====================================
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,6 +1,8 @@
 before_script:
   - mkdir -p tmp/pids log
   - bundle check || bundle install
+# workaround for plugins with Gemfile
+  - perl -pi -e 's/--local //' script/noosfero-plugins
   - script/noosfero-plugins disableall
   - bundle exec rake makemo &>/dev/null
 # database


=====================================
.travis.yml
=====================================
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,7 +2,6 @@ language: ruby
 rvm:
 # for 2.2 support we need to upgrade the pg gem
   - 2.1.6
-cache: bundler
 
 sudo: false
 addons:
@@ -19,9 +18,20 @@ addons:
       - libsqlite3-dev
       - libxslt1-dev
 
+before_install:
+  - gem env
+
+# workaround for https://github.com/travis-ci/travis-ci/issues/4536
+before_install:
+  - export GEM_HOME=$PWD/vendor/bundle/ruby/2.1.0
+  - gem install bundler
+cache: bundler
+
 before_script:
   - mkdir -p tmp/pids log
-  - bundle check || bundle install
+# workaround for plugins with Gemfile
+  - perl -pi -e 's/cat .+ > \$gemfile/echo "source \\"https:\/\/rubygems.org\\"" > \$gemfile && cat \$source\/Gemfile >> \$gemfile/' script/noosfero-plugins
+  - perl -pi -e 's/--local --quiet/install --jobs=3 --retry=3/' script/noosfero-plugins
   - script/noosfero-plugins disableall
   - bundle exec rake makemo &>/dev/null
 # database


=====================================
lib/noosfero/plugin.rb
=====================================
--- a/lib/noosfero/plugin.rb
+++ b/lib/noosfero/plugin.rb
@@ -138,11 +138,12 @@ class Noosfero::Plugin
         filters = [filters]
       end
       filters.each do |plugin_filter|
+        plugin_filter[:options] ||= {}
+        plugin_filter[:options][:if] = -> { environment.plugin_enabled? plugin.module_name }
+
         filter_method = "#{plugin.identifier}_#{plugin_filter[:method_name]}".to_sym
-        controller_class.send(plugin_filter[:type], filter_method, (plugin_filter[:options] || {}))
-        controller_class.send(:define_method, filter_method) do
-          instance_exec(&plugin_filter[:block]) if environment.plugin_enabled?(plugin)
-        end
+        controller_class.send plugin_filter[:type], filter_method, plugin_filter[:options]
+        controller_class.send :define_method, filter_method, &plugin_filter[:block]
       end
     end
 


=====================================
lib/noosfero/plugin/parent_methods.rb
=====================================
--- a/lib/noosfero/plugin/parent_methods.rb
+++ b/lib/noosfero/plugin/parent_methods.rb
@@ -11,6 +11,10 @@ class Noosfero::Plugin
       @identifier ||= (if self.parents.first.instance_of? Module then self.parents.first else self end).name.underscore
     end
 
+    def module_name
+      @name ||= (if self.parents.first != Object then self.parents.first else self end).to_s
+    end
+
     def public_name
       @public_name ||= self.identifier.gsub '_plugin', ''
     end


=====================================
plugins/analytics/Gemfile
=====================================
--- /dev/null
+++ b/plugins/analytics/Gemfile
@@ -0,0 +1,2 @@
+gem 'slim'
+


=====================================
plugins/spaminator/dependencies.rb
=====================================
--- a/plugins/spaminator/dependencies.rb
+++ b/plugins/spaminator/dependencies.rb
@@ -1,3 +1,2 @@
 require 'rubygems'
-require 'progressbar'
 require 'benchmark'


=====================================
plugins/stoa/Gemfile
=====================================
--- a/plugins/stoa/Gemfile
+++ b/plugins/stoa/Gemfile
@@ -1 +1,5 @@
 gem 'sinatra'
+
+group :test do
+  gem 'sqlite3'
+end



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/6b50d1d94c792d2bdbf588cd34da9b8afb787b22...059e63bfc0d979d9f86b426bfea13848d6ee6452
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150723/fcc70a92/attachment.html>


More information about the Noosfero-dev mailing list