Created
June 14, 2013 15:41
-
-
Save Sailias/5782845 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ItemsController | |
def initialize | |
@items = [] | |
1.upto(10) do |i| | |
@items << { id: i, name: "Item #{i}" } | |
end | |
# => GET /items | |
def index | |
@items.each do |item| | |
puts "id: #{item[:id]} - #{item[:name]}" | |
end | |
end | |
# => POST /items | |
def create | |
end | |
# => GET /items/:id | |
def show(index) | |
item = @items[index - 1] | |
puts "id: #{item[:id]} - #{item[:name]}" | |
end | |
# => DELETE /items/:id | |
def destroy | |
end | |
# => PUT /items/:id | |
def update | |
end | |
end | |
end | |
class Router | |
def initialize(url) | |
items = ItemsController.new | |
case url | |
when '/items' | |
items.index | |
when '/items/1' | |
items.show(1) | |
when '/items/2' | |
items.show(2) | |
else | |
items.index | |
end | |
end | |
end | |
http_method = ARGV[0] | |
url = ARGV[1] | |
Router.new(http_method, url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment