Sha256: c0b7acc65bfb48445dc5862a3f879b81ac39718d3d1fc179b40467cfb7cb837e

Contents?: true

Size: 1.34 KB

Versions: 7

Compression:

Stored size: 1.34 KB

Contents

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 = IceNine.deep_freeze(
        '.' => Matcher::Methods::Singleton,
        '#' => Matcher::Methods::Instance
      )
      private_constant(*constants(false))

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

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

      # Matcher on expression
      #
      # @param [Env] env
      #
      # @return [Matcher::Method]
      #
      # @api private
      def matcher(env)
        MATCHERS.fetch(scope_symbol).new(env, scope)
      end

      # Length of match with other expression
      #
      # @param [Expression] expression
      #
      # @return [Fixnum]
      #
      # @api private
      def match_length(expression)
        if expression.syntax.start_with?(syntax)
          syntax.length
        else
          0
        end
      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/methods.rb
mutant-0.8.6 lib/mutant/expression/methods.rb
mutant-0.8.5 lib/mutant/expression/methods.rb
mutant-0.8.4 lib/mutant/expression/methods.rb
mutant-0.8.3 lib/mutant/expression/methods.rb
mutant-0.8.2 lib/mutant/expression/methods.rb
mutant-0.8.1 lib/mutant/expression/methods.rb