swag 0.0.1 → 0.1.0
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/swag +1 -0
- data/lib/swag.rb +44 -7
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3730514a48c593969d65e0aade3f9bf8815dfb95
|
|
4
|
+
data.tar.gz: 758d3304a1a983fc7524ffee0922f9159ecd646e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3587fa2c131e746227ca579033b04e8e91ff57d698ce30c0daa419ed83c3ca3ae124fbddabb64997d74817807264a1ea0b30b32cc6911a5c8d32e79019e43e99
|
|
7
|
+
data.tar.gz: c5cd06424ba1437643174145a57c60b4c6b02123591ff93e0da7489bf9f0e83a63c16bf443166869dce6d2976e253ca92ff05cbf8543b041b8dc2e6084b35ae0
|
data/bin/swag
CHANGED
data/lib/swag.rb
CHANGED
|
@@ -5,6 +5,7 @@ class Swag
|
|
|
5
5
|
puts "Swag, world."
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
+
# verifies rails directory
|
|
8
9
|
def self.check
|
|
9
10
|
puts "Checking your directory: #{Dir.pwd}"
|
|
10
11
|
if File.exist?("bin/rails")
|
|
@@ -15,10 +16,11 @@ class Swag
|
|
|
15
16
|
end
|
|
16
17
|
end
|
|
17
18
|
|
|
19
|
+
# checks that app/controllers can be read
|
|
18
20
|
def self.checkControllers
|
|
19
21
|
puts "Checking controllers."
|
|
20
22
|
begin
|
|
21
|
-
Dir.foreach("app/controllers") do |c|
|
|
23
|
+
Dir.foreach("app/controllers") do |c|
|
|
22
24
|
puts "Found #{c}"
|
|
23
25
|
end
|
|
24
26
|
rescue => ex
|
|
@@ -28,15 +30,50 @@ class Swag
|
|
|
28
30
|
end
|
|
29
31
|
end
|
|
30
32
|
|
|
33
|
+
# writes specific controller's routes (helper for self.writePaths)
|
|
34
|
+
# 'name' is the controller's name, 'doc' is the open YAML File to write to
|
|
35
|
+
def self.analyzeController(controllerName, doc)
|
|
36
|
+
puts "Analyzing controller: #{controllerName}"
|
|
37
|
+
# controller = File.open("app/controllers/#{controllerName}", 'r')
|
|
38
|
+
nameSliced = controllerName.slice(0..(controllerName.index('_') -1))
|
|
39
|
+
doc << " /#{nameSliced}:\n"
|
|
40
|
+
File.open("app/controllers/#{controllerName}", 'r') do |c|
|
|
41
|
+
@show = false
|
|
42
|
+
c.each_line do |line|
|
|
43
|
+
if line.include? "def index"
|
|
44
|
+
puts "#{controllerName} contains index"
|
|
45
|
+
doc << " get:\n"
|
|
46
|
+
doc << " description:\n"
|
|
47
|
+
elsif line.include? "def create"
|
|
48
|
+
puts "#{controllerName} contains new"
|
|
49
|
+
doc << " post:\n"
|
|
50
|
+
doc << " description:\n"
|
|
51
|
+
elsif line.include? "def show"
|
|
52
|
+
@show = true
|
|
53
|
+
end
|
|
54
|
+
end # end each_line do block
|
|
55
|
+
if @show
|
|
56
|
+
puts "#{controllerName} contains show"
|
|
57
|
+
doc << " /#{nameSliced}/:id\n"
|
|
58
|
+
end
|
|
59
|
+
end # end File.open do block
|
|
60
|
+
puts "Closed file." # closed automatically
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# lists controller paths by reading app/controllers directory
|
|
31
64
|
def self.writePaths
|
|
32
65
|
puts "Writing paths."
|
|
33
66
|
begin
|
|
34
|
-
|
|
35
|
-
doc
|
|
36
|
-
doc
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
67
|
+
doc = File.open("doc.yml", 'w')
|
|
68
|
+
doc << "info: Generated with Swag.\n"
|
|
69
|
+
doc << "paths:\n"
|
|
70
|
+
Dir.foreach("app/controllers") do |c|
|
|
71
|
+
unless (c == "." || c == ".." || c == "concerns" ||
|
|
72
|
+
c == "application_controller.rb")
|
|
73
|
+
analyzeController(c, doc)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
doc.close
|
|
40
77
|
end
|
|
41
78
|
end
|
|
42
79
|
end
|