Last active
August 29, 2015 14:03
-
-
Save jeffdeville/687b8abdad02ceb82f5e to your computer and use it in GitHub Desktop.
A demo of how a console router might work
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
| module Models | |
| class Inventory | |
| def self.all | |
| [Object.new] | |
| end | |
| def self.find(inventory_id) | |
| Object.new | |
| end | |
| end | |
| end | |
| module Views | |
| module InventoryViews | |
| def self.menu | |
| puts "\t\tinventory menu, chomping" | |
| gets.chomp | |
| end | |
| def self.all(inventories) | |
| puts "\t\tshow all inventories" | |
| end | |
| def self.show(inventory) | |
| puts "\t\tshow 1 inventory" | |
| end | |
| end | |
| module RootViews | |
| def self.menu | |
| puts "Root Menu, chomping" | |
| gets.chomp | |
| end | |
| end | |
| end | |
| module Controllers | |
| class InventoryController | |
| def self.menu | |
| Views::InventoryViews.menu | |
| end | |
| def self.all | |
| inventories = Models::Inventory.all | |
| Views::InventoryViews.all(inventories) | |
| end | |
| def self.show(inventory_id) | |
| inventory = Models::Inventory.find inventory_id | |
| Views::InventoryViews.show(inventory) | |
| end | |
| def self.route(choice=nil, *args) | |
| while true | |
| case choice | |
| when nil | |
| when "1" | |
| puts "\tInventory.all" | |
| all | |
| when "2" | |
| puts "\tInventory.show" | |
| show(args) | |
| when "x" | |
| puts "\texiting" | |
| return | |
| else | |
| puts "I do not understand" | |
| end | |
| choice = menu | |
| end | |
| end | |
| end | |
| class RootController | |
| def self.menu | |
| Views::RootViews.menu | |
| end | |
| def self.route(choice=nil) | |
| while true | |
| case choice | |
| when nil | |
| when "1" | |
| puts "going to Inventory Controller" | |
| InventoryController.route | |
| when "2" | |
| puts "going to Orders Controller" | |
| OrdersController.route | |
| when "x" | |
| puts "exiting" | |
| return | |
| else | |
| p "I have no ideas what you want" | |
| end | |
| choice = menu | |
| end | |
| end | |
| end | |
| end | |
| Controllers::RootController.route |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment