9
10
11
12
13
14
15
16
17
18
19
20
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/boilerman/actions.rb', line 9
def self.get_action_hash(filters={})
controller_filters = filters[:controller_filters] || []
with_actions = filters[:with_actions] || []
without_actions = filters[:without_actions] || []
with_filters = filters[:with_filters] || []
without_filters = filters[:without_filters] || []
ignore_filters = filters[:ignore_filters] || []
ignore_actions = filters[:ignore_actions] || []
routes = Rails.application.routes.routes.routes.select do |route|
route.defaults.key?(:controller) &&
!route.defaults.empty? &&
route.app.class != ActionDispatch::Routing::Redirect
end
controller_action_hash = build_controller_action_list(routes)
filter_list = build_filter_list(controller_action_hash)
unless controller_filters.empty?
filter_list.select! do |controller, _|
METADATA_KEYS.include?(controller) || include_controller?(controller_filters, controller.to_s)
end
end
unless ignore_actions.empty?
filter_list = filter_list.inject(Hash.new) do |new_results, (controller, actions)|
new_results[controller] = actions.reject{|action, filter| ignore_actions.include?(action) }
new_results
end
end
unless ignore_filters.empty?
filter_list = filter_list.inject(Hash.new) do |new_results, (controller, actions)|
new_results[controller] = Hash[actions.map do |action, filters|
[action, filters.reject{|filter| ignore_filters.include?(filter.to_s)}]
end]
new_results
end
end
unless without_filters.empty?
filter_list = filter_list.inject(Hash.new) do |new_results, (controller, actions)|
new_results[controller] = actions.select{|action, filters| (without_filters & Array(filters)).empty? }
new_results
end
end
unless with_filters.empty?
filter_list = filter_list.inject(Hash.new) do |new_results, (controller, actions)|
new_results[controller] = actions.select{|action, filters| (with_filters - Array(filters)).empty? }
new_results
end
end
filter_list
end
|