api-document-generator 0.0.3 → 0.0.7
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/lib/api_document_generator/api_grabber.rb +38 -36
- data/lib/api_document_generator/page_writer.rb +3 -1
- data/lib/api_document_generator.rb +6 -7
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 642dc3d6e6b56ddf446329d4f47cf9ef9e546b33395001d34d5b61792f038377
|
4
|
+
data.tar.gz: dadba8dc009fff4cd8529d5639b3b0f8f1ba6fd65baa4e7274f00f596e3fe871
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7866dd085d8facd6ec3e1c7e590e50e9dc17b71169339625fad3442cb64cb8491069b49cb04d291494a29829fe6af67fc814c02d9e49ab0bf684d4eed39919c1
|
7
|
+
data.tar.gz: 93eada07c21b2666aaf8084cf49dacbaca69d640c0f692e3164638692a13dda1df493b19ed8d471941bfe1ad68cf54cecda71710fdfa7f09a4809b157745d84b
|
@@ -1,49 +1,51 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
controllers
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
module ApiDocumentGenerator
|
2
|
+
class ApiGrabber
|
3
|
+
def self.grab_apis_params(controllers)
|
4
|
+
controllers.keys.each do |controller|
|
5
|
+
c_controller = controller.contantize.new
|
6
|
+
param_hash = c_controller.parameters_for_different_actions
|
7
|
+
controllers[controller][:resources] = c_controller.is_resources
|
8
|
+
controllers[controller][:exclude_actions] = c_controller.exclude_actions
|
9
|
+
|
10
|
+
controllers[controller][:actions].each do |action|
|
11
|
+
params = param_hash[action[:action].to_sym]
|
12
|
+
|
13
|
+
controllers[controller][:actions][:params] = params
|
14
|
+
end
|
13
15
|
end
|
16
|
+
|
17
|
+
add_routes(controllers)
|
14
18
|
end
|
15
19
|
|
16
|
-
add_routes(controllers)
|
17
|
-
|
20
|
+
def self.add_routes(controllers)
|
21
|
+
insert_lines = [
|
22
|
+
" namespace :api do\n",
|
23
|
+
" end \n"
|
24
|
+
]
|
18
25
|
|
19
|
-
|
20
|
-
insert_lines = [
|
21
|
-
" namespace :api do\n",
|
22
|
-
" end \n"
|
23
|
-
]
|
24
|
-
|
25
|
-
default_actions = ["index", "show", "new", "edit", "create", "delete", "update"]
|
26
|
+
default_actions = ["index", "show", "new", "edit", "create", "delete", "update"]
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
controllers.each do |k, v|
|
29
|
+
path = v[:path]
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
insert_lines.insert(-1, " #{v[:resources] ? ('resources') : ('resource')} :#{path.split("/").last}, only : #{default_actions - v[:exclude_actions]} do\n")
|
32
|
+
insert_lines.insert(-1, " end\n")
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
v[:actions].each do |action|
|
35
|
+
if !default_actions.include?(action[:action])
|
36
|
+
insert_lines.insert(-2, " #{action[:method].downcase} :#{action[:action]}\n")
|
37
|
+
end
|
36
38
|
end
|
37
39
|
end
|
38
|
-
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
File.open(file_name, 'r+') do |f|
|
42
|
+
routes = f.each_line.to_a
|
43
|
+
end_line = routes.delete_at(-1)
|
44
|
+
|
45
|
+
routes = routes + insert_lines + [end_line]
|
46
|
+
f.rewind
|
47
|
+
f.write(routes.join)
|
48
|
+
end
|
47
49
|
end
|
48
50
|
end
|
49
51
|
end
|
@@ -1,6 +1,11 @@
|
|
1
|
-
|
1
|
+
require 'api_document_generator/api_grabber'
|
2
|
+
require 'api_document_generator/page_writer'
|
3
|
+
|
4
|
+
class ApiDocumentGenerator
|
2
5
|
class << self
|
3
6
|
def initialize
|
7
|
+
install
|
8
|
+
|
4
9
|
controllers = {}
|
5
10
|
Rails.application.routes.routes.each do |route|
|
6
11
|
controller_path = route.defaults[:controller]
|
@@ -19,16 +24,10 @@
|
|
19
24
|
generate_api_document(controllers)
|
20
25
|
end
|
21
26
|
|
22
|
-
def hi
|
23
|
-
puts "Hello this is my api documentat generator gem!"
|
24
|
-
end
|
25
|
-
|
26
27
|
def install
|
27
28
|
if Dir.exist?('public') == false
|
28
29
|
`mkdir public`
|
29
30
|
end
|
30
|
-
|
31
|
-
initialize
|
32
31
|
end
|
33
32
|
|
34
33
|
def generate_api_document(controllers)
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Koe(shushi)
|
@@ -9,7 +9,21 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2021-11-16 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.0.0
|
13
27
|
description: Shushi first gem!
|
14
28
|
email: blackshushi4571@gmail.com
|
15
29
|
executables:
|
@@ -42,5 +56,5 @@ requirements: []
|
|
42
56
|
rubygems_version: 3.2.22
|
43
57
|
signing_key:
|
44
58
|
specification_version: 4
|
45
|
-
summary: Auto
|
59
|
+
summary: Auto `enerate Api document!
|
46
60
|
test_files: []
|