Removing files?
This commit is contained in:
parent
5ea17719be
commit
3579f47eda
2 changed files with 0 additions and 100 deletions
|
|
@ -1,23 +0,0 @@
|
||||||
#require 'rubygems' # not necessary for Ruby 1.9
|
|
||||||
require 'mongo'
|
|
||||||
|
|
||||||
Mongo::Logger.logger.level = ::Logger::FATAL
|
|
||||||
|
|
||||||
include Mongo
|
|
||||||
|
|
||||||
class MongoConnect
|
|
||||||
def initialize(dbname, collname)
|
|
||||||
@db = Mongo::Client.new(
|
|
||||||
["127.0.0.1:27017"],
|
|
||||||
:database => dbname)
|
|
||||||
@coll = @db[collname.to_sym]
|
|
||||||
end
|
|
||||||
|
|
||||||
def db()
|
|
||||||
return @db
|
|
||||||
end
|
|
||||||
|
|
||||||
def collection()
|
|
||||||
return @coll
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
@ -1,77 +0,0 @@
|
||||||
class MongoDocumentWrapper
|
|
||||||
@mc = nil # MongoConnect instance
|
|
||||||
@doc = nil # MongoDocument instance....
|
|
||||||
@id = nil # BSON ID for the Doc
|
|
||||||
|
|
||||||
def initialize(mc, doc=nil)
|
|
||||||
@mc = mc
|
|
||||||
|
|
||||||
if doc == nil then
|
|
||||||
create()
|
|
||||||
else
|
|
||||||
@id = doc['_id']
|
|
||||||
@doc = doc
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def create()
|
|
||||||
@id = BSON::ObjectId.new()
|
|
||||||
|
|
||||||
doc = get_default_doc()
|
|
||||||
doc['_id'] = @id
|
|
||||||
|
|
||||||
@doc = doc
|
|
||||||
|
|
||||||
@mc.collection.insert_one(@doc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def load()
|
|
||||||
@doc = @mc.collection().find({"_id" => @id}).first()
|
|
||||||
end
|
|
||||||
|
|
||||||
# save and grab the ID and doc....
|
|
||||||
def set(params={}, persist=true)
|
|
||||||
@doc.merge!(params)
|
|
||||||
|
|
||||||
if persist == true then
|
|
||||||
persist()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def get(field)
|
|
||||||
return @doc[field]
|
|
||||||
end
|
|
||||||
|
|
||||||
def persist()
|
|
||||||
@mc.collection().update_one({"_id" => @id}, @doc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def delete()
|
|
||||||
if @id == nil then
|
|
||||||
die
|
|
||||||
end
|
|
||||||
|
|
||||||
@mc.collection().delete_one({"_id" => @id})
|
|
||||||
end
|
|
||||||
|
|
||||||
def update(query)
|
|
||||||
@mc.collection().update_one({"_id" => @id}, query)
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_default_doc()
|
|
||||||
puts "Override this in ent class"
|
|
||||||
return {}
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.build_from(mc, doc=nil)
|
|
||||||
if doc == nil then
|
|
||||||
puts "wtf whoops??"
|
|
||||||
else
|
|
||||||
@mc = mc
|
|
||||||
@doc = doc
|
|
||||||
@id = @doc['_id']
|
|
||||||
end
|
|
||||||
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue