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
pwnash-mongo_mapper-0.7.5 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-0.7.6 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-0.7.5 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper_ign-0.7.4 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-0.7.4 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-0.7.3 lib/mongo_mapper/support/descendant_appends.rb
numon-0.0.1 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-0.7.2 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-0.7.1 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.3.8 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.3.5 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.3.4 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.3.3 lib/mongo_mapper/support/descendant_appends.rb
drogus-mongo_mapper-0.6.10 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-rails3-0.7.0.1 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.2.28 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.2.27 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.2.26 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.2.25 lib/mongo_mapper/support/descendant_appends.rb
mongo_mapper-unstable-2010.2.24 lib/mongo_mapper/support/descendant_appends.rb