lib/bigamy.rb in bigamy-0.1.2 vs lib/bigamy.rb in bigamy-0.2.0
- old
+ new
@@ -22,12 +22,15 @@
end
end
module Base
def self.configure(model)
- model.class_inheritable_accessor :bigamy_associations
- model.bigamy_associations = {}
+ class << model
+ def bigamy_associations
+ @bigamy_associations ||= {}
+ end
+ end
end
end
module Mongo
@@ -36,10 +39,11 @@
end
module ClassMethods
def divorce_everyone
self.bigamy_associations.each {|k,v| v.divorce_everyone }
+ self.bigamy_associations.clear
end
def belongs_to_ar name, options = {}
bigamy_associations[name] = MongoBelongsTo.new(self, name, options)
end
@@ -55,11 +59,11 @@
module InstanceMethods
def set_value c, val
write_key c, val
end
-
+
def read_val c
read_key c
end
def export_id_val i
@@ -68,10 +72,16 @@
def import_id_val i
i
end
end
+
+ module PluginAddition
+ def self.included(model)
+ model.plugin Bigamy::Mongo
+ end
+ end
end
module ActiveRecord
def self.configure(model)
::Bigamy::Base.configure(model)
@@ -81,10 +91,11 @@
end
module ClassMethods
def divorce_everyone
self.bigamy_associations.each {|k,v| v.divorce_everyone }
+ self.bigamy_associations.clear
end
def belongs_to_mm name, options = {}
bigamy_associations[name] = ARBelongsTo.new(self, name, options)
end
@@ -100,11 +111,11 @@
module InstanceMethods
def set_value c, val
self[c] = val
end
-
+
def read_val c
read_attribute c
end
def export_id_val i
@@ -116,5 +127,8 @@
end
end
end
end
+
+MongoMapper::Document.append_inclusions(Bigamy::Mongo::PluginAddition)
+Bigamy::ActiveRecord.configure(ActiveRecord::Base)