Sha256: b8b7efe6fde551d9c4938a10fda6560b524866b4a5e09b7cda235c7e8809a8cf

Contents?: true

Size: 639 Bytes

Versions: 10

Compression:

Stored size: 639 Bytes

Contents

# frozen_string_literal: true

module Mutant
  class Matcher
    # Matcher for all descendants by constant name
    class Descendants < self
      include Anima.new(:const_name)

      def call(env)
        const = env.world.try_const_get(const_name) or return EMPTY_ARRAY

        Chain.new(
          matchers: matched_scopes(env, const).map { |scope| Scope.new(scope: scope.raw) }
        ).call(env)
      end

    private

      def matched_scopes(env, const)
        env.matchable_scopes.select do |scope|
          scope.raw.equal?(const) || const > scope.raw
        end
      end
    end # Descendant
  end # Matcher
end # Mutant

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mutant-0.11.28 lib/mutant/matcher/descendants.rb
mutant-0.11.27 lib/mutant/matcher/descendants.rb
mutant-0.11.26 lib/mutant/matcher/descendants.rb
mutant-0.11.25 lib/mutant/matcher/descendants.rb
mutant-0.11.24 lib/mutant/matcher/descendants.rb
mutant-0.11.23 lib/mutant/matcher/descendants.rb
mutant-0.11.22 lib/mutant/matcher/descendants.rb
mutant-0.11.21 lib/mutant/matcher/descendants.rb
mutant-0.11.20 lib/mutant/matcher/descendants.rb
mutant-0.11.19 lib/mutant/matcher/descendants.rb