lib/cantango/rules/adaptor.rb in cantango-0.9.3.2 vs lib/cantango/rules/adaptor.rb in cantango-0.9.4
- old
+ new
@@ -1,30 +1,35 @@
module CanTango
module Rules
module Adaptor
- autoload_modules :Generic
- autoload_modules :ActiveRecord, :Mongoid
+ 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
- adaptor_class = const.constantize
- base.class.send(:include, adaptor(orm)) if object.kind_of?(adaptor_class)
- rescue
+ base.class.send :include, get_adapter(object, const.constantize, orm)
+ rescue
next
end
end
end
- def adaptor orm
+ def get_adapter object, adaptor_class, orm
+ object.kind_of?(adaptor_class) ? adaptor_for(orm) : adaptor_for(:generic)
+ end
+
+ def adaptor_for orm
"CanTango::Rules::Adaptor::#{orm.to_s.camelize}".constantize
end
def orm_map
{
:active_record => "ActiveRecord::Base",
- :mongoid => "Mongoid::Document"
+ :data_mapper => "DataMapper::Resource",
+ :mongoid => "Mongoid::Document",
+ :mongo_mapper => "MongoMapper::Document"
}
end
end
end
end