Module: RailsCom::Routes

Extended by:
Routes
Included in:
Routes
Defined in:
lib/rails_com/meta/routes.rb

Instance Method Summary collapse

Instance Method Details

#actions(controller) ⇒ Object



8
9
10
# File 'lib/rails_com/meta/routes.rb', line 8

def actions(controller)
  routes_wrapper.select { |i| i[:controller] == controller.to_s }.map { |i| i[:action] }.uniq
end

#controllersObject



12
13
14
15
# File 'lib/rails_com/meta/routes.rb', line 12

def controllers
  _controllers = routes_wrapper.map { |i| i[:controller] }.compact.uniq
  _controllers - RailsCom.config.ignore_controllers
end

#detail(route) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rails_com/meta/routes.rb', line 37

def detail(route)
  wrap = ActionDispatch::Routing::RouteWrapper.new(route)
  info = route.defaults

  {
    verb: route.verb,
    path: wrap.path,
    controller: info[:controller],
    action: info[:action]
  }
end

#modulesObject



17
18
19
20
21
22
23
24
# File 'lib/rails_com/meta/routes.rb', line 17

def modules
  controllers.map do |i|
    x = i.split('/')
    if x.size >= 2
      x[0..-2].join('/')
    end
  end.compact.uniq
end

#routesObject



49
50
51
# File 'lib/rails_com/meta/routes.rb', line 49

def routes
  @routes ||= Rails.application.routes.routes
end

#routes_wrapperObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/rails_com/meta/routes.rb', line 26

def routes_wrapper
  return @routes_wrapper if @routes_wrapper.present?

  @routes_wrapper = []
  routes.each do |route|
    @routes_wrapper << detail(route)
  end

  @routes_wrapper
end

#verbs(controller, action) ⇒ Object



4
5
6
# File 'lib/rails_com/meta/routes.rb', line 4

def verbs(controller, action)
  routes_wrapper.select { |i| i[:controller] == controller.to_s && i[:action] == action.to_s }.map { |i| i[:verb] }.uniq
end