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
- .map_routes ⇒ Object
- .missing_definitions ⇒ Object
- .normalise_routes! ⇒ Object
- .params_for(route) ⇒ Object
Class Method Details
.find(id) ⇒ Object
51 52 53 |
# File 'lib/api_taster/route.rb', line 51 def find(id) routes.select { |r| r[:id] == id.to_i }[0] end |
.find_by_verb_and_path(verb, path) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/api_taster/route.rb', line 55 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
47 48 49 |
# File 'lib/api_taster/route.rb', line 47 def grouped_routes routes.group_by { |r| r[:reqs][:controller] } end |
.map_routes ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/api_taster/route.rb', line 11 def map_routes self.route_set = Rails.application.routes self.supplied_params = {} self.obsolete_definitions = [] normalise_routes! Mapper.instance_eval(&self.mappings.call) end |
.missing_definitions ⇒ Object
70 71 72 |
# File 'lib/api_taster/route.rb', line 70 def missing_definitions routes.select { |route| undefined_route?(route) } end |
.normalise_routes! ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/api_taster/route.rb', line 21 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 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, 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
62 63 64 65 66 67 68 |
# File 'lib/api_taster/route.rb', line 62 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 |