free_mutant/lib/mutant/predicate.rb

75 lines
1.3 KiB
Ruby
Raw Normal View History

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]
# returns nil otherwise
#
# @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]
# returns nil
#
# @api private
#
def self.handle(_notation)
nil
end
2013-09-07 17:12:03 -04:00
# Mutation predicate matching all mutations
2013-09-07 12:57:06 -04:00
Mutant.singleton_subclass_instance('ALL', self) do
# Test for match
#
# @pram [Mutation] _mutation
#
# @return [true]
# returns true
#
# @api private
#
def match?(_mutation)
true
end
end
end # Filter
end # Mutant