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
novelys_mongo_mapper-0.6.12 lib/novelys_mongo_mapper/descendant_appends.rb
novelys_mongo_mapper-0.6.11 lib/novelys_mongo_mapper/descendant_appends.rb
mongo_mapper-unstable-2010.2.3 lib/mongo_mapper/descendant_appends.rb
novelys_mongo_mapper-0.6.10 lib/mongo_mapper/descendant_appends.rb
mongo_mapper-unstable-2010.2.2 lib/mongo_mapper/descendant_appends.rb
mongo_mapper-unstable-2010.2.1 lib/mongo_mapper/descendant_appends.rb
mongo_mapper-unstable-2010.1.31 lib/mongo_mapper/descendant_appends.rb
mongo_mapper-unstable-2010.1.30 lib/mongo_mapper/descendant_appends.rb
mongo_mapper-unstable-2010.1.29 lib/mongo_mapper/descendant_appends.rb
mongo_mapper-unstable-2010.1.28 lib/mongo_mapper/descendant_appends.rb
mongo_mapper-unstable-2010.1.27 lib/mongo_mapper/descendant_appends.rb
mongo_mapper-unstable-2010.1.26 lib/mongo_mapper/descendant_appends.rb
mongo_mapper-unstable-2010.1.25 lib/mongo_mapper/descendant_appends.rb
mongo_mapper-unstable-2010.1.22 lib/mongo_mapper/descendant_appends.rb
mongo_mapper-unstable-2010.1.21 lib/mongo_mapper/descendant_appends.rb
mongo_mapper-unstable-2010.1.20 lib/mongo_mapper/descendant_appends.rb
mongo_mapper-unstable-2010.1.19 lib/mongo_mapper/descendant_appends.rb
jmonteiro-mongo_mapper-0.1.7 lib/mongo_mapper/descendant_appends.rb
mongo_mapper-unstable-2010.1.18 lib/mongo_mapper/descendant_appends.rb
jmonteiro-mongo_mapper-0.1.6 lib/mongo_mapper/descendant_appends.rb