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
81 82 83 84 85 |
# File 'lib/api_taster/route.rb', line 81 def comment_for(route) unless undefined_route?(route) self.comments[route[:id].to_i] end end |
.defined_definitions ⇒ Object
93 94 95 |
# File 'lib/api_taster/route.rb', line 93 def defined_definitions routes.reject { |route| undefined_route?(route) } end |
.find(id) ⇒ Object
62 63 64 |
# File 'lib/api_taster/route.rb', line 62 def find(id) routes.find { |r| r[:id] == id.to_i } end |
.find_by_verb_and_path(verb, path) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/api_taster/route.rb', line 66 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
58 59 60 |
# File 'lib/api_taster/route.rb', line 58 def grouped_routes defined_definitions.group_by { |r| r[:reqs][:controller] } end |
.map_routes(path = ApiTaster.route_path) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/api_taster/route.rb', line 12 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
87 88 89 90 91 |
# File 'lib/api_taster/route.rb', line 87 def (route) unless undefined_route?(route) self.[route[:id].to_i] end end |
.missing_definitions ⇒ Object
97 98 99 |
# File 'lib/api_taster/route.rb', line 97 def missing_definitions routes.select { |route| undefined_route?(route) } end |
.normalise_routes! ⇒ Object
29 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 |
# File 'lib/api_taster/route.rb', line 29 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
73 74 75 76 77 78 79 |
# File 'lib/api_taster/route.rb', line 73 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 |