class Sapp::RouteMap
Attributes
routes[R]
Public Class Methods
new()
click to toggle source
# File lib/sapp/route_map.rb, line 8 def initialize @routes = Hash.new end
Public Instance Methods
add(verb, path, &handler)
click to toggle source
# File lib/sapp/route_map.rb, line 34 def add verb, path, &handler path_hash = Sapp::Path::Base.new(path, options: options ).parse verbs = get_or_create_verb verb controller = get_or_create_controller path_hash, verbs if path_exist? controller, path_hash[:original] update_path controller, path_hash, handler else create_set controller, path_hash, &handler end end
add_handler(path_hash, handler)
click to toggle source
# File lib/sapp/route_map.rb, line 101 def add_handler path_hash, handler path_hash.merge handler: handler end
add_path(path_hash, controller, &handler)
click to toggle source
# File lib/sapp/route_map.rb, line 93 def add_path path_hash, controller, &handler if block_given? controller[:paths] << add_handler(path_hash, handler) else controller[:paths] << add_handler(path_hash, empty_proc) end end
add_path_to_index(controller, path)
click to toggle source
# File lib/sapp/route_map.rb, line 68 def add_path_to_index controller, path controller[:index] << path end
add_stream(path_hash, controller)
click to toggle source
# File lib/sapp/route_map.rb, line 89 def add_stream path_hash, controller controller[:streams] << path_hash[:stream] end
create_set(controller, path_hash, &handler)
click to toggle source
# File lib/sapp/route_map.rb, line 61 def create_set controller, path_hash, &handler get_or_create_paths controller get_or_create_index controller add_path path_hash, controller, &handler add_path_to_index controller, path_hash[:original] end
empty_proc()
click to toggle source
# File lib/sapp/route_map.rb, line 24 def empty_proc @empty_proc ||= Proc.new { "Placeholder" } end
get_or_create_controller(path_hash, verbs)
click to toggle source
# File lib/sapp/route_map.rb, line 76 def get_or_create_controller path_hash, verbs controller = path_hash[:controller] verbs[controller] ||= Hash.new end
get_or_create_index(controller)
click to toggle source
# File lib/sapp/route_map.rb, line 85 def get_or_create_index controller controller[:index] ||= Array.new end
get_or_create_paths(controller)
click to toggle source
# File lib/sapp/route_map.rb, line 81 def get_or_create_paths controller controller[:paths] ||= Array.new end
get_or_create_verb(verb)
click to toggle source
# File lib/sapp/route_map.rb, line 72 def get_or_create_verb verb routes[verb] ||= Hash.new end
namespaces()
click to toggle source
# File lib/sapp/route_map.rb, line 12 def namespaces @namespaces ||= Array.new end
options()
click to toggle source
# File lib/sapp/route_map.rb, line 28 def options options = Hash.new options[:namespaces] = namespaces if namespaces options end
path_exist?(controller, path)
click to toggle source
# File lib/sapp/route_map.rb, line 57 def path_exist? controller, path controller.any? && controller[:index].include?(path) end
remove(verb, path=nil)
click to toggle source
# File lib/sapp/route_map.rb, line 105 def remove verb, path=nil if path routes[verb].delete path else routes.delete verb end end
set_namespace(names, nest)
click to toggle source
# File lib/sapp/route_map.rb, line 16 def set_namespace names, nest if nest && namespaces.any? @namespaces = namespaces << names else @namespaces = [names] end end
update_path(controller, path_hash, handler)
click to toggle source
# File lib/sapp/route_map.rb, line 48 def update_path controller, path_hash, handler map = controller[:paths].collect do |path| if path[:original] == path_hash[:original] add_handler(path_hash, handler) end end controller[:paths] = map end