Plugins power MarkMapper from the ground up. Every piece of functionality is a plugin, making MarkMapper easily extendable. If you need some crazy functionality, just build it.
A plugin, in MarkMapper terms, is simply a module that extends ActiveSupport::Concern.
module ActsAsListFu
extend ActiveSupport::Concern
included do
key :position, Integer, :default => 1
end
module ClassMethods
def reorder(ids)
# reorder ids...
end
end
module InstanceMethods
def move_to_top
# move to top
end
end
endOnce you have your plugin defined, you can use it by calling the plugin method in your model:
class Item
include MarkMapper::Document
plugin ActsAsListFu
endIf you would like to use a plugin in all documents or embedded documents, call plugin on the Document or EmbeddedDocument module:
MarkMapper::Document.plugin(ActsAsListFu)
MarkMapper::EmbeddedDocument.plugin(ActsAsListFu)
//