api-document-generator 0.0.0 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/adg +22 -0
- data/lib/api_document_generator/api_grabber.rb +49 -0
- data/lib/api_document_generator/page_writer.rb +3 -0
- data/lib/api_document_generator.rb +46 -3
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6321821bddfac046fc70de339224a1d874305b79b52eafe06c024464b3ae0f26
|
4
|
+
data.tar.gz: ac629197affa7839d90282efaa47d3fcce9d2331e522abc350ff5977cdc24067
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 027ae92f3c4e56ab8895c57a0e799efd4ac182485edb6ddbac2f2366cfb8f3eaa098f794e55eb51aaea55e80df4517c93bf2e47ebf0edb9238a0ed423e66da2e
|
7
|
+
data.tar.gz: f6750c0a291832c46514b8cb8ba81cfd73c8e5cc17f735d8c80b1f088bdc9d4849f07176a8a6f3a919d141c3a66e4c05582801d73c556c79a728a5d5a95ceb63
|
data/bin/adg
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'api_document_generator'
|
4
|
+
require 'api_document_generator/api_grabber'
|
5
|
+
require 'api_document_generator/page_writer'
|
6
|
+
|
7
|
+
command = ARGV[0]
|
8
|
+
|
9
|
+
if command == "install"
|
10
|
+
ApiDocumentGenerator.install
|
11
|
+
puts "\e[32mInstallation competed!\e[0m"
|
12
|
+
end
|
13
|
+
|
14
|
+
if command == "run"
|
15
|
+
ApiDocumentGenerator.generate_api_document
|
16
|
+
puts "\e[32mApi document generated!\e[0m"
|
17
|
+
end
|
18
|
+
|
19
|
+
if command == 'uninstall'
|
20
|
+
ApiDocumentGenerator.uninstall
|
21
|
+
puts "\e[33mApi Document Generator had been uninstalled.. Bye :'(\e[0m"
|
22
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class ApiDocumentGenerator::ApiGrabber
|
2
|
+
def self.grab_apis_params(controllers)
|
3
|
+
controllers.keys.each do |controller|
|
4
|
+
c_controller = controller.contantize.new
|
5
|
+
param_hash = c_controller.parameters_for_different_actions
|
6
|
+
controllers[controller][:resources] = c_controller.is_resources
|
7
|
+
controllers[controller][:exclude_actions] = c_controller.exclude_actions
|
8
|
+
|
9
|
+
controllers[controller][:actions].each do |action|
|
10
|
+
params = param_hash[action[:action].to_sym]
|
11
|
+
|
12
|
+
controllers[controller][:actions][:params] = params
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
add_routes(controllers)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.add_routes(controllers)
|
20
|
+
insert_lines = [
|
21
|
+
" namespace :api do\n",
|
22
|
+
" end \n"
|
23
|
+
]
|
24
|
+
|
25
|
+
default_actions = ["index", "show", "new", "edit", "create", "delete", "update"]
|
26
|
+
|
27
|
+
controllers.each do |k, v|
|
28
|
+
path = v[:path]
|
29
|
+
|
30
|
+
insert_lines.insert(-1, " #{v[:resources] ? ('resources') : ('resource')} :#{path.split("/").last}, only : #{default_actions - v[:exclude_actions]} do\n")
|
31
|
+
insert_lines.insert(-1, " end\n")
|
32
|
+
|
33
|
+
v[:actions].each do |action|
|
34
|
+
if !default_actions.include?(action[:action])
|
35
|
+
insert_lines.insert(-2, " #{action[:method].downcase} :#{action[:action]}\n")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
File.open(file_name, 'r+') do |f|
|
41
|
+
routes = f.each_line.to_a
|
42
|
+
end_line = routes.delete_at(-1)
|
43
|
+
|
44
|
+
routes = routes + insert_lines + [end_line]
|
45
|
+
f.rewind
|
46
|
+
f.write(routes.join)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,5 +1,48 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require 'api_document_generator/api_grabber'
|
2
|
+
require 'api_document_generaor/page_writer'
|
3
|
+
|
4
|
+
class ApiDocumentGenerator
|
5
|
+
class << self
|
6
|
+
def initialize
|
7
|
+
install
|
8
|
+
|
9
|
+
controllers = {}
|
10
|
+
Rails.application.routes.routes.each do |route|
|
11
|
+
controller_path = route.defaults[:controller]
|
12
|
+
|
13
|
+
if controller_path
|
14
|
+
controller_name = controller_path.split('/').map(&:humanize).join('::')
|
15
|
+
|
16
|
+
if controller_name.constantize.include?(Api::GeneratorHelper)
|
17
|
+
controllers[controller_name] ||= {path: controller_path, actions: []}
|
18
|
+
|
19
|
+
controllers[controller_name][:actions].push({action: route.defaults[:action], method: route.verb})
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
generate_api_document(controllers)
|
25
|
+
end
|
26
|
+
|
27
|
+
def install
|
28
|
+
if Dir.exist?('public') == false
|
29
|
+
`mkdir public`
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def generate_api_document(controllers)
|
34
|
+
apis = ApiDocumentGenerator::ApiGrabber.grab_apis(controllers)
|
35
|
+
# api_document = ApiDocumentGenerator::PageWriter(apis)
|
36
|
+
|
37
|
+
# File.open('public/api_document', 'w') do |f|
|
38
|
+
# api_document.each do |line|
|
39
|
+
# f.write(line + "\n")
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
end
|
43
|
+
|
44
|
+
def uninstall
|
45
|
+
`rm -rf public/api_document`
|
46
|
+
end
|
4
47
|
end
|
5
48
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api-document-generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Koe(shushi)
|
@@ -12,11 +12,15 @@ date: 2021-11-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
13
13
|
description: Shushi first gem!
|
14
14
|
email: blackshushi4571@gmail.com
|
15
|
-
executables:
|
15
|
+
executables:
|
16
|
+
- adg
|
16
17
|
extensions: []
|
17
18
|
extra_rdoc_files: []
|
18
19
|
files:
|
20
|
+
- bin/adg
|
19
21
|
- lib/api_document_generator.rb
|
22
|
+
- lib/api_document_generator/api_grabber.rb
|
23
|
+
- lib/api_document_generator/page_writer.rb
|
20
24
|
homepage: https://github.com/blackshushi/api_document_generator
|
21
25
|
licenses: []
|
22
26
|
metadata: {}
|