Skip to content

Instantly share code, notes, and snippets.

@lucashungaro
Created February 27, 2012 15:38
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/1924747 to your computer and use it in GitHub Desktop.
Save lucashungaro/1924747 to your computer and use it in GitHub Desktop.
Some ideas on a small framework. Yet another web framework.
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