Skip to content

Instantly share code, notes, and snippets.

@lucashungaro
Forked from fnando/gist:1920324
Created February 27, 2012 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucashungaro/1924445 to your computer and use it in GitHub Desktop.
Save lucashungaro/1924445 to your computer and use it in GitHub Desktop.
Some ideas on a small framework. Yet another web framework.
class Lists < App
all { List.all } # :get /lists
one { List.find(params[:id]) } # :get /lists/:id
instance { List.new(params[:list]) }
to_update { list.update_attributes(params[:list]) }
to_destroy { list.destroy }
# If you want to set an action for this resource only.
get :search do
List.search(params[:query])
end
end
class Tasks < App
parent List # this invokes List#find and sets an ivar before finding tasks
all { list.tasks.all } # :get /lists/:id/tasks
one { list.tasks.find(params[:task_id]) } # :get /lists/:id/tasks/:id
instance { list.tasks.new(params[:task]) }
to_update { task.update_attributes(params[:task]) }
to_destroy { task.destroy }
end
class Search
all { SearchService.search(params[:resource], params[:query]) } # :get /search
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment