Module: Interdasting::Router

Defined in:
lib/interdasting/router.rb

Class Method Summary collapse

Class Method Details

.api_controller_namesObject



27
28
29
30
# File 'lib/interdasting/router.rb', line 27

def api_controller_names
  ar = routes.named_routes.select { |_k, v| v.defaults[:rp_prefix] }
  ar.values.map { |r| r.defaults[:controller] }.uniq
end

.api_controller_paths(controllers = api_controllers) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/interdasting/router.rb', line 11

def api_controller_paths(controllers = api_controllers)
  cp = controllers.map do |c|
    c.instance_methods(false).map do |m|
      c.instance_method(m).source_location.first
    end
  end
  cp.flatten.uniq.compact
end

.api_controllers(names = api_controller_names) ⇒ Object



20
21
22
23
24
25
# File 'lib/interdasting/router.rb', line 20

def api_controllers(names = api_controller_names)
  names.map do |cn|
    cn += '_controller'
    cn.classify.constantize
  end
end

.api_fullObject



4
5
6
7
8
9
# File 'lib/interdasting/router.rb', line 4

def api_full
  result = {}
  versions.each { |v| result[v] = {} }
  result.each { |k, v| fill_controllers_hash_for_version(k, v) }
  result
end

.app_routesObject



44
45
46
# File 'lib/interdasting/router.rb', line 44

def app_routes
  Rails.application.class.routes
end

.routesObject



40
41
42
# File 'lib/interdasting/router.rb', line 40

def routes
  app_routes.routes
end

.routes_for_version(version) ⇒ Object



32
33
34
# File 'lib/interdasting/router.rb', line 32

def routes_for_version(version)
  routes.to_a.select { |v| v && v.defaults[:version] == version }
end

.versionsObject



36
37
38
# File 'lib/interdasting/router.rb', line 36

def versions
  routes.to_a.map { |r| r && r.defaults[:version] }.uniq.compact
end