lib/machinist/mongo_mapper.rb in machinist_mongo-1.1.1 vs lib/machinist/mongo_mapper.rb in machinist_mongo-1.2.0

- old
+ new

@@ -1,10 +1,10 @@ require "machinist" require "machinist/blueprints" - begin require "mongo_mapper" + require "mongo_mapper/embedded_document" rescue LoadError puts "MongoMapper is not installed (gem install mongo_mapper)" exit end @@ -18,21 +18,21 @@ else @object[key] = value end end end - + class MongoMapperAdapter def self.has_association?(object, attribute) object.class.associations[attribute] end - + def self.class_for_association(object, attribute) association = object.class.associations[attribute] association && association.klass end - + def self.assigned_attributes_without_associations(lathe) attributes = {} lathe.assigned_attributes.each_pair do |attribute, value| association = lathe.object.class.associations[attribute] if association && association.belongs_to? && !value.nil? @@ -55,21 +55,22 @@ end lathe.object(&block) end def make_unsaved(*args) - returning(Machinist.with_save_nerfed { make(*args) }) do |object| + Machinist.with_save_nerfed{ make(*args) }.tap do |object| yield object if block_given? end end def plan(*args) lathe = Lathe.run(Machinist::MongoMapperAdapter, self.new, *args) Machinist::MongoMapperAdapter.assigned_attributes_without_associations(lathe) end end - + module EmbeddedDocument + def make(*args, &block) lathe = Lathe.run(Machinist::MongoMapperAdapter, self.new, *args) lathe.object(&block) end end