Sha256: cf6f507ec521403ee1cb287a28565d319dc3207ef098bc525d47f0467169f58d
Contents?: true
Size: 943 Bytes
Versions: 8
Compression:
Stored size: 943 Bytes
Contents
module CanTango module Adaptor autoload_modules :Generic, :Relational, :Mongo autoload_modules :ActiveRecord, :DataMapper, :Mongoid, :MongoMapper # include adaptor depending on which ORM the object inherits from or includes def use_adaptor! base, object orm_map.each_pair do |orm, const| begin base.class.send :include, get_adapter(object, const.constantize, orm) rescue next end end end def get_adapter object, adaptor_class, orm object.kind_of?(adaptor_class) ? adaptor_for(orm) : adaptor_for(:generic) end def adaptor_for orm "#{self.class}::#{orm.to_s.camelize}".constantize end def orm_map { :active_record => "ActiveRecord::Base", :data_mapper => "DataMapper::Resource", :mongoid => "Mongoid::Document", :mongo_mapper => "MongoMapper::Document" } end end end
Version data entries
8 entries across 8 versions & 1 rubygems