Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converted mongo_mapper extension as an ActiveSupport::Concern #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 35 additions & 21 deletions lib/machinist/mongo_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,40 +46,54 @@ def self.assigned_attributes_without_associations(lathe)
end

module MongoMapperExtensions

module Document
def make(*args, &block)
lathe = Lathe.run(Machinist::MongoMapperAdapter, self.new, *args)
unless Machinist.nerfed?
lathe.object.save!
lathe.object.reload
extend ActiveSupport::Concern

module ClassMethods
include Machinist::Blueprints::ClassMethods

def make(*args, &block)
lathe = Lathe.run(Machinist::MongoMapperAdapter, self.new, *args)
unless Machinist.nerfed?
lathe.object.save!
lathe.object.reload
end
lathe.object(&block)
end
lathe.object(&block)
end

def make_unsaved(*args)
Machinist.with_save_nerfed{ make(*args) }.tap do |object|
yield object if block_given?
def make_unsaved(*args)
Machinist.with_save_nerfed{ make(*args) }.tap do |object|
yield object if block_given?
end
end
end

def plan(*args)
lathe = Lathe.run(Machinist::MongoMapperAdapter, self.new, *args)
Machinist::MongoMapperAdapter.assigned_attributes_without_associations(lathe)
def plan(*args)
lathe = Lathe.run(Machinist::MongoMapperAdapter, self.new, *args)
Machinist::MongoMapperAdapter.assigned_attributes_without_associations(lathe)
end
end
end

module EmbeddedDocument
extend ActiveSupport::Concern

def make(*args, &block)
lathe = Lathe.run(Machinist::MongoMapperAdapter, self.new, *args)
lathe.object(&block)
module ClassMethods
include Machinist::Blueprints::ClassMethods

def make(*args, &block)
lathe = Lathe.run(Machinist::MongoMapperAdapter, self.new, *args)
lathe.object(&block)
end
end
end
end
end

MongoMapper::Document.append_extensions(Machinist::Blueprints::ClassMethods)
MongoMapper::Document.append_extensions(Machinist::MongoMapperExtensions::Document)
module MongoMapper::Document
include Machinist::MongoMapperExtensions::Document
end

MongoMapper::EmbeddedDocument.append_extensions(Machinist::Blueprints::ClassMethods)
MongoMapper::EmbeddedDocument.append_extensions(Machinist::MongoMapperExtensions::EmbeddedDocument)
module MongoMapper::EmbeddedDocument
include Machinist::MongoMapperExtensions::EmbeddedDocument
end