Sha256: 8d653855ed98e23618c024408a698e1ce4857342f86fdb0d9910e8f704a727b9
Contents?: true
Size: 780 Bytes
Versions: 8
Compression:
Stored size: 780 Bytes
Contents
module Restfulness class Router attr_accessor :routes, :current_scope def initialize(&block) self.routes = [] self.current_scope = [] instance_eval(&block) if block_given? end def add(*args, &block) # Do we need to pretend we've been given a scope? scope(*args[0..-2], &block) if block_given? routes << Route.new(*(current_scope + args)) end def scope(*args, &block) old_scope = current_scope self.current_scope += args instance_eval(&block) if block_given? self.current_scope = old_scope end def route_for(path) parts = path.gsub(/^\/|\/$/, '').split(/\//) routes.each do |route| return route if route.handles?(parts) end nil end end end
Version data entries
8 entries across 8 versions & 1 rubygems