Class: ApiTaster::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/api_taster/route.rb

Class Method Summary collapse

Class Method Details

.comment_for(route) ⇒ Object



79
80
81
82
83
# File 'lib/api_taster/route.rb', line 79

def comment_for(route)
  unless undefined_route?(route)
    self.comments[route[:id].to_i]
  end
end

.defined_definitionsObject



91
92
93
# File 'lib/api_taster/route.rb', line 91

def defined_definitions
  routes.reject { |route| undefined_route?(route) }
end

.find(id) ⇒ Object



60
61
62
# File 'lib/api_taster/route.rb', line 60

def find(id)
  routes.find { |r| r[:id] == id.to_i }
end

.find_by_verb_and_path(verb, path) ⇒ Object



64
65
66
67
68
69
# File 'lib/api_taster/route.rb', line 64

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_routesObject



56
57
58
# File 'lib/api_taster/route.rb', line 56

def grouped_routes
  defined_definitions.group_by { |r| r[:reqs][:controller] }
end

.map_routesObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/api_taster/route.rb', line 13

def map_routes
  self.route_set            = Rails.application.routes
  self.supplied_params      = {}
  self.obsolete_definitions = []
  self.comments             = {}
  self.             = {}

  normalise_routes!

  begin
    Mapper.instance_eval(&self.mappings.call)
  rescue
    Route.mappings = {}
  end
end

.metadata_for(route) ⇒ Object



85
86
87
88
89
# File 'lib/api_taster/route.rb', line 85

def (route)
  unless undefined_route?(route)
    self.[route[:id].to_i]
  end
end

.missing_definitionsObject



95
96
97
# File 'lib/api_taster/route.rb', line 95

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
# 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?(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|
        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



71
72
73
74
75
76
77
# File 'lib/api_taster/route.rb', line 71

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