Sha256: 70ab84e3a4c7691dbb32185a49ece20a925b75fd21096c36152db7d3cc210954

Contents?: true

Size: 1.45 KB

Versions: 13

Compression:

Stored size: 1.45 KB

Contents

# encoding: utf-8

module Mutant
  class Matcher

    # Matcher for specific namespace
    class Namespace < self
      include Concord::Public.new(:cache, :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(cache, scope, &block)
        end

        self
      end

    private

      # Return pattern
      #
      # @return [Regexp]
      #
      # @api private
      #
      def pattern
        /\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)
        name = scope.name
        # FIXME: Fix nokogiri to return a string here
        return unless name.kind_of?(String)
        if pattern =~ name
          yield scope
        end
      end

    end # Namespace
  end # Matcher
end # Mutant

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
mutant-0.3.6 lib/mutant/matcher/namespace.rb
mutant-0.3.5 lib/mutant/matcher/namespace.rb
mutant-0.3.4 lib/mutant/matcher/namespace.rb
mutant-0.3.3 lib/mutant/matcher/namespace.rb
mutant-0.3.2 lib/mutant/matcher/namespace.rb
mutant-0.3.1 lib/mutant/matcher/namespace.rb
mutant-0.3.0 lib/mutant/matcher/namespace.rb
mutant-0.3.0.rc5 lib/mutant/matcher/namespace.rb
mutant-0.3.0.rc4 lib/mutant/matcher/namespace.rb
mutant-0.3.0.rc3 lib/mutant/matcher/namespace.rb
mutant-0.3.0.rc2 lib/mutant/matcher/namespace.rb
mutant-0.3.0.rc1 lib/mutant/matcher/namespace.rb
mutant-0.3.0.beta22 lib/mutant/matcher/namespace.rb