Class: ApiTaster::Route
- Inherits:
-
Object
- Object
- ApiTaster::Route
- Defined in:
- lib/api_taster/route.rb
Class Method Summary collapse
- .find(id) ⇒ Object
- .find_by_verb_and_path(verb, path) ⇒ Object
- .grouped_routes ⇒ Object
- .inputs_for(route) ⇒ Object
- .map_routes ⇒ Object
- .missing_definitions ⇒ Object
- .normalise_routes! ⇒ Object
Class Method Details
.find(id) ⇒ Object
48 49 50 |
# File 'lib/api_taster/route.rb', line 48 def find(id) routes.select { |r| r[:id] == id.to_i }[0] end |
.find_by_verb_and_path(verb, path) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/api_taster/route.rb', line 52 def find_by_verb_and_path(verb, path) routes.select do |r| r[:path].to_s == path && r[:verb].to_s.downcase == verb.to_s.downcase end[0] end |
.grouped_routes ⇒ Object
44 45 46 |
# File 'lib/api_taster/route.rb', line 44 def grouped_routes routes.group_by { |r| r[:reqs][:controller] } end |
.inputs_for(route) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/api_taster/route.rb', line 59 def inputs_for(route) unless inputs.has_key?(route[:id]) return { :undefined => route } end inputs[route[:id]].collect { |input| split_input(input, route) } end |
.map_routes ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/api_taster/route.rb', line 10 def map_routes self.route_set = Rails.application.routes self.inputs = {} self.obsolete_definitions = [] normalise_routes! Mapper.instance_eval(&self.mappings.call) end |
.missing_definitions ⇒ Object
67 68 69 |
# File 'lib/api_taster/route.rb', line 67 def missing_definitions routes.select { |route| undefined_route?(route) } end |
.normalise_routes! ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/api_taster/route.rb', line 20 def normalise_routes! self.routes = [] i = -1 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 if (rack_app = discover_rack_app(route.app)) && rack_app.respond_to?(:routes) rack_app.routes.routes.each do |rack_route| self.routes << normalise_route(rack_route, i+=1) end end next if route.verb.source.empty? self.routes << normalise_route(route, i+=1) end end |