lib/pickle/adapter.rb in pickle-0.3.5 vs lib/pickle/adapter.rb in pickle-0.4.0
- old
+ new
@@ -23,18 +23,19 @@
cattr_writer :model_classes
end
self.model_classes = nil
- # Include this module into your adapter
+ # Include this module into your ORM adapter
# this will register the adapter with pickle and it will be picked up for you
# To create an adapter you should create an inner constant "PickleAdapter"
#
# e.g. ActiveRecord::Base::PickleAdapter
#
# @see pickle/adapters/active_record
# @see pickle/adapters/datamapper
+ # @see pickle/adapters/mongoid
module Base
def self.included(base)
adapters << base
end
@@ -67,10 +68,14 @@
end
def find_all_models(klass, conditions)
klass.const_get(:PickleAdapter).find_all_models(klass, conditions)
end
+
+ def create_model(klass, attributes)
+ klass.const_get(:PickleAdapter).create_model(klass, attributes)
+ end
end
# machinist adapter
class Machinist < Adapter
def self.factories
@@ -111,21 +116,22 @@
def create(attrs = {})
Factory(@name, attrs)
end
end
- # fallback active record adapter
- class ActiveRecord < Adapter
+ # ORM adapter. If you have no factory adapter, you can use this adapter to
+ # use your orm as 'factory' - ie create objects
+ class Orm < Adapter
def self.factories
- ::ActiveRecord::Base::PickleAdapter.model_classes.map{|k| new(k)}
+ model_classes.map{|k| new(k)}
end
def initialize(klass)
@klass, @name = klass, klass.name.underscore.gsub('/','_')
end
def create(attrs = {})
- @klass.send(:create!, attrs)
+ Pickle::Adapter.create_model(@klass, attrs)
end
end
end
end