7
8
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
|
# File 'lib/express_admin/commandable.rb', line 7
def call(mapper, options = {})
options = @defaults.merge(options)
modules = []
controller_name = mapper.send(:parent_resource).controller
scope = mapper.instance_variable_get(:@scope)
while scope.respond_to?(:parent) && scope = scope.parent
possible_module = scope.instance_variable_get(:@hash)[:module]
break if possible_module.nil?
modules << possible_module
end
modules.compact!
modules << controller_name
controller_class = nil
begin
controller_class = "#{modules.join("/").classify.pluralize}Controller".constantize
rescue NameError => e
controller_class = "#{modules.join("/").classify}Controller".constantize
end
if controller_class.respond_to?(:resource_class)
resource_class = controller_class.resource_class
if resource_class.respond_to?(:commands)
resource_class.commands.each do |action|
mapper.member do
mapper.post action[:name].debang, to: "#{controller_name}##{action[:name].debang}"
end
end
end
end
end
|