forked from mongomapper/mongomapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugins.rb
38 lines (31 loc) · 785 Bytes
/
plugins.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
require 'mongo_mapper'
require 'pp'
MongoMapper.database = 'testing'
# To create your own plugin, just create a module that
# extends ActiveSupport::Concern.
module FooPlugin
extend ActiveSupport::Concern
# ClassMethods module will automatically get extended
module ClassMethods
def foo
'Foo class method!'
end
end
def foo
'Foo instance method!'
end
# Any configuration can be done in the #included block, which gets
# class evaled. Feel free to add keys, validations, or anything else.
included do
puts "Configuring #{self}..."
key :foo, String
end
end
class User
include MongoMapper::Document
plugin FooPlugin
end
puts User.foo
puts User.new.foo
puts User.key?(:foo)