Permalink
Browse files

Updated all of the plugins to use configure.

  • Loading branch information...
1 parent 7da8115 commit 728958507ffe4ff42bc42063f732756a314cb0ed @jnunemaker jnunemaker committed Jan 23, 2010
View
30 lib/mongo_mapper/plugins/callbacks.rb
@@ -1,23 +1,23 @@
module MongoMapper
module Plugins
module Callbacks
- module InstanceMethods
- def self.included(model)
- model.class_eval do
- include ActiveSupport::Callbacks
+ def self.configure(model)
+ model.class_eval do
+ include ActiveSupport::Callbacks
- define_callbacks(
- :before_save, :after_save,
- :before_create, :after_create,
- :before_update, :after_update,
- :before_validation, :after_validation,
- :before_validation_on_create, :after_validation_on_create,
- :before_validation_on_update, :after_validation_on_update,
- :before_destroy, :after_destroy
- )
- end
+ define_callbacks(
+ :before_save, :after_save,
+ :before_create, :after_create,
+ :before_update, :after_update,
+ :before_validation, :after_validation,
+ :before_validation_on_create, :after_validation_on_create,
+ :before_validation_on_update, :after_validation_on_update,
+ :before_destroy, :after_destroy
+ )
end
-
+ end
+
+ module InstanceMethods
def valid?
action = new? ? 'create' : 'update'
View
8 lib/mongo_mapper/plugins/identity_map.rb
@@ -8,6 +8,10 @@ def self.models
def self.clear
models.each { |m| m.identity_map.clear }
end
+
+ def self.configure(model)
+ IdentityMap.models << model
+ end
module ClassMethods
def inherited(descendant)
@@ -97,10 +101,6 @@ def selecting_fields?(options)
end
module InstanceMethods
- def self.included(model)
- IdentityMap.models << model
- end
-
def identity_map
self.class.identity_map
end
View
8 lib/mongo_mapper/plugins/keys.rb
@@ -1,6 +1,10 @@
module MongoMapper
module Plugins
module Keys
+ def self.configure(model)
+ model.key :_id, ObjectId
+ end
+
module ClassMethods
def inherited(descendant)
descendant.instance_variable_set(:@keys, keys.dup)
@@ -133,10 +137,6 @@ def create_validations_for(key)
end
module InstanceMethods
- def self.included(model)
- model.key :_id, ObjectId
- end
-
def initialize(attrs={}, from_db=false)
unless attrs.nil?
provided_keys = attrs.keys.map { |k| k.to_s }
View
12 lib/mongo_mapper/plugins/serialization.rb
@@ -3,6 +3,10 @@
module MongoMapper
module Plugins
module Serialization
+ def self.configure(model)
+ model.class_eval { include Json }
+ end
+
class Serializer
attr_reader :options
@@ -96,14 +100,6 @@ def apply_to_json_defaults(options)
options[:except] = except
end
end
-
- module InstanceMethods
- def self.included(model)
- model.class_eval do
- include Json
- end
- end
- end
end
end
end
View
6 lib/mongo_mapper/plugins/validations.rb
@@ -1,10 +1,8 @@
module MongoMapper
module Plugins
module Validations
- module InstanceMethods
- def self.included(model)
- model.class_eval { include Validatable }
- end
+ def self.configure(model)
+ model.class_eval { include Validatable }
end
module DocumentMacros

0 comments on commit 7289585

Please sign in to comment.