Skip to content

Instantly share code, notes, and snippets.

@mgiagante
Created March 26, 2018 17:40
Show Gist options
  • Save mgiagante/f5266874c468b801cded319ad9ec072c to your computer and use it in GitHub Desktop.
Save mgiagante/f5266874c468b801cded319ad9ec072c to your computer and use it in GitHub Desktop.
require "cuba"
require "mote"
require "mote/render"
Cuba.plugin Mote::Render
require_relative "controllers/pages"
require_relative "controllers/tasks"
require_relative "db/data_store"
require_relative "models/task"
DataStore.load_data
Cuba.define do
on get do
on "dashboard" do
with action: :dashboard do
run PagesController
end
end
end
on root do
res.redirect "dashboard"
end
on post do
on "tasks/:id" do |id|
on param(:event) do |event|
with action: :trigger, id: id.to_i, event: event do
run TasksController
end
end
end
end
end
class TasksController < Cuba
define do
on default do
res.write public_send(*vars.values)
res.redirect "/dashboard"
end
end
def trigger(id, event)
target_task = DataStore::Tasks.all.find { |task| task.id == id }
target_task.public_send(event)
target_task.status
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment