Sha256: 97178882d1db7748533a695090e73751885ff1e4a6e746bf31a89990a0d25db7

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

module Mutant
  class Matcher

    # Matcher for specific namespace
    class Namespace < self
      include Concord::Public.new(:namespace)

      # Enumerate subjects
      #
      # @return [self]
      #   if block given
      #
      # @return [Enumerator<Subject>]
      #   otherwise
      #
      # @api private
      #
      def each(&block)
        return to_enum unless block_given?

        scopes.each do |scope|
          Scope.each(scope, &block)
        end

        self
      end

    private

      # Return pattern
      #
      # @return [Regexp]
      #
      # @api private
      #
      def pattern
        %r(\A#{Regexp.escape(namespace.name)}(?:::)?)
      end
      memoize :pattern

      # Return scope enumerator
      #
      # @return [Enumerable<Object>]
      #
      # @api private
      #
      def scopes(&block)
        return to_enum(__method__) unless block_given?

        ::ObjectSpace.each_object(Module).each do |scope|
          emit_scope(scope, &block)
        end
      end

      # Yield scope if name matches pattern
      #
      # @param [Module,Class] scope
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_scope(scope)
        if pattern =~ scope.name
          yield scope
        end
      end

    end # Namespace
  end # Matcher
end # Mutant

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mutant-0.3.0.beta3 lib/mutant/matcher/namespace.rb
mutant-0.3.0.beta2 lib/mutant/matcher/namespace.rb