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.07.15 examples/plugins.rb
mongo_mapper-unstable-2010.07.14 examples/plugins.rb
mongo_mapper-unstable-2010.07.13 examples/plugins.rb
mongo_mapper-unstable-2010.07.12 examples/plugins.rb
mongo_mapper-unstable-2010.07.09 examples/plugins.rb
mongo_mapper-unstable-2010.07.08 examples/plugins.rb
mongo_mapper-unstable-2010.07.07 examples/plugins.rb
mongo_mapper-unstable-2010.07.06 examples/plugins.rb
mongo_mapper-unstable-2010.07.05 examples/plugins.rb
mongo_mapper-unstable-2010.07.02 examples/plugins.rb
mongo_mapper-unstable-2010.07.01 examples/plugins.rb
mongo_mapper-unstable-2010.06.30 examples/plugins.rb
mongo_mapper-unstable-2010.06.29 examples/plugins.rb
mongo_mapper-unstable-2010.06.28 examples/plugins.rb
mongo_mapper-unstable-2010.06.25 examples/plugins.rb
mongo_mapper-unstable-2010.06.24 examples/plugins.rb
mongo_mapper-unstable-2010.06.23 examples/plugins.rb
mongo_mapper-0.8.2 examples/plugins.rb
mongo_mapper-0.8.1 examples/plugins.rb
mongo_mapper-0.8.0 examples/plugins.rb