lib/superscript/runner.rb in superscript-0.6.0 vs lib/superscript/runner.rb in superscript-0.7.0

- old
+ new

@@ -16,14 +16,12 @@ puts "-- [ superscript error ] --" error_message = "" case where when :exception exception = args.first - pp exception - pp exception.backtrace_locations error_message = exception - when :tp_call_superscript + when :tp_call_superscript, :tp_call_superscript_global error_message = "Can't touch this" when :ctx_method_missing, :tp_singleton_method_added, :tp_command_not_found error_message = args.first when :tp_class_define, :tp_module_define error_message = args.first @@ -48,10 +46,14 @@ @armed = false end def run!(ctx, contents:nil) contents = File.read(@path) unless contents + $__superscript_none_of_yer_business = self + ctx.define_singleton_method "method_missing" do |*args| + $__superscript_none_of_yer_business.error! :ctx_method_missing, "No such command or variable '#{args.first}'" + end disarm! :at_start trace = TracePoint.new do |tp| if ENV["SUPERSCRIPT_DEBUG"] p [@armed, tp.path, tp.lineno, tp.method_id, tp.event, tp.defined_class] @@ -86,10 +88,15 @@ end line = lines[tp.lineno-1].lstrip puts "< #{tp.path}:#{tp.lineno-1}" puts line + + if line.match(/\$__superscript_none_of_yer_business/) + tp.disable + error! :tp_call_superscript_global + end when :c_call # allow calls to these instances if tp.defined_class.ancestors.at(1) == Struct disarm! :safe_instance next @@ -104,10 +111,12 @@ if @methods next end trace.disable error! :tp_singleton_method_added, "Deffining methods is not allowed" + when :method_missing + trace.disable else trace.disable case tp.defined_class.name when "Class" error! :tp_class_define, "Defining classes is not allowed" @@ -133,9 +142,14 @@ error! :tp_command_not_found, "Command not found '#{command_name}'" end end when :call + if tp.method_id == :method_missing + tp.disable + next + end + if tp.defined_class.ancestors.first.to_s == "#<Class:Superscript>" tp.disable error! :tp_call_superscript end # disable if calling some other file