free_mutant/lib/mutant/expression/method.rb
Markus Schirp d647563055 Refactor expression parsing and representation
* Avoids boot time mutation of REGISTER constant
* Allows to define project specific expression parsing
* Avoids custom (slow) serialization of Expression objects speeding up
  reporter / killer IPC
* Improve specification
* Improve integration API as it now finally references an object the config
* Allow reproduction of syntax from Expression#syntax
* Allow instantiation of Expresssion objects without generating the
  syntax, much nicer for most specs & internal code, avoids generating
  a string to parse it into an expression
* Fix LSP violation in Mutant::Matcher namespace
2015-06-21 14:44:33 +00:00

62 lines
1.3 KiB
Ruby

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
# Return syntax
#
# @return [String]
#
# @api private
#
def syntax
[scope_name, scope_symbol, method_name].join
end
memoize :syntax
# Return method matcher
#
# @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
# Return scope
#
# @return [Class, Method]
#
# @api private
#
def scope
Object.const_get(scope_name)
end
end # Method
end # Expression
end # Mutant