Skip to content
Browse files

Added configure to plugins. This allows you to modify the model addin…

…g the plugin without needed to do an included hook in InstanceMethods.
  • Loading branch information...
1 parent 58e57dd commit 7da811504229240cc7aa235870b8a22411011ab7 @jnunemaker jnunemaker committed Jan 23, 2010
Showing with 15 additions and 12 deletions.
  1. +3 −8 lib/mongo_mapper/plugins.rb
  2. +12 −4 test/unit/test_plugins.rb
View
11 lib/mongo_mapper/plugins.rb
@@ -5,14 +5,9 @@ def plugins
end
def plugin(mod)
- if mod.const_defined?(:ClassMethods)
- extend mod::ClassMethods
- end
-
- if mod.const_defined?(:InstanceMethods)
- include mod::InstanceMethods
- end
-
+ extend mod::ClassMethods if mod.const_defined?(:ClassMethods)
+ include mod::InstanceMethods if mod.const_defined?(:InstanceMethods)
+ mod.configure(self) if mod.respond_to?(:configure)
plugins << mod
end
end
View
16 test/unit/test_plugins.rb
@@ -1,12 +1,16 @@
require 'test_helper'
module MyPlugin
+ def self.configure(model)
+ model.class_eval { attr_accessor :from_configure }
+ end
+
module ClassMethods
def class_foo
'class_foo'
end
end
-
+
module InstanceMethods
def instance_foo
'instance_foo'
@@ -26,15 +30,19 @@ class PluginsTest < Test::Unit::TestCase
should "include instance methods" do
@document.new.instance_foo.should == 'instance_foo'
end
-
+
should "extend class methods" do
@document.class_foo.should == 'class_foo'
end
-
+
+ should "pass model to configure" do
+ @document.new.should respond_to(:from_configure)
+ end
+
should "default plugins to empty array" do
Class.new { extend MongoMapper::Plugins }.plugins.should == []
end
-
+
should "add plugin to plugins" do
@document.plugins.should include(MyPlugin)
end

0 comments on commit 7da8115

Please sign in to comment.
Something went wrong with that request. Please try again.