Module: RouteDog
- Included in:
- Middleware::RouteDog
- Defined in:
- lib/route_dog.rb,
lib/route_dog/report.rb,
lib/route_dog/railtie.rb,
lib/route_dog/middleware/watcher.rb,
lib/route_dog/middleware/notifier.rb,
lib/route_dog/middleware/route_dog.rb
Defined Under Namespace
Modules: Middleware
Classes: Railtie, Report
Class Method Summary
collapse
Class Method Details
.action_string_for_route(route) ⇒ Object
47
48
49
|
# File 'lib/route_dog.rb', line 47
def self.action_string_for_route(route)
"#{route.requirements[:controller]}##{route.requirements[:action]}"
end
|
.config_file ⇒ Object
6
7
8
|
# File 'lib/route_dog.rb', line 6
def self.config_file
File.join(Rails.root, 'config', 'middlewares_route_dog.yml')
end
|
.constantize_controller_str(controller) ⇒ Object
43
44
45
|
# File 'lib/route_dog.rb', line 43
def self.constantize_controller_str(controller)
controller.split("/").map{|c| c.split("_").map{|cc| cc.capitalize}.join }.join("::").concat("Controller").constantize
end
|
.delete_watched_routes_file ⇒ Object
24
25
26
|
# File 'lib/route_dog.rb', line 24
def self.delete_watched_routes_file
File.delete(watched_routes_file) if File.exists?(watched_routes_file)
end
|
.load_watched_routes ⇒ Object
14
15
16
17
18
|
# File 'lib/route_dog.rb', line 14
def self.load_watched_routes
YAML.load_file(watched_routes_file)
rescue Errno::ENOENT
{}
end
|
.route_tested?(route) ⇒ Boolean
38
39
40
41
|
# File 'lib/route_dog.rb', line 38
def self.route_tested?(route)
requirements = route.requirements
route_tested_with_requirements?(requirements[:controller], requirements[:action], route.verb)
end
|
.route_tested_with_requirements?(controller, action, method) ⇒ Boolean
When method.nil? it respond to all methods.
29
30
31
32
33
34
35
36
|
# File 'lib/route_dog.rb', line 29
def self.route_tested_with_requirements?(controller, action, method)
begin
available_methods = load_watched_routes[controller.to_s.downcase][action.to_s.downcase]
method.nil? ? available_methods.any? : available_methods.include?(method.to_s.downcase)
rescue
false
end
end
|
.watched_routes_file ⇒ Object
10
11
12
|
# File 'lib/route_dog.rb', line 10
def self.watched_routes_file
File.join(Rails.root, 'tmp', 'route_dog_routes.yml')
end
|
.write_watched_routes(routes) ⇒ Object
20
21
22
|
# File 'lib/route_dog.rb', line 20
def self.write_watched_routes(routes)
File.open(watched_routes_file, "w+") {|file| file.puts(routes.to_yaml) }
end
|