Sha256: 2ff0db63b32aee5dc9922d7e7974fee9cc7375a238b7d89df77694df8f9da429

Contents?: true

Size: 1.35 KB

Versions: 22

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module Mutant
  class Expression

    # Explicit method expression
    class Method < self
      include Anima.new(
        :method_name,
        :scope_name,
        :scope_symbol
      )

      private(*anima.attribute_names)

      MATCHERS = IceNine.deep_freeze(
        '.' => [Matcher::Methods::Singleton, Matcher::Methods::Metaclass],
        '#' => [Matcher::Methods::Instance]
      )

      METHOD_NAME_PATTERN = Regexp.union(
        /(?<method_name>[A-Za-z_][A-Za-z\d_]*[!?=]?)/,
        *AST::Types::OPERATOR_METHODS.map(&:to_s)
      ).freeze

      private_constant(*constants(false))

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

      # Syntax of expression
      #
      # @return [String]
      def syntax
        [scope_name, scope_symbol, method_name].join
      end
      memoize :syntax

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

        methods_matcher = Matcher::Chain.new(matcher_candidates)

        Matcher::Filter.new(methods_matcher, ->(subject) { subject.expression.eql?(self) })
      end

    private

      def scope
        Object.const_get(scope_name)
      end

    end # Method
  end # Expression
end # Mutant

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
mutant-0.10.17 lib/mutant/expression/method.rb
mutant-0.10.16 lib/mutant/expression/method.rb
mutant-0.10.15 lib/mutant/expression/method.rb
mutant-0.10.14 lib/mutant/expression/method.rb
mutant-0.10.13 lib/mutant/expression/method.rb
mutant-0.10.12 lib/mutant/expression/method.rb
mutant-0.10.11 lib/mutant/expression/method.rb
mutant-0.10.10 lib/mutant/expression/method.rb
mutant-0.10.9 lib/mutant/expression/method.rb
mutant-0.10.8 lib/mutant/expression/method.rb
mutant-0.10.7 lib/mutant/expression/method.rb
mutant-0.10.6 lib/mutant/expression/method.rb
mutant-0.10.5 lib/mutant/expression/method.rb
mutant-0.10.4 lib/mutant/expression/method.rb
mutant-0.10.1 lib/mutant/expression/method.rb
mutant-0.10.0 lib/mutant/expression/method.rb
mutant-0.9.14 lib/mutant/expression/method.rb
mutant-0.9.13 lib/mutant/expression/method.rb
mutant-0.9.12 lib/mutant/expression/method.rb
mutant-0.9.11 lib/mutant/expression/method.rb