2012-07-26 13:25:23 -04:00
|
|
|
module Mutant
|
2012-11-21 14:31:01 -05:00
|
|
|
# Base class for code loaders
|
2012-07-26 13:25:23 -04:00
|
|
|
class Loader
|
2014-03-14 16:56:04 -04:00
|
|
|
include AbstractType, Concord.new(:root, :subject), Procto.call
|
2012-08-19 23:01:26 -04:00
|
|
|
|
2012-11-21 14:31:01 -05:00
|
|
|
# Eval based loader
|
|
|
|
class Eval < self
|
2013-01-04 14:07:41 -05:00
|
|
|
|
2013-12-29 16:50:24 -05:00
|
|
|
# Call loader
|
2012-11-21 14:31:01 -05:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
2014-12-21 20:28:30 -05:00
|
|
|
# One off the very few valid uses of eval
|
|
|
|
#
|
|
|
|
# rubocop:disable Lint/Eval
|
|
|
|
#
|
2015-07-01 23:35:54 -04:00
|
|
|
# @api private
|
2013-12-29 16:50:24 -05:00
|
|
|
def call
|
2013-07-28 13:24:00 -04:00
|
|
|
eval(
|
|
|
|
source,
|
|
|
|
TOPLEVEL_BINDING,
|
2014-03-14 16:56:04 -04:00
|
|
|
subject.source_path.to_s,
|
|
|
|
subject.source_line
|
2013-07-28 13:24:00 -04:00
|
|
|
)
|
2014-11-17 15:31:12 -05:00
|
|
|
self
|
2012-11-21 14:31:01 -05:00
|
|
|
end
|
2012-08-19 15:25:11 -04:00
|
|
|
|
2013-12-29 16:50:24 -05:00
|
|
|
private
|
|
|
|
|
2015-07-03 11:21:39 -04:00
|
|
|
# Source generated from AST
|
2012-11-21 14:31:01 -05:00
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def source
|
2014-03-14 16:56:04 -04:00
|
|
|
Unparser.unparse(root)
|
2012-11-21 14:31:01 -05:00
|
|
|
end
|
2013-12-29 16:50:24 -05:00
|
|
|
|
2013-06-04 04:25:13 -04:00
|
|
|
end # Eval
|
2012-07-26 13:25:23 -04:00
|
|
|
|
2013-06-04 04:25:13 -04:00
|
|
|
end # Loader
|
|
|
|
end # Mutant
|