Created
February 27, 2012 15:38
-
-
Save lucashungaro/1924747 to your computer and use it in GitHub Desktop.
Some ideas on a small framework. Yet another web framework.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Lists < App | |
authenticate { AuthenticationService.authenticate(session) } # just an example, it checks for true or false only | |
authorize { current_user.role? :admin }, :for => :create, :update # same here | |
all { List.all } # :get /lists | |
# the param name should always be class.name.singularize | |
one { List.find(params[:list]) } # :get /lists/:id | |
instance { List.new(params[:list]) } | |
to_update { list.update_attributes(params[:list]) } | |
to_destroy { list.destroy } | |
to_save { list.save } | |
# If you want to set an action for this resource only. | |
get :search do | |
List.search(params[:query]) | |
end | |
end | |
class Tasks < App | |
parent Lists # this invokes Lists#find and sets an ivar before finding tasks | |
all { list.tasks.all } # :get /lists/:id/tasks | |
one { list.tasks.find(params[:task]) } # :get /lists/:id/tasks/:id | |
instance { list.tasks.new(params[:task]) } | |
to_update { task.update_attributes(params[:task]) } | |
to_destroy { task.destroy } | |
to_save { task.save } | |
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