Sha256: fae7f20fb4598ea72e45d4bdb3b8a56b67e69efaf9a885c7ed70b36b505cbd10

Contents?: true

Size: 1.37 KB

Versions: 29

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module Mutant
  class Expression

    # Abstract base class for methods expression
    class Methods < self
      include Anima.new(
        :scope_name,
        :scope_symbol
      )

      private(*anima.attribute_names)

      MATCHERS = {
        '.' => [Matcher::Methods::Singleton, Matcher::Methods::Metaclass].freeze,
        '#' => [Matcher::Methods::Instance].freeze
      }.freeze

      private_constant(*constants(false))

      REGEXP = /\A#{SCOPE_NAME_PATTERN}#{SCOPE_SYMBOL_PATTERN}\z/.freeze

      def initialize(*)
        super
        @syntax = [scope_name, scope_symbol].join.freeze
      end

      # Syntax of expression
      #
      # @return [String]
      attr_reader :syntax

      # Matcher on expression
      #
      # @return [Matcher::Method]
      def matcher
        matcher_candidates = MATCHERS.fetch(scope_symbol)
          .map { |submatcher| submatcher.new(scope) }

        Matcher::Chain.new(matcher_candidates)
      end

      # Length of match with other expression
      #
      # @param [Expression] expression
      #
      # @return [Integer]
      def match_length(expression)
        if expression.syntax.start_with?(syntax)
          syntax.length
        else
          0
        end
      end

    private

      def scope
        Object.const_get(scope_name)
      end

    end # Methods
  end # Expression
end # Mutant

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
mutant-0.11.18 lib/mutant/expression/methods.rb
mutant-0.11.17 lib/mutant/expression/methods.rb
mutant-0.11.16 lib/mutant/expression/methods.rb
mutant-0.11.15 lib/mutant/expression/methods.rb
mutant-0.11.14 lib/mutant/expression/methods.rb
mutant-0.11.13 lib/mutant/expression/methods.rb
mutant-0.11.12 lib/mutant/expression/methods.rb
mutant-0.11.11 lib/mutant/expression/methods.rb
mutant-0.11.10 lib/mutant/expression/methods.rb
mutant-0.11.9 lib/mutant/expression/methods.rb
mutant-0.11.8 lib/mutant/expression/methods.rb
mutant-0.11.7 lib/mutant/expression/methods.rb
mutant-0.11.6 lib/mutant/expression/methods.rb
mutant-0.11.5 lib/mutant/expression/methods.rb
mutant-0.11.4 lib/mutant/expression/methods.rb
mutant-0.11.3 lib/mutant/expression/methods.rb
mutant-0.11.2 lib/mutant/expression/methods.rb
mutant-0.11.1 lib/mutant/expression/methods.rb
mutant-0.11.0 lib/mutant/expression/methods.rb
mutant-0.10.35 lib/mutant/expression/methods.rb