swag 0.1.0 → 0.1.2

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 (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/Swag.rb +88 -0
  3. data/lib/SwagHelper.rb +32 -0
  4. metadata +4 -3
  5. data/lib/swag.rb +0 -79
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3730514a48c593969d65e0aade3f9bf8815dfb95
4
- data.tar.gz: 758d3304a1a983fc7524ffee0922f9159ecd646e
3
+ metadata.gz: 09b2a6509fa9e6cfecd0f8c3a23a1471d46b6533
4
+ data.tar.gz: 0cc410a101873e72f5cf5273643c791e95a1d95f
5
5
  SHA512:
6
- metadata.gz: 3587fa2c131e746227ca579033b04e8e91ff57d698ce30c0daa419ed83c3ca3ae124fbddabb64997d74817807264a1ea0b30b32cc6911a5c8d32e79019e43e99
7
- data.tar.gz: c5cd06424ba1437643174145a57c60b4c6b02123591ff93e0da7489bf9f0e83a63c16bf443166869dce6d2976e253ca92ff05cbf8543b041b8dc2e6084b35ae0
6
+ metadata.gz: 6d85e83d050badd528c08134088c228efc6150da7ec3ae7d3961edbfdeb310eeab8716c647053c31445075fcae1dbecf5e23859ab4e74da740701d94b85416f8
7
+ data.tar.gz: 6b2df6f230f22b788b05af90acb9b5ec03e164f6c09ac9333ac417ad77ea608503e57003cf41b10002baf69dd449a77b3acd09c1377c4c9a850246f18739e914
data/lib/Swag.rb ADDED
@@ -0,0 +1,88 @@
1
+ require_relative 'SwagHelper.rb'
2
+
3
+ class Swag
4
+
5
+ @helper = SwagHelper.new
6
+
7
+ def initialize
8
+ end
9
+
10
+ def self.hi
11
+ puts "Swag, world."
12
+ end
13
+
14
+ # verifies rails directory
15
+ def self.check
16
+ puts "Checking your directory: #{Dir.pwd}"
17
+ if File.exist?("bin/rails")
18
+ puts "Rails App detected. Proceeding."
19
+ else
20
+ puts "You must be in a Rails root directory for Swag to work. Aborting."
21
+ abort
22
+ end
23
+ end
24
+
25
+ # checks that app/controllers can be read
26
+ def self.checkControllers
27
+ puts "Checking controllers."
28
+ begin
29
+ Dir.foreach("app/controllers") do |c|
30
+ puts "Found #{c}"
31
+ end
32
+ rescue => ex
33
+ puts "Error while reading controllers."
34
+ puts ex.inspect
35
+ puts ex.backtrace
36
+ end # end begin
37
+ end # end checkControllers
38
+
39
+ # writes specific controller's routes (helper for self.writePaths)
40
+ # 'controllerName' is the controller's name, 'doc' is the open File
41
+ def self.analyzeController(controllerName, doc)
42
+ puts "Analyzing controller: #{controllerName}"
43
+
44
+ # edits the controller name for use in the File
45
+ nameSliced = controllerName.slice(0..(controllerName.index('_') -1))
46
+ doc << " /#{nameSliced}:\n"
47
+
48
+ File.open("app/controllers/#{controllerName}", 'r') do |c|
49
+ @show = false
50
+ c.each_line do |line|
51
+ if line.include? "def index"
52
+ @helper.doIndex(controllerName, doc)
53
+ elsif line.include? "def create"
54
+ @helper.doCreate(controllerName, doc)
55
+ elsif line.include? "def show"
56
+ @show = true
57
+ end
58
+ end # end each_line do block
59
+ if @show
60
+ @helper.doShow(nameSliced, controllerName, doc)
61
+ end
62
+ end # end File.open do block (File is closed automatically)
63
+ end # end analyzeController
64
+
65
+ # lists controller paths by reading app/controllers directory
66
+ def self.writePaths
67
+ puts "Writing paths."
68
+ begin
69
+ # creates directory for swag to use
70
+ Dir.mkdir("swagGem") unless File.exists?("swagGem")
71
+
72
+ doc = File.open("swagGem/api.yml", 'w')
73
+ doc << "info: Generated with Swag.\n"
74
+ doc << "paths:\n"
75
+ Dir.foreach("app/controllers") do |c|
76
+ unless (c == "." || c == ".." || c == "concerns" ||
77
+ c == "application_controller.rb")
78
+ analyzeController(c, doc)
79
+ end
80
+ end
81
+ doc.close
82
+ rescue => ex
83
+ puts "Error while writing paths."
84
+ puts ex.inspect
85
+ puts ex.backtrace
86
+ end # end begin block
87
+ end # end writePaths
88
+ end # end Class
data/lib/SwagHelper.rb ADDED
@@ -0,0 +1,32 @@
1
+ class SwagHelper
2
+
3
+ def initialize
4
+ end
5
+
6
+ # writes config info to YAML doc
7
+ def doConfig(doc)
8
+ # open config file (make one if it doesn't exist)
9
+ # read line-by-line
10
+ # write relevant information to doc
11
+ doc << "info: Generated with Swag.\n"
12
+ doc << "paths:\n"
13
+ end
14
+
15
+ # prints index info to open YAML File 'doc'
16
+ def doIndex(controllerName, doc)
17
+ puts "#{controllerName} contains index"
18
+ doc << " get:\n"
19
+ doc << " description:\n"
20
+ end
21
+
22
+ def doCreate(controllerName, doc)
23
+ puts "#{controllerName} contains new"
24
+ doc << " post:\n"
25
+ doc << " description:\n"
26
+ end
27
+
28
+ def doShow(nameSliced, controllerName, doc)
29
+ puts "#{controllerName} contains show"
30
+ doc << " /#{nameSliced}/:id\n"
31
+ end
32
+ end # end class
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan Miller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-04 00:00:00.000000000 Z
11
+ date: 2015-08-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  A gem with which to generate YAML from a Rails app. Currently
@@ -20,7 +20,8 @@ extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
22
  - bin/swag
23
- - lib/swag.rb
23
+ - lib/Swag.rb
24
+ - lib/SwagHelper.rb
24
25
  homepage: http://rubygems.org/gems/swag
25
26
  licenses:
26
27
  - ''
data/lib/swag.rb DELETED
@@ -1,79 +0,0 @@
1
- class Swag
2
- def initialize
3
- end
4
- def self.hi
5
- puts "Swag, world."
6
- end
7
-
8
- # verifies rails directory
9
- def self.check
10
- puts "Checking your directory: #{Dir.pwd}"
11
- if File.exist?("bin/rails")
12
- puts "Rails App detected. Proceeding."
13
- else
14
- puts "You must be in a Rails root directory for Swag to work. Aborting."
15
- abort
16
- end
17
- end
18
-
19
- # checks that app/controllers can be read
20
- def self.checkControllers
21
- puts "Checking controllers."
22
- begin
23
- Dir.foreach("app/controllers") do |c|
24
- puts "Found #{c}"
25
- end
26
- rescue => ex
27
- puts "Error while reading controllers."
28
- puts ex.inspect
29
- puts ex.backtrace
30
- end
31
- end
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
64
- def self.writePaths
65
- puts "Writing paths."
66
- begin
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
77
- end
78
- end
79
- end