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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/swag +1 -0
  3. data/lib/swag.rb +44 -7
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c7b608e3eb31ac4e990719a648833c6674dba3a
4
- data.tar.gz: 31a5bf8147cc3791867b710aafa96be7d4e0843a
3
+ metadata.gz: 3730514a48c593969d65e0aade3f9bf8815dfb95
4
+ data.tar.gz: 758d3304a1a983fc7524ffee0922f9159ecd646e
5
5
  SHA512:
6
- metadata.gz: a2b703ef5d4e643f72159f128b878c739e69ec17b0eff13e3c50634206760023305f2cb0c17a25bf0823c8c98ba08a16cb6974381dc174305428027cce81a464
7
- data.tar.gz: c91fad0fdf25c8d4050c7b83670eb066e6dca398d6e50bcf46fa27766ae260d2bd971c65b73ce29fb483020ff39b88d3205dde957901f14de19c7484e0c68817
6
+ metadata.gz: 3587fa2c131e746227ca579033b04e8e91ff57d698ce30c0daa419ed83c3ca3ae124fbddabb64997d74817807264a1ea0b30b32cc6911a5c8d32e79019e43e99
7
+ data.tar.gz: c5cd06424ba1437643174145a57c60b4c6b02123591ff93e0da7489bf9f0e83a63c16bf443166869dce6d2976e253ca92ff05cbf8543b041b8dc2e6084b35ae0
data/bin/swag CHANGED
@@ -4,3 +4,4 @@ require 'swag'
4
4
  puts Swag.hi
5
5
  puts Swag.check
6
6
  puts Swag.checkControllers
7
+ puts Swag.writePaths
@@ -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
- @controllerArray = self.readControllers
35
- doc = open(doc.yml, 'w')
36
- doc.truncate(0)
37
- doc.write("info: Generated with Swag.\n")
38
- doc.write("paths:\n")
39
- @controllerArray.each {|c| doc.write("-#{c}\n")}
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan Miller