Sha256: fe1aa0265e52098feff1f831a2631954b6f5b2b437b6307b4d77a99948ded967

Contents?: true

Size: 1.02 KB

Versions: 27

Compression:

Stored size: 1.02 KB

Contents

module MongoMapper
  module DescendantAppends
    def included(model)
      extra_extensions.each { |extension| model.extend(extension) }
      extra_inclusions.each { |inclusion| model.send(:include, inclusion) }
      descendants << model
    end
    
    # @api public
    def descendants
      @descendants ||= Set.new
    end

    # @api public
    def append_extensions(*extensions)
      extra_extensions.concat extensions

      # Add the extension to existing descendants
      descendants.each do |model|
        extensions.each { |extension| model.extend(extension) }
      end
    end

    # @api public
    def append_inclusions(*inclusions)
      extra_inclusions.concat inclusions

      # Add the inclusion to existing descendants
      descendants.each do |model|
        inclusions.each { |inclusion| model.send(:include, inclusion) }
      end
    end

    # @api private
    def extra_extensions
      @extra_extensions ||= []
    end

    # @api private
    def extra_inclusions
      @extra_inclusions ||= []
    end
  end
end

Version data entries

27 entries across 27 versions & 3 rubygems

Version Path
jmonteiro-mongo_mapper-0.1.5 lib/mongo_mapper/descendant_appends.rb
mongo_mapper-unstable-2010.1.17 lib/mongo_mapper/descendant_appends.rb
jmonteiro-mongo_mapper-0.1.4 lib/mongo_mapper/descendant_appends.rb
jmonteiro-mongo_mapper-0.1.2 lib/mongo_mapper/descendant_appends.rb
jmonteiro-mongo_mapper-0.1.1 lib/mongo_mapper/descendant_appends.rb
jmonteiro-mongo_mapper-0.1.0 lib/mongo_mapper/descendant_appends.rb
mongo_mapper-unstable-2010.1.12 lib/mongo_mapper/descendant_appends.rb