diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2015-06-19 00:50:41 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2015-06-19 00:50:41 +0900 |
commit | eeaa5ec5230d7a15f1c25ec696caf3a6a0aa5327 (patch) | |
tree | 3358672e3e3b27d30dd8d9d739221b55d21f860a | |
parent | e0b70b538cac33ef4cf0dca3a9df81b1651f9ba4 (diff) | |
download | aclog-eeaa5ec5230d7a15f1c25ec696caf3a6a0aa5327.tar.gz |
web: docs should be collected in Api class
-rw-r--r-- | app/api/api.rb | 17 | ||||
-rw-r--r-- | app/controllers/apidocs_controller.rb | 12 |
2 files changed, 18 insertions, 11 deletions
diff --git a/app/api/api.rb b/app/api/api.rb index 588e755..3183271 100644 --- a/app/api/api.rb +++ b/app/api/api.rb @@ -50,4 +50,21 @@ class Api < Grape::API route :any, "*path", ignore: true do raise Aclog::Exceptions::NotFound end + + class << self + def docs + Rails.cache.fetch("apidocs") do + {}.tap do |h| + Api.routes.each {|route| + next if route.route_ignore + next if route.route_method == "HEAD" + method = route.route_method + namespace = route.route_namespace.sub(/^\//, "") + path = route.route_path.split("/", 3).last.sub(/\(\.:format\)$/, "") + ((h[method] ||= {})[namespace] ||= {})[path] = route + } + end + end + end + end end diff --git a/app/controllers/apidocs_controller.rb b/app/controllers/apidocs_controller.rb index b22ecf3..3057405 100644 --- a/app/controllers/apidocs_controller.rb +++ b/app/controllers/apidocs_controller.rb @@ -12,17 +12,7 @@ class ApidocsController < ApplicationController private def set_apidocs - @apidocs = Rails.cache.fetch("apidocs", expired_in: 1.days) do - h = {} - Api.routes.reject {|r| r.route_ignore }.each {|route| - next if route.route_method == "HEAD" - method = route.route_method - namespace = route.route_namespace.sub(/^\//, "") - path = route.route_path.split("/", 3).last.sub(/\(\.:format\)$/, "") - ((h[method] ||= {})[namespace] ||= {})[path] = route - } - h - end + @apidocs = Api.docs end def set_sidebar |