api-document-generator 0.0.2 → 0.0.6
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 +51 -9
- data/lib/api_document_generator/page_writer.rb +5 -2
- data/lib/api_document_generator.rb +25 -7
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d573c2a2002f4f1d887e28623543a55505833855f07de5210b3af4063013af01
|
4
|
+
data.tar.gz: 10906b929d5e03e2e59bff6125835e747f1aa4b6b180326588f9bb7fb9ccc912
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19c600ebd56f6aa0e54026078bc8c08210214a0ab532ac81ea9bec6b1cc3a1e8f4cfbd19c172e76728305483533c8f02a32f46f92730b0ad7d52360197ad89ae
|
7
|
+
data.tar.gz: e414a7f359b59affd4b0f94088ee34b2121ab2aa52db44b16c7a4a0417e808b509ade2c8d73bbd9fc9a418fa0a464423ca3f4cb0d1e6a6c759b68939cca042bd
|
@@ -1,9 +1,51 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
15
|
+
end
|
16
|
+
|
17
|
+
add_routes(controllers)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.add_routes(controllers)
|
21
|
+
insert_lines = [
|
22
|
+
" namespace :api do\n",
|
23
|
+
" end \n"
|
24
|
+
]
|
25
|
+
|
26
|
+
default_actions = ["index", "show", "new", "edit", "create", "delete", "update"]
|
27
|
+
|
28
|
+
controllers.each do |k, v|
|
29
|
+
path = v[:path]
|
30
|
+
|
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")
|
33
|
+
|
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
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
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
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -1,19 +1,37 @@
|
|
1
|
-
|
1
|
+
require 'api_document_generator/api_grabber'
|
2
|
+
require 'api_document_generaor/page_writer'
|
3
|
+
|
4
|
+
class ApiDocumentGenerator
|
2
5
|
class << self
|
3
|
-
def
|
4
|
-
|
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)
|
5
25
|
end
|
6
26
|
|
7
27
|
def install
|
8
28
|
if Dir.exist?('public') == false
|
9
29
|
`mkdir public`
|
10
30
|
end
|
11
|
-
|
12
|
-
generate_api_document
|
13
31
|
end
|
14
32
|
|
15
|
-
def generate_api_document
|
16
|
-
apis = ApiDocumentGenerator::ApiGrabber.grab_apis
|
33
|
+
def generate_api_document(controllers)
|
34
|
+
apis = ApiDocumentGenerator::ApiGrabber.grab_apis(controllers)
|
17
35
|
# api_document = ApiDocumentGenerator::PageWriter(apis)
|
18
36
|
|
19
37
|
# File.open('public/api_document', 'w') do |f|
|
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.6
|
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:
|