You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: expander.rb
    path of file: ./repos/karafka/lib/karafka/routing/features/base
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

module Karafka
  module Routing
    module Features
      class Base
        # Routing builder expander that injects feature related drawing operations into it
        class Expander < Module
          # @param scope [Module] feature scope in which contract and other things should be
          # @return [Expander] builder expander instance
          def initialize(scope)
            super()
            @scope = scope
          end

          # Builds anonymous module that alters how `#draw` behaves allowing the feature contracts
          # to run.
          # @param mod [::Karafka::Routing::Bui
    
          def prepended_module
            scope = @scope

            Module.new do
              # Runs validations related to this feature on a routing resources
              #
              # @param block [Proc] routing defining block
              define_method :draw do |&block|
                result = super(&block)

                each do |consumer_group|
                  if scope::Contracts.const_defined?('ConsumerGroup', false)
                    scope::Contracts::ConsumerGroup.new.validate!(consumer_group.to_h)
                  end

                  next unless scope::Contracts.const_defined?('Topic', false)

                  consumer_group.topics.each do |topic|
                    scope::Contracts::Topic.new.validate!(topic.to_h)
                  end
                end

                result
              end
            end