class Shaf::ApiRoutes::Registry
Public Class Methods
controllers()
click to toggle source
# File lib/shaf/extensions/api_routes.rb, line 11 def controllers routes.keys.sort_by(&:to_s) end
register(controller, method, symbol)
click to toggle source
# File lib/shaf/extensions/api_routes.rb, line 7 def register(controller, method, symbol) routes[controller][symbol] << method.to_s.upcase end
routes_for(controller) { |route_info(controller, symbol)| ... }
click to toggle source
# File lib/shaf/extensions/api_routes.rb, line 15 def routes_for(controller) sorted = routes[controller].keys.sort_by(&:to_s) sorted.each do |symbol| yield route_info(controller, symbol) end end
Private Class Methods
route_info(controller, symbol)
click to toggle source
# File lib/shaf/extensions/api_routes.rb, line 33 def route_info(controller, symbol) methods = routes[controller][symbol].to_a template_method = :"#{symbol}_template" if controller.respond_to? template_method template = controller.public_send(template_method) else template = symbol symbol = '-' end [methods, template, symbol] end
routes()
click to toggle source
# File lib/shaf/extensions/api_routes.rb, line 24 def routes @routes ||= Hash.new do |hash, key| # Group routes with conditionals together (`Set.new`). Like: # get(:foobar_path, agent: /ios/) { "ios specific" } # get(:foobar_path, agent: /android/) { "android specific" } hash[key] = Hash.new { |h, k| h[k] = Set.new } end end