class Peictt::Builder::Router

Public Class Methods

new() click to toggle source
# File lib/peictt/builder/router.rb, line 4
def initialize
  @routes = []
  @placeholders = []
end

Public Instance Methods

all() click to toggle source
# File lib/peictt/builder/router.rb, line 13
def all
  @routes
end
draw(&block) click to toggle source
# File lib/peictt/builder/router.rb, line 9
def draw(&block)
  instance_eval(&block)
end
method_missing(name, url, args = {}) click to toggle source
# File lib/peictt/builder/router.rb, line 24
def method_missing(name, url, args = {})
  verb = name.to_s.upcase
  verb_class = Object.const_get "Peictt::Http::#{verb}"
  route = verb_class.new url, args
  @routes << route unless route_exists? route
  route
end
respond_to_missing?(type, include_private = false) click to toggle source
Calls superclass method
# File lib/peictt/builder/router.rb, line 41
def respond_to_missing?(type, include_private = false)
  super
end
root(arg) click to toggle source
# File lib/peictt/builder/router.rb, line 17
def root(arg)
  url = "/"
  route = Peictt::Http::GET.new url, to: arg
  @routes << route
  route
end
route_exists?(route) click to toggle source
# File lib/peictt/builder/router.rb, line 32
def route_exists?(route)
  @routes.each do |r|
    if r.url == route.url
      return true
    end
  end
  false
end