Sha256: ff45f29d420eca5be6065c9a38e187269f4d2b9104a7e3ffe7d314d4083e0b3d

Contents?: true

Size: 1.21 KB

Versions: 7

Compression:

Stored size: 1.21 KB

Contents

module Mutest
  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/

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

      # Matcher on expression
      #
      # @return [Matcher::Method]
      def matcher
        MATCHERS.fetch(scope_symbol).new(scope)
      end

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

      private

      # Scope object
      #
      # @return [Class, Method]
      def scope
        Object.const_get(scope_name)
      end
    end # Methods
  end # Expression
end # Mutest

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mutest-0.0.8 lib/mutest/expression/methods.rb
mutest-0.0.7 lib/mutest/expression/methods.rb
mutest-0.0.6 lib/mutest/expression/methods.rb
mutest-0.0.5 lib/mutest/expression/methods.rb
mutest-0.0.4 lib/mutest/expression/methods.rb
mutest-0.0.3 lib/mutest/expression/methods.rb
mutest-0.0.2 lib/mutest/expression/methods.rb