free_mutant/lib/mutant/loader.rb

57 lines
919 B
Ruby
Raw Normal View History

# encoding: utf-8
module Mutant
# Base class for code loaders
class Loader
2012-11-26 11:30:00 +01:00
include AbstractType
include Procto.call
# Initialize and insert mutation into vm
#
# @param [Parser::AST::Node] root
# @param [Subject] subject
#
# @return [undefined]
#
# @api private
#
def initialize(root, subject)
@root, @subject = root, subject
2012-08-20 05:01:26 +02:00
end
# Eval based loader
class Eval < self
2013-01-04 20:07:41 +01:00
# Call loader
#
# @return [undefined]
#
# @api private
#
def call
2013-07-28 19:24:00 +02:00
eval(
source,
TOPLEVEL_BINDING,
@subject.source_path.to_s,
@subject.source_line
)
nil
end
private
# Return source
#
# @return [String]
#
# @api private
#
def source
Unparser.unparse(@root)
end
end # Eval
end # Loader
end # Mutant