Class: ApiTaster::Route
- Inherits:
-
Object
- Object
- ApiTaster::Route
- Defined in:
- lib/api_taster/route.rb
Class Method Summary collapse
- .comment_for(route) ⇒ Object
- .defined_definitions ⇒ Object
- .find(id) ⇒ Object
- .find_by_verb_and_path(verb, path) ⇒ Object
- .grouped_routes ⇒ Object
- .map_routes(path = ApiTaster.route_path) ⇒ Object
- .metadata_for(route) ⇒ Object
- .missing_definitions ⇒ Object
- .normalise_routes! ⇒ Object
- .params_for(route) ⇒ Object
Class Method Details
.comment_for(route) ⇒ Object
82 83 84 85 86 |
# File 'lib/api_taster/route.rb', line 82 def comment_for(route) unless undefined_route?(route) self.comments[route[:id].to_i] end end |
.defined_definitions ⇒ Object
94 95 96 |
# File 'lib/api_taster/route.rb', line 94 def defined_definitions routes.reject { |route| undefined_route?(route) } end |
.find(id) ⇒ Object
63 64 65 |
# File 'lib/api_taster/route.rb', line 63 def find(id) routes.find { |r| r[:id] == id.to_i } end |
.find_by_verb_and_path(verb, path) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/api_taster/route.rb', line 67 def find_by_verb_and_path(verb, path) routes.find do |r| r[:path].to_s == path && r[:verb].to_s.downcase == verb.to_s.downcase end end |
.grouped_routes ⇒ Object
59 60 61 |
# File 'lib/api_taster/route.rb', line 59 def grouped_routes defined_definitions.group_by { |r| r[:reqs][:controller] } end |
.map_routes(path = ApiTaster.route_path) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/api_taster/route.rb', line 13 def map_routes(path = ApiTaster.route_path) self.route_set = Rails.application.routes self.supplied_params = {} self.obsolete_definitions = [] self.comments = {} self. = {} normalise_routes! begin ApiTaster::RouteCollector.collect(path) Mapper.instance_eval(&self.mappings) rescue Route.mappings = {} end end |
.metadata_for(route) ⇒ Object
88 89 90 91 92 |
# File 'lib/api_taster/route.rb', line 88 def (route) unless undefined_route?(route) self.[route[:id].to_i] end end |
.missing_definitions ⇒ Object
98 99 100 |
# File 'lib/api_taster/route.rb', line 98 def missing_definitions routes.select { |route| undefined_route?(route) } end |
.normalise_routes! ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/api_taster/route.rb', line 30 def normalise_routes! @_route_counter = 0 self.routes = [] 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?(Sprockets::Environment) next if route.app == ApiTaster::Engine next if route.defaults[:controller].to_s.starts_with?('rails/') rack_app = discover_rack_app(route.app) if rack_app && rack_app.respond_to?(:routes) && rack_app.routes.respond_to?(:routes) rack_app.routes.routes.each do |rack_route| self.routes << normalise_route(rack_route, route.path.spec) end end next if route.verb.source.empty? self.routes << normalise_route(route) end self.routes.flatten! end |
.params_for(route) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/api_taster/route.rb', line 74 def params_for(route) unless supplied_params.has_key?(route[:id]) return { :undefined => route } end supplied_params[route[:id]].collect { |input| split_input(input, route) } end |