Skip to content

Instantly share code, notes, and snippets.

@fnando
Created February 27, 2012 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fnando/1920324 to your computer and use it in GitHub Desktop.
Save fnando/1920324 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 }
find { List.find(params[:id]) }
instance { List.new(params[:list]) }
to_update { list.update_attributes(params[:list]) }
to_destroy { list.destroy }
# Setting actions
actions :index, :show, :new, :create, :remove, :destroy, :edit, :update
# The actions above can be shortened as following:
actions :all
# To register a new action. This would be done in a global file,
# when more than one router needs this specific action.
register :search, :path => ":endpoint/search", :method => :get do
collection { default_finder.search(params[:query]) }
render :search
end
# Or if you want to set an action to this router only.
get :search do
collection { List.search(params[:query]) }
end
# To set custom paths
action :index => "/lists"
action :show => "/lists/:id"
action :new => "/lists/new"
action :create => "/lists/new"
action :edit => "/lists/:id/edit"
action :update => "/lists/:id/edit"
action :remove => "/lists/:id/remove"
action :destroy => "/lists/:id/remove"
action :search => "/lists/search"
end
class Tasks < App
all { list.tasks.all }
find(:list) { List.find(params[:list_id]) }
find { list.tasks.find(params[:task_id]) }
instance { list.tasks.new(params[:task]) }
to_update { task.update_attributes(params[:task]) }
to_destroy { task.destroy }
base_path { "/lists/:list" }
actions :all
end
# register :new, :path => ":endpoint/new", :method => :get do
# respond_with(instance)
# end
#
# register :create, :path => ":endpoint/new", :method => :create do
# respond_with(instance)
# end
#
# register :edit, :path => ":endpoint/:id/edit", :method => :get do
# respond_with(default_finder)
# end
#
# register :update, :path => ":endpoint/:id/edit", :method => :patch do
# run :to_update
# respond_with(default_finder, :location => :show)
# end
#
# register :remove, :path => ":endpoint/:id/remove", :method => :get do
# respond_with(default_finder)
# end
#
# register :destroy, :path => ":endpoint/:id/remove", :method => :destroy do
# run :to_destroy
# respond_with(:location => :index)
# end
@fnando
Copy link
Author

fnando commented Feb 27, 2012

Still need to think about view rendering, presenters, layout files and filters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment