Sha256: a5c5850fd3e20de7ae1a07cb4d633595c06d1d1cab6ade7f6f2b70c8705906dd

Contents?: true

Size: 871 Bytes

Versions: 60

Compression:

Stored size: 871 Bytes

Contents

$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.
module FooPlugin
  
  # ClassMethods module will automatically get extended
  module ClassMethods
    def foo
      'Foo class method!'
    end
  end

  # InstanceMethods module will automatically get included
  module InstanceMethods
    def foo
      'Foo instance method!'
    end
  end

  # If present, configure method will be called and passed the 
  # model as an argument. Feel free to class_eval or add keys.
  # if method is not present, it doesn't call it.
  def self.configure(model)
    puts "Configuring #{model}..."
    model.key :foo, String
  end

end

class User
  include MongoMapper::Document
  plugin FooPlugin
end

puts User.foo
puts User.new.foo
puts User.key?(:foo)

Version data entries

60 entries across 60 versions & 7 rubygems

Version Path
jonbell-mongo_mapper-0.8.6 examples/plugins.rb
ign-mongo_mapper-0.8.6.2 examples/plugins.rb
ign-mongo_mapper-0.8.6.1 examples/plugins.rb
ssherman-mongo_mapper-0.8.6 examples/plugins.rb
mongo_mapper-0.8.6 examples/plugins.rb
mongo_mapper-0.8.5 examples/plugins.rb
honkster-mongo_mapper-0.8.4 examples/plugins.rb
mongo_mapper-0.8.4 examples/plugins.rb
mongo_mapper-unstable-2010.08.19 examples/plugins.rb
mongo_mapper-unstable-2010.08.18 examples/plugins.rb
mongo_mapper-unstable-2010.08.17 examples/plugins.rb
mongo_mapper-unstable-2010.08.16 examples/plugins.rb
mongo_mapper-unstable-2010.08.15 examples/plugins.rb
mongo_mapper-unstable-2010.08.14 examples/plugins.rb
mongo_mapper-unstable-2010.08.13 examples/plugins.rb
mongo_mapper-unstable-2010.08.12 examples/plugins.rb
mongo_mapper-unstable-2010.08.11 examples/plugins.rb
mongo_mapper-unstable-2010.08.10 examples/plugins.rb
mongo_mapper-unstable-2010.08.09 examples/plugins.rb
mongo_mapper-0.8.3 examples/plugins.rb