Sha256: f2b7654b3a87769bc83b6b193866b227f5f71e68e0106e1f48bfc48f69ada911
Contents?: true
Size: 1.17 KB
Versions: 18
Compression:
Stored size: 1.17 KB
Contents
# -*- encoding : utf-8 -*- module Dao class << Conducer def autocrud! include(Conducer::AutoCRUD) end alias_method('crud!', 'autocrud!') end class Conducer module AutoCRUD Code = proc do class << self def db @db ||= Db.instance end def db_collection db.collection(collection_name) end def all(*args) hashes = db_collection.all() hashes.map{|hash| new(hash)} end def find(*args) options = args.extract_options!.to_options! id = args.shift || options[:id] hash = db_collection.find(id) new(hash) if hash end end def save id = self.class.db_collection.save(@attributes) @attributes.set(:id => id) true end def destroy id = self.id if id self.class.db_collection.destroy(id) @attributes.rm(:id) end id end end def AutoCRUD.included(other) super ensure other.module_eval(&Code) end end end end
Version data entries
18 entries across 18 versions & 1 rubygems