Module: MongoLight::Document::InstanceMethods
- Defined in:
- lib/mongo_light/document.rb
Instance Method Summary collapse
- #collection ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
- #id ⇒ Object
- #id=(value) ⇒ Object
- #initialize(attributes = {}) ⇒ Object
- #save(options = nil) ⇒ Object
- #save!(options = {}) ⇒ Object
Instance Method Details
#collection ⇒ Object
85 86 87 |
# File 'lib/mongo_light/document.rb', line 85 def collection self.class.collection end |
#eql?(other) ⇒ Boolean Also known as: ==
69 70 71 |
# File 'lib/mongo_light/document.rb', line 69 def eql?(other) other.is_a?(self.class) && id == other.id end |
#hash ⇒ Object
73 74 75 |
# File 'lib/mongo_light/document.rb', line 73 def hash id.hash end |
#id ⇒ Object
76 77 78 |
# File 'lib/mongo_light/document.rb', line 76 def id @attributes[:_id] || @attributes['_id'] end |
#id=(value) ⇒ Object
79 80 81 |
# File 'lib/mongo_light/document.rb', line 79 def id=(value) @attributes[:_id] = value end |
#initialize(attributes = {}) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/mongo_light/document.rb', line 58 def initialize(attributes = {}) attributes = {} unless attributes @attributes = {:_id => (attributes['_id'] || attributes[:_id] || Id.new)} attributes.each do |k,v| if self.class.map_include?(k) @attributes[k] = v elsif k != :_id && k != '_id' send("#{k}=", v) end end end |
#save(options = nil) ⇒ Object
88 89 90 91 92 |
# File 'lib/mongo_light/document.rb', line 88 def save( = nil) opts = ! || .include?(:safe) ? : {:safe => } opts[:safe].delete(:w) if MongoLight.configuration.skip_replica_concern && opts && opts.include?(:safe) && opts[:safe].is_a?(Hash) collection.save(self.class.map(@attributes), opts || {}) end |
#save!(options = {}) ⇒ Object
93 94 95 |
# File 'lib/mongo_light/document.rb', line 93 def save!( = {}) save({:safe => true}.merge()) end |