Sha256: 491bdafec06a3f708c637dedfcc5c945f929eda9f5ee9982b9ac09efb1b4eb8a
Contents?: true
Size: 1.03 KB
Versions: 23
Compression:
Stored size: 1.03 KB
Contents
module Apipie class RoutesFormatter API_METHODS = %w{GET POST PUT PATCH OPTIONS DELETE} # The entry method called by Apipie to extract the array # representing the api dsl from the routes definition. def format_routes(rails_routes, args) rails_routes.map { |rails_route| format_route(rails_route, args) } end def format_route(rails_route, args) { :path => format_path(rails_route), :verb => format_verb(rails_route), :desc => args[:desc], :options => args[:options] } end def format_path(rails_route) File.join(rails_route.base_url, rails_route.path.spec.to_s.gsub('(.:format)', '')) end def format_verb(rails_route) verb = API_METHODS.select{|defined_verb| defined_verb =~ /\A#{rails_route.verb}\z/} if verb.count != 1 verb = API_METHODS.select{|defined_verb| defined_verb == rails_route.constraints[:method]} if verb.blank? raise "Unknow verb #{rails_route.path.spec.to_s}" end end verb.first end end end
Version data entries
23 entries across 23 versions & 1 rubygems