From 61b22c49bf4d35896bf0173a22861554a02f02ad Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Wed, 29 Aug 2012 13:33:47 +0200 Subject: [PATCH] Cleanup Mutant::Mutation interface * Equalize on sha1 * Expose code (for mutation filters) * Expose node --- lib/mutant/mutation.rb | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/mutant/mutation.rb b/lib/mutant/mutation.rb index 5c4b496c..ae8cabdf 100644 --- a/lib/mutant/mutation.rb +++ b/lib/mutant/mutation.rb @@ -1,7 +1,7 @@ module Mutant # Represent a mutated node with its subject class Mutation - include Immutable + include Immutable, Equalizer.new(:sha1) # Return mutation subject # @@ -11,6 +11,14 @@ module Mutant # def subject; @subject; end + # Return mutated node + # + # @return [Subject] + # + # @api private + # + def node; @node; end + # Return mutated root node # # @return [Rubinius::AST::Script] @@ -40,17 +48,29 @@ module Mutant # @api private # def identification - "#{subject.identification}:#{sha1[0..4]}" + "#{subject.identification}:#{code}" end + memoize :identification - # Return sha1 sum of source + # Return mutation code + # + # @return [String] + # + # @api private + # + def code + sha1[0..4] + end + memoize :code + + # Return sha1 sum of source and subject identification # # @return [String] # # @api private # def sha1 - SHA1.hexdigest(source) + SHA1.hexdigest(subject.identification + source) end memoize :sha1