Sha256: e93d4fe3353907995c795a46b5f3b55f5e3102d27e669732aa9895aec9bc85f5

Contents?: true

Size: 1.11 KB

Versions: 35

Compression:

Stored size: 1.11 KB

Contents

module MongoMapper
  module Support
    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
end

Version data entries

35 entries across 35 versions & 7 rubygems

Version Path
mongo_mapper-unstable-2010.2.23 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.2.22 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.2.19 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.2.18 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.2.17 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.2.16 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.2.15 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.2.12 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.2.11 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.2.10 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-0.7.0 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.2.9 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.2.8 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.2.5 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.2.4 lib/mongo_mapper/support/descendant_appends.rb