Sha256: bf5ebaffcd49c12f5b1d408997d036a40c854e8653d196b0f80262b645b831cb
Contents?: true
Size: 977 Bytes
Versions: 14
Compression:
Stored size: 977 Bytes
Contents
# frozen_string_literal: true module SwaggerDocsGenerator # # Extractor routes info # # Give information about routes class Extractor def initialize(controller, action) @action = action @controller = controller @routes = Rails.application.routes.routes end def verb router do |route| route.verb.source.to_s.delete('$' + '^') end end def path router do |route| route.path.spec.to_s.gsub('(.:format)', '.json').gsub(':id', '{id}') end end private def rte_controller(rte) rte[:controller].eql?(controller_name) end def rte_action(rte) rte[:action].eql?(@action.to_s) end def controller_name @controller.controller_path end def router data = nil @routes.map do |route| rte = route.defaults data = yield(route, rte) if rte_controller(rte) && rte_action(rte) end data.downcase end end end
Version data entries
14 entries across 14 versions & 1 rubygems