Class: Crystal::DefaultRouter

Inherits:
Object
  • Object
show all
Defined in:
lib/crystal/router/default_router.rb

Instance Method Summary collapse

Instance Method Details

#decode(path, params) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/crystal/router/default_router.rb', line 10

def decode path, params
  parts = path[1..-1].split '/'
  if parts.size >= 2
    method = parts.pop        
    
    class_path = parts.join('/')
    class_name = class_path.camelize
    klass = class_name.constantize
                    
    return klass, method, params
  end
end

#encode(klass, method, params) ⇒ Object



5
6
7
8
# File 'lib/crystal/router/default_router.rb', line 5

def encode klass, method, params
  path = "/#{klass.name.underscore}/#{method}"
  return path, params
end