2013-09-09 01:37:07 -04:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2013-09-07 12:57:06 -04:00
|
|
|
module Mutant
|
2013-09-07 17:12:03 -04:00
|
|
|
# Abstract base class for predicates used to filter subjects / mutations
|
|
|
|
class Predicate
|
2013-09-07 12:57:06 -04:00
|
|
|
include Adamantium::Flat, AbstractType
|
|
|
|
extend DescendantsTracker
|
|
|
|
|
|
|
|
# Check for match
|
|
|
|
#
|
|
|
|
# @param [Object] object
|
|
|
|
#
|
|
|
|
# @return [true]
|
2013-09-07 17:12:03 -04:00
|
|
|
# if object is matched by predicate
|
2013-09-07 12:57:06 -04:00
|
|
|
#
|
|
|
|
# @return [false]
|
|
|
|
# otherwise
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
abstract_method :match?
|
|
|
|
|
2013-09-07 17:12:03 -04:00
|
|
|
# Build predicate from string
|
2013-09-07 12:57:06 -04:00
|
|
|
#
|
|
|
|
# @param [String] notation
|
|
|
|
#
|
|
|
|
# @return [Filter]
|
|
|
|
# when can be build from string
|
|
|
|
#
|
|
|
|
# @return [nil]
|
2013-09-11 14:48:44 -04:00
|
|
|
# otherwise
|
2013-09-07 12:57:06 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def self.build(notation)
|
|
|
|
descendants.each do |descendant|
|
2013-09-07 17:12:03 -04:00
|
|
|
predicate = descendant.handle(notation)
|
|
|
|
return predicate if predicate
|
2013-09-07 12:57:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2013-09-07 17:12:03 -04:00
|
|
|
# Return predicate for handle
|
2013-09-07 12:57:06 -04:00
|
|
|
#
|
|
|
|
# @param [String] _notation
|
|
|
|
#
|
|
|
|
# @return [nil]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def self.handle(_notation)
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2013-09-13 16:28:04 -04:00
|
|
|
# Mutation predicate matching no inputs
|
|
|
|
Mutant.singleton_subclass_instance('CONTRADICTION', self) do
|
|
|
|
|
|
|
|
# Test for match
|
|
|
|
#
|
|
|
|
# @pram [Mutation] _mutation
|
|
|
|
#
|
|
|
|
# @return [true]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def match?(_mutation)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
# Mutation predicate matching all inputs
|
|
|
|
Mutant.singleton_subclass_instance('TAUTOLOGY', self) do
|
2013-09-07 12:57:06 -04:00
|
|
|
|
|
|
|
# Test for match
|
|
|
|
#
|
|
|
|
# @pram [Mutation] _mutation
|
|
|
|
#
|
|
|
|
# @return [true]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def match?(_mutation)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end # Filter
|
|
|
|
end # Mutant
|