4
5
6
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
|
# File 'lib/api_doc_generation/format_file.rb', line 4
def analyze_file(path)
controller_path = path.split("app/controllers").last
class_name = controller_path.gsub(/controller.*\.rb/, 'controller').classify
klass = class_name.safe_constantize
filelines = File.readlines(path)
actions = klass.action_methods - klass.superclass.action_methods
ctrl_about = get_controller_about(filelines, klass.to_s)
actions = actions.map do |action|
method = klass.instance_method action
filepath, line = method.source_location
note = FormatNote.analyze(filelines, line - 2)
note["Level"] ||= ''
note['Name'] = action.to_s
unless note['Path']
note = get_routes(klass, action).merge(note)
else
note['Path'] = note['Path'][0]['desc']
note['Method'] = note['Method'][0]['desc'] rescue nil
end
note
end
actions.delete_if do |val|
val['Return'].nil?
end
{
'Path' => path,
'Klass' => klass.to_s,
'About' => ctrl_about,
'Actions' => actions
}
end
|