Sha256: 53b65c8a700bd5a76c6734e8d51bd95f88d2e40479f29c71680f841744a00f99

Contents?: true

Size: 1.7 KB

Versions: 2

Compression:

Stored size: 1.7 KB

Contents

module Mutant
  class Expression

    # Explicit method expression
    class Method < self

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

      register(
        /\A(?<scope_name>#{SCOPE_PATTERN})(?<scope_symbol>[.#])(?<method_name>#{METHOD_NAME_PATTERN})\z/
      )

      # Return method matcher
      #
      # @param [Cache] cache
      #
      # @return [Matcher::Method]
      #
      # @api private
      #
      def matcher(cache)
        methods_matcher = MATCHERS.fetch(scope_symbol).new(cache, scope)
        method = methods_matcher.methods.detect do |meth|
          meth.name.equal?(method_name)
        end or raise NameError, "Cannot find method #{identifier}"
        methods_matcher.matcher.build(cache, scope, method)
      end

    private

      # Return scope name
      #
      # @return [String]
      #
      # @api private
      #
      def scope_name
        match[__method__]
      end

      # Return scope
      #
      # @return [Class, Method]
      #
      # @api private
      #
      def scope
        Mutant.constant_lookup(scope_name)
      end

      # Return method name
      #
      # @return [String]
      #
      # @api private
      #
      def method_name
        match[__method__].to_sym
      end

      # Return scope symbol
      #
      # @return [Symbol]
      #
      # @api private
      #
      def scope_symbol
        match[__method__]
      end

      # Return matcher class
      #
      # @return [Class:Mutant::Matcher]
      #
      # @api private
      #
      def methods_matcher(cache)
        MATCHERS.fetch(scope_symbol).new(cache, scope)
      end

    end # Method
  end # Expression
end # Mutant

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mutant-0.5.24 lib/mutant/expression/method.rb
mutant-0.5.23 lib/mutant/expression/method.rb