Permalink
Browse files

get rid of InstanceMethods module

  • Loading branch information...
1 parent bfdf4f9 commit 1d42259b0f52c2103a188c8bc7fbb2b425aef6cb @mislav committed Jan 29, 2012
Showing with 36 additions and 38 deletions.
  1. +36 −38 lib/mingo/persistence.rb
@@ -3,7 +3,7 @@
class Mingo
module Persistence
extend ActiveSupport::Concern
-
+
module ClassMethods
def create(obj = nil)
new(obj).tap do |object|
@@ -12,52 +12,50 @@ def create(obj = nil)
end
end
end
-
- module InstanceMethods
- def initialize(*args)
- @destroyed = false
- super
- end
- def persisted?
- !!id
- end
+ def initialize(*args)
+ @destroyed = false
+ super
+ end
- def save(options = {})
- if persisted?
- hash = values_for_update
- unless %w[$set $unset] == hash.keys && hash.values.all? { |v| v.empty? }
- update(hash, options)
- end
- else
- self['_id'] = self.class.collection.insert(self.to_hash, options)
+ def persisted?
+ !!id
+ end
+
+ def save(options = {})
+ if persisted?
+ hash = values_for_update
+ unless %w[$set $unset] == hash.keys && hash.values.all? { |v| v.empty? }
+ update(hash, options)
end
+ else
+ self['_id'] = self.class.collection.insert(self.to_hash, options)
end
+ end
- def update(doc, options = {})
- self.class.collection.update({'_id' => self.id}, doc, options)
- end
+ def update(doc, options = {})
+ self.class.collection.update({'_id' => self.id}, doc, options)
+ end
- def reload
- doc = self.class.first(id, :transformer => nil)
- replace doc
- end
+ def reload
+ doc = self.class.first(id, :transformer => nil)
+ replace doc
+ end
- def destroy
- self.class.collection.remove('_id' => self.id)
- @destroyed = true
- self.freeze
- end
+ def destroy
+ self.class.collection.remove('_id' => self.id)
+ @destroyed = true
+ self.freeze
+ end
- def destroyed?
- @destroyed
- end
-
- private
+ def destroyed?
+ @destroyed
+ end
- def values_for_update
- self.to_hash
- end
+ private
+
+ def values_for_update
+ self.to_hash
end
end
end

0 comments on commit 1d42259

Please sign in to comment.