Sha256: 62b4be3d729da5a92fbfde6ad2cdb30efb31c2bd18e58cd600a8b6469c84a804

Contents?: true

Size: 775 Bytes

Versions: 28

Compression:

Stored size: 775 Bytes

Contents

module Mongoid #:nodoc:
  module Associations #:nodoc:
    module Decorator #:nodoc:
      def self.included(base)
        base.class_eval do
          attr_reader :document

          # Grabs all the public methods on the document and adds them
          # to the association class. This is preferred over method_missing
          # since we can ask the class for its methods and get an
          # accurate list.
          def decorate!
            meths = document.public_methods
            meths.each do |method|
              (class << self; self; end).class_eval do
                define_method method do |*args|
                  document.send method, *args
                end
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
mongoid-0.9.4 lib/mongoid/associations/decorator.rb
mongoid-0.9.3 lib/mongoid/associations/decorator.rb
mongoid-0.9.2 lib/mongoid/associations/decorator.rb
mongoid-0.9.1 lib/mongoid/associations/decorator.rb
mongoid-0.9.0 lib/mongoid/associations/decorator.rb
mongoid-0.8.10 lib/mongoid/associations/decorator.rb
mongoid-0.8.9 lib/mongoid/associations/decorator.rb
mongoid-0.8.8 lib/mongoid/associations/decorator.rb
mongoid-0.8.7 lib/mongoid/associations/decorator.rb
mongoid-0.8.6 lib/mongoid/associations/decorator.rb
mongoid-0.8.5 lib/mongoid/associations/decorator.rb
mongoid-0.8.4 lib/mongoid/associations/decorator.rb
mongoid-0.8.3 lib/mongoid/associations/decorator.rb
mongoid-0.8.2 lib/mongoid/associations/decorator.rb
mongoid-0.8.1 lib/mongoid/associations/decorator.rb
mongoid-0.7.10 lib/mongoid/associations/decorator.rb
mongoid-0.7.9 lib/mongoid/associations/decorator.rb
mongoid-0.7.8 lib/mongoid/associations/decorator.rb
mongoid-0.7.7 lib/mongoid/associations/decorator.rb
mongoid-0.7.6 lib/mongoid/associations/decorator.rb