diff --git a/Gemfile b/Gemfile index 7007c896..7ac769fd 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,7 @@ source 'https://rubygems.org' gemspec gem 'immutable', :git => 'https://github.com/mbj/immutable' +gem 'abstract', :git => 'https://github.com/mbj/abstract' # Until there is a release with explicit sends to self fix gem 'to_source', :git => 'https://github.com/mbj/to_source' diff --git a/lib/mutant.rb b/lib/mutant.rb index 12df9a4b..1d791320 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -1,4 +1,5 @@ require 'immutable' +require 'abstract' require 'securerandom' require 'to_source' require 'ice_nine' @@ -33,7 +34,6 @@ module Mutant end end -require 'mutant/support/abstract' require 'mutant/random' require 'mutant/runner' #require 'mutant/runner/rspec' diff --git a/lib/mutant/context.rb b/lib/mutant/context.rb index 40717ade..365d1dfd 100644 --- a/lib/mutant/context.rb +++ b/lib/mutant/context.rb @@ -1,8 +1,7 @@ module Mutant # An abstract context where mutations can be appied to. class Context - include Immutable - extend Abstract + include Immutable, Abstract # Return root ast for mutated node # @@ -12,6 +11,6 @@ module Mutant # # @api private # - abstract :root + abstract_method :root end end diff --git a/lib/mutant/matcher.rb b/lib/mutant/matcher.rb index fadf5c26..88ba7383 100644 --- a/lib/mutant/matcher.rb +++ b/lib/mutant/matcher.rb @@ -1,8 +1,7 @@ module Mutant # Abstract matcher to find ASTs to mutate class Matcher - include Enumerable - extend Abstract + include Enumerable, Abstract # Enumerate subjects # @@ -10,7 +9,7 @@ module Mutant # # @return [undefined] # - abstract :each + abstract_method :each private diff --git a/lib/mutant/matcher/method.rb b/lib/mutant/matcher/method.rb index 0c6c1b00..569bd8a5 100644 --- a/lib/mutant/matcher/method.rb +++ b/lib/mutant/matcher/method.rb @@ -86,7 +86,7 @@ module Mutant # # @api private # - abstract :method + abstract_method :method # Return node classes this matcher matches # @@ -94,7 +94,7 @@ module Mutant # # @api private # - abstract :node_class + abstract_method :node_class # Check if node is matched # @@ -160,7 +160,7 @@ module Mutant # # @api private # - abstract :matched_node + abstract_method :matched_node # Return subject # diff --git a/lib/mutant/mutator.rb b/lib/mutant/mutator.rb index 526e8a01..8a176d92 100644 --- a/lib/mutant/mutator.rb +++ b/lib/mutant/mutator.rb @@ -1,8 +1,7 @@ module Mutant # Generator for mutations class Mutator - include Immutable - extend Abstract + include Immutable, Abstract # Enumerate mutations on node # @@ -65,7 +64,7 @@ module Mutant # # @api private # - abstract :dispatch + abstract_method :dispatch # Append node to generated mutations if node does not equal orignal node # diff --git a/lib/mutant/mutator/literal/boolean.rb b/lib/mutant/mutator/literal/boolean.rb index 04f75076..2b2bdf06 100644 --- a/lib/mutant/mutator/literal/boolean.rb +++ b/lib/mutant/mutator/literal/boolean.rb @@ -23,7 +23,7 @@ module Mutant # # @api private # - abstract :inverse + abstract_method :inverse # Represent mutations of true literal class TrueLiteral < Boolean diff --git a/lib/mutant/mutator/literal/range.rb b/lib/mutant/mutator/literal/range.rb index a0e69ffc..6e8b554e 100644 --- a/lib/mutant/mutator/literal/range.rb +++ b/lib/mutant/mutator/literal/range.rb @@ -48,7 +48,7 @@ module Mutant # # @api private # - abstract :inverse_class + abstract_method :inverse_class # Mutator for range exclude literals class Exclude < Range diff --git a/lib/mutant/runner.rb b/lib/mutant/runner.rb index da767943..45d33fa7 100644 --- a/lib/mutant/runner.rb +++ b/lib/mutant/runner.rb @@ -1,8 +1,7 @@ module Mutant # Abstract runner for tests class Runner - include Immutable - extend Abstract + include Immutable, Abstract # Run runner # @@ -75,6 +74,6 @@ module Mutant # # @api private # - abstract :run + abstract_method :run end end diff --git a/lib/mutant/support/abstract.rb b/lib/mutant/support/abstract.rb deleted file mode 100644 index 5497a99b..00000000 --- a/lib/mutant/support/abstract.rb +++ /dev/null @@ -1,67 +0,0 @@ -module Mutant - # Module to declare abstract methods - module Abstract - - # Declare abstract instance method - # - # @return [self] - # - # @api private - # - def abstract(*names) - names.each do |name| - define_instance_method(name) - end - - self - end - - # Declare abstract singleton method - # - # @return [self] - # - # @api private - # - def abstract_singleton(*names) - names.each do |name| - define_singleton_method(name) - end - - self - end - - private - - # Define abstract method stub on singleton - # - # @param [String] name - # - # @return [undefined] - # - # @api private - # - def define_singleton_method(name) - class_eval(<<-RUBY, __FILE__, __LINE__+1) - def #{name}(*) - raise NotImplementedError, "\#{self.name}.\#{__method__} is not implemented" - end - RUBY - end - - # Define abstract method stub on instances - # - # @param [String] name - # - # @return [undefined] - # - # @api private - # - def define_instance_method(name) - class_eval(<<-RUBY, __FILE__, __LINE__+1) - def #{name}(*) - raise NotImplementedError, "\#{self.class.name}#\#{__method__} is not implemented" - end - RUBY - end - end -end diff --git a/mutant.gemspec b/mutant.gemspec index 32d7ac06..4513d2b7 100644 --- a/mutant.gemspec +++ b/mutant.gemspec @@ -16,7 +16,9 @@ Gem::Specification.new do |gem| gem.test_files = `git ls-files -- spec`.split("\n") gem.extra_rdoc_files = %w[TODO] - gem.add_dependency('to_source', '~> 0.1.3') - gem.add_dependency('ice_nine', '~> 0.4.0') + gem.add_runtime_dependency('to_source', '~> 0.1.3') + gem.add_runtime_dependency('ice_nine', '~> 0.4.0') gem.add_runtime_dependency('backports', '~> 2.6') + gem.add_runtime_dependency('immutable', '~> 0.0.1') + gem.add_runtime_dependency('abstract', '~> 0.0.1') end