lib/api_taster/route.rb in api_taster-0.4.8 vs lib/api_taster/route.rb in api_taster-0.5.0

- old
+ new

@@ -3,17 +3,21 @@ cattr_accessor :route_set cattr_accessor :routes cattr_accessor :mappings cattr_accessor :supplied_params cattr_accessor :obsolete_definitions + cattr_accessor :comments + cattr_accessor :metadata class << self def map_routes self.route_set = Rails.application.routes self.supplied_params = {} self.obsolete_definitions = [] + self.comments = {} + self.metadata = {} normalise_routes! begin Mapper.instance_eval(&self.mappings.call) @@ -29,10 +33,11 @@ unless route_set.respond_to?(:routes) raise ApiTaster::Exception.new('Route definitions are missing, have you defined ApiTaster.routes?') end route_set.routes.each do |route| + next if route.app.is_a?(ActionDispatch::Routing::Mapper::Constraints) next if route.app.is_a?(Sprockets::Environment) next if route.app == ApiTaster::Engine if (rack_app = discover_rack_app(route.app)) && rack_app.respond_to?(:routes) rack_app.routes.routes.each do |rack_route| @@ -67,9 +72,21 @@ unless supplied_params.has_key?(route[:id]) return { :undefined => route } end supplied_params[route[:id]].collect { |input| split_input(input, route) } + end + + def comment_for(route) + unless undefined_route?(route) + self.comments[route[:id].to_i] + end + end + + def metadata_for(route) + unless undefined_route?(route) + self.metadata[route[:id].to_i] + end end def defined_definitions routes.reject { |route| undefined_route?(route) } end