Class: NetMate::Routing

Inherits:
Object
  • Object
show all
Defined in:
lib/net_mate/routing.rb

Instance Method Summary collapse

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, options
  path = path == '/' ? path : "/#{path}"
  controller, action = options[:to].split('#')
  NetMate::routes[[path, options[: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, options = { only: [:new, :create, :edit, :update, :show, :index] }
  options[: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