lib/jets/poly_fun.rb in jets-1.0.5 vs lib/jets/poly_fun.rb in jets-1.0.6

- old
+ new

@@ -15,10 +15,12 @@ @app_class = app_class # already a Constant, IE: PostController @app_meth = app_meth.to_sym end def run(event, context={}) + check_private_method! + if task.lang == :ruby # controller = PostsController.new(event, content) # resp = controller.edit @app_class.process(event, context, @app_meth) else @@ -52,10 +54,22 @@ error_class = "Jets::PolyFun::#{task.lang.to_s.classify}Error".constantize raise error_class.new(resp["errorMessage"], backtrace) end def task - @app_class.all_tasks[@app_meth] + task = @app_class.all_public_tasks[@app_meth] + # Provider user a better error message to user than a nil failure. + unless task + raise "Unable to find #{@app_class}##{@app_meth}" + end + task end memoize :task + + def check_private_method! + private_detected = @app_class.all_private_tasks.keys.include?(@app_meth) + return unless private_detected # Ok to continue + + raise "The #{@app_class}##{@app_meth} is a private method. Unable to call it unless it is public" + end end end