Sha256: 24d25eae346e3b3a6b07b144eea53e8af67808277a1ad34ce52b268e5208342d

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

require 'forwardable'

module Mutant
  class Mutatee
    extend Forwardable

    attr_reader :implementation, :mutations

    def initialize(implementation)
      @implementation = implementation
      @mutations = []
    end

    def_delegators :@implementation, :class_name, :method_name, :to_s

    def clean
      body.array.delete_if do |literal|
        not Mutant::Literal.constants.map(&:to_sym).include?(literal.class.basename.to_sym)
      end
    end

    def set_mutations
      nodes.each do |node|
        @mutations << Mutation.new(node, body.array)
      end
    end

    def nodes
      body.array.map {|item| Node.new(item) }
    end

    def mutations_remaining
      @mutations.reject(&:mutated?)
    end

    def ast
      @ast ||= rbx_method.parse_file && rbx_method.ast
    end

    def body
      @body ||= rbx_method.is_a?(SingletonMethod) ? ast.body.body : ast.body

    end

    def rbx_method
      @rbx_method ||=
        case implementation.scope_type
        when :singleton then SingletonMethod.new \
          implementation.constant.method(method_name)
        when :instance then InstanceMethod.new \
          implementation.constant.instance_method(method_name)
        end
    end

    private

    def marshal(data)
      Marshal.load(Marshal.dump(data))
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mutant-0.1.1 lib/mutant/mutatee.rb
mutant-0.1.0 lib/mutant/mutatee.rb