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
mongo_mapper-unstable-2010.08.08 examples/plugins.rb
mongo_mapper-unstable-2010.08.06 examples/plugins.rb
mongo_mapper-unstable-2010.08.05 examples/plugins.rb
mongo_mapper-unstable-2010.08.04 examples/plugins.rb
mongo_mapper-unstable-2010.08.03 examples/plugins.rb
mongo_mapper-unstable-2010.08.02 examples/plugins.rb
mongo_mapper-unstable-2010.08.01 examples/plugins.rb
mongo_mapper-unstable-2010.07.31 examples/plugins.rb
mongo_mapper-unstable-2010.07.30 examples/plugins.rb
mongo_mapper-unstable-2010.07.29 examples/plugins.rb
mongo_mapper-unstable-2010.07.28 examples/plugins.rb
mongo_mapper-unstable-2010.07.27 examples/plugins.rb
thorsson-mongo_mapper-0.8.2 examples/plugins.rb
mongo_mapper-unstable-2010.07.26 examples/plugins.rb
mongo_mapper-unstable-2010.07.23 examples/plugins.rb
mongo_mapper-unstable-2010.07.21 examples/plugins.rb
mongo_mapper-unstable-2010.07.20 examples/plugins.rb
mongo_mapper-unstable-2010.07.19 examples/plugins.rb
mongo_mapper-unstable-2010.07.18 examples/plugins.rb
mongo_mapper-unstable-2010.07.16 examples/plugins.rb