Sha256: 4ee561e835fa4b108438aad725d76742069b2675a8361de3bef1dc3a513eae71

Contents?: true

Size: 1.33 KB

Versions: 7

Compression:

Stored size: 1.33 KB

Contents

module Mutant
  class Expression

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

      MATCHERS = IceNine.deep_freeze(
        '.' => Matcher::Methods::Singleton,
        '#' => 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]
      #
      # @api private
      def syntax
        [scope_name, scope_symbol, method_name].join
      end
      memoize :syntax

      # Matcher for expression
      #
      # @param [Env] env
      #
      # @return [Matcher]
      #
      # @api private
      def matcher(env)
        methods_matcher = MATCHERS.fetch(scope_symbol).new(env, scope)

        Matcher::Filter.build(methods_matcher) { |subject| subject.expression.eql?(self) }
      end

    private

      # Scope object
      #
      # @return [Class, Method]
      #
      # @api private
      def scope
        Object.const_get(scope_name)
      end

    end # Method
  end # Expression
end # Mutant

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mutant-0.8.7 lib/mutant/expression/method.rb
mutant-0.8.6 lib/mutant/expression/method.rb
mutant-0.8.5 lib/mutant/expression/method.rb
mutant-0.8.4 lib/mutant/expression/method.rb
mutant-0.8.3 lib/mutant/expression/method.rb
mutant-0.8.2 lib/mutant/expression/method.rb
mutant-0.8.1 lib/mutant/expression/method.rb