Skip to content
Browse files

Removed InstanceMethod module as it is no longer used in ActiveSuppor…

…t::Concern (and MongoMappers plugins)
  • Loading branch information...
1 parent 5078807 commit 7121f21d616b3473d537d480e20e2e74d033e4a0 @andrewtimberlake committed Jan 25, 2012
Showing with 70 additions and 75 deletions.
  1. +9 −12 lib/mongo_mapper/plugins/auto_increment_id.rb
  2. +61 −63 lib/mongo_mapper/plugins/updating_modifiers.rb
View
21 lib/mongo_mapper/plugins/auto_increment_id.rb
@@ -11,19 +11,16 @@ def auto_increment_id
end
end
- module InstanceMethods
- private
- def generate_document_id(options={})
- while true
- oldest_number = self.class.fields(:_id).sort([[:_id, :descending]]).first.try(:id)
- self.id = oldest_number.to_i + 1
- begin
- break if collection.insert({:_id => id}, :safe => true)
- rescue Mongo::OperationFailure => e
- #Ignored, trying to get the next key
- end
- end
+ def generate_document_id(options={})
+ while true
+ oldest_number = self.class.fields(:_id).sort([[:_id, :descending]]).first.try(:id)
+ self.id = oldest_number.to_i + 1
+ begin
+ break if collection.insert({:_id => id}, :safe => true)
+ rescue Mongo::OperationFailure => e
+ #Ignored, trying to get the next key
end
+ end
end
end
end
View
124 lib/mongo_mapper/plugins/updating_modifiers.rb
@@ -6,85 +6,83 @@ module UpdatingModifiers
def self.configure(mod)
end
- module InstanceMethods
- def set(hash)
- hash.each do |key, value|
- obj, method = get_obj_and_method(key)
- obj.send("#{method}=", value)
- end
- super hash_to_mongo(hash)
+ def set(hash)
+ hash.each do |key, value|
+ obj, method = get_obj_and_method(key)
+ obj.send("#{method}=", value)
end
+ super hash_to_mongo(hash)
+ end
- def increment(hash)
- hash.each do |key, value|
- obj, method = get_obj_and_method(key)
- val = obj.send(method)
- obj.send("#{method}=", val + value)
- end
- super hash_to_mongo(hash)
+ def increment(hash)
+ hash.each do |key, value|
+ obj, method = get_obj_and_method(key)
+ val = obj.send(method)
+ obj.send("#{method}=", val + value)
end
+ super hash_to_mongo(hash)
+ end
- def decrement(hash)
- hash.each do |key, value|
- obj, method = get_obj_and_method(key)
- val = obj.send(method)
- obj.send("#{method}=", val - value)
- end
- super hash_to_mongo(hash)
+ def decrement(hash)
+ hash.each do |key, value|
+ obj, method = get_obj_and_method(key)
+ val = obj.send(method)
+ obj.send("#{method}=", val - value)
end
+ super hash_to_mongo(hash)
+ end
- def push(hash)
- hash.each do |key, value|
- obj, method = get_obj_and_method(key)
- obj = obj.send(method)
- obj.push value
- end
- super hash_to_mongo(hash)
+ def push(hash)
+ hash.each do |key, value|
+ obj, method = get_obj_and_method(key)
+ obj = obj.send(method)
+ obj.push value
end
+ super hash_to_mongo(hash)
+ end
- def pull(hash)
- hash.each do |key, value|
- obj, method = get_obj_and_method(key)
- obj = obj.send(method)
- obj.delete_if { |e| e == value }
- end
- super hash_to_mongo(hash)
+ def pull(hash)
+ hash.each do |key, value|
+ obj, method = get_obj_and_method(key)
+ obj = obj.send(method)
+ obj.delete_if { |e| e == value }
end
+ super hash_to_mongo(hash)
+ end
- def add_to_set(hash)
- hash.each do |key, value|
- obj, method = get_obj_and_method(key)
- obj = obj.send(method)
- obj.push(value) unless obj.include?(value)
- end
- super hash_to_mongo(hash)
+ def add_to_set(hash)
+ hash.each do |key, value|
+ obj, method = get_obj_and_method(key)
+ obj = obj.send(method)
+ obj.push(value) unless obj.include?(value)
end
- alias push_uniq add_to_set
+ super hash_to_mongo(hash)
+ end
+ alias push_uniq add_to_set
- private
- def get_obj_and_method(key)
- children = key.to_s.split(/\./)
- method = children.pop
+ private
+ def get_obj_and_method(key)
+ children = key.to_s.split(/\./)
+ method = children.pop
- obj = self
- children.each do |child|
- obj = obj.send(child)
- end
+ obj = self
+ children.each do |child|
+ obj = obj.send(child)
+ end
- [obj, method]
- end
+ [obj, method]
+ end
- def hash_to_mongo(arg)
- if arg.is_a?(Hash)
- keys = arg.keys
- keys.each do |k|
- arg[k] = hash_to_mongo(arg[k])
- end
- arg
- else
- arg && arg.respond_to?(:to_mongo) ? arg.to_mongo : arg
- end
+ def hash_to_mongo(arg)
+ if arg.is_a?(Hash)
+ keys = arg.keys
+ keys.each do |k|
+ arg[k] = hash_to_mongo(arg[k])
end
+ arg
+ else
+ arg && arg.respond_to?(:to_mongo) ? arg.to_mongo : arg
+ end
end
end
end

0 comments on commit 7121f21

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