app/controllers/cogy/cogy_controller.rb in cogy-0.1.1 vs app/controllers/cogy/cogy_controller.rb in cogy-0.2.0
- old
+ new
@@ -10,19 +10,26 @@
# by the cogy executable.
#
# See https://github.com/skroutz/cogy-bundle.
def command
cmd = params[:cmd]
- args = request.query_parameters.select { |k, _| k.start_with?("cog_argv_") }.values
+ args = request.query_parameters.select { |k, _| k.start_with?("cog_argv_") }
+ .sort_by { |k, _| k.match(/\d+\z/)[0] }.to_h.values
+
opts = request.query_parameters.select { |k, _| k.start_with?("cog_opt_") }
.transform_keys { |k| k.sub("cog_opt_", "") }
cogy_env = request.query_parameters.select { |k, _| k.start_with?("cogy_") }
user = params[:user]
begin
if (command = Cogy.commands[cmd])
- context = Context.new(args, opts, user, cogy_env)
- render text: context.run!(command)
+ result = Context.new(command, args, opts, user, cogy_env).invoke
+ if result.is_a?(Hash)
+ result = "COG_TEMPLATE: #{command.template || command.name}\n" \
+ "JSON\n" \
+ "#{result.to_json}"
+ end
+ render text: result
else
render status: 404, text: "The command '#{cmd}' does not exist."
end
rescue => e
@user = user