Class: HRoutes

Inherits:
Object
  • Object
show all
Defined in:
lib/webber/hroutes.rb

Overview


路由 简单实现 rails 的方式 

  get "/", "home#index"
  post "/item/buy", "item#buy"
  match "/items", "item#new", via: [:get, :post]

Defined Under Namespace

Classes: RouteStruct

Constant Summary collapse

@@tables =
{}

Class Method Summary collapse

Class Method Details

._parse(_m, *args) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/webber/hroutes.rb', line 35

def _parse _m,*args
  _path_info = args[0].to_s
  if args[1] =~ /^(.*)#(.*)$/
    @@tables[_path_info] = RouteStruct.new $1,$2, _m == "match" ? args[2][:via].map(&:to_s) : [_m.to_s]
  else
    raise "routes error!"
  end
end

.get(*args) ⇒ Object



19
20
21
# File 'lib/webber/hroutes.rb', line 19

def get *args
  self._parse "get",*args
end

.match(*args) ⇒ Object



27
28
29
# File 'lib/webber/hroutes.rb', line 27

def match *args
  self._parse "match",*args
end

.post(*args) ⇒ Object



23
24
25
# File 'lib/webber/hroutes.rb', line 23

def post *args
  self._parse "get",*args
end

.tablesObject



31
32
33
# File 'lib/webber/hroutes.rb', line 31

def tables
  @@tables
end