Class: NetMate::Routing
- Inherits:
-
Object
- Object
- NetMate::Routing
- Defined in:
- lib/net_mate/routing.rb
Instance Method Summary collapse
- #get(path) ⇒ Object
- #match(path, options) ⇒ Object
- #post(path) ⇒ Object
- #resources(controller, options = { only: [:new, :create, :edit, :update, :show, :index] }) ⇒ Object
Instance Method Details
#get(path) ⇒ Object
5 6 7 |
# File 'lib/net_mate/routing.rb', line 5 def get path match path, to: path.tr('/','#'), via: 'get' end |
#match(path, options) ⇒ Object
13 14 15 16 17 |
# File 'lib/net_mate/routing.rb', line 13 def match path, path = path == '/' ? path : "/#{path}" controller, action = [:to].split('#') NetMate::routes[[path, [:via]]] = [controller, action] end |
#post(path) ⇒ Object
9 10 11 |
# File 'lib/net_mate/routing.rb', line 9 def post path match path, to: path.tr('/','#'), via: 'post' end |
#resources(controller, options = { only: [:new, :create, :edit, :update, :show, :index] }) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/net_mate/routing.rb', line 19 def resources controller, = { only: [:new, :create, :edit, :update, :show, :index] } [:only].each do |action| action = action.to_s controller = controller.to_s path = "/#{controller}/#{action}" method = ['create', 'update'].include?(action) ? 'post' : 'get' NetMate::routes[[path, method]] = [controller, action] end end |