restwoods 0.0.1
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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +16 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/LICENSE.txt +21 -0
- data/README.md +206 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/restwoods.rb +9 -0
- data/lib/restwoods/file_parser.rb +115 -0
- data/lib/restwoods/line_parser.rb +109 -0
- data/lib/restwoods/version.rb +3 -0
- data/restwoods.gemspec +43 -0
- metadata +215 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ed23f0e542281459c429e01d9c0e16d5bc731484
|
4
|
+
data.tar.gz: 581843d3b25f1ac7537c7ae4405145f45889ad66
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1b2041d7ac3f750e669c8487b94fb3d63d343741e8ca1df766b00fe60adaccb777a1b3820e445e48e79d511f5693dab7095a18ea1cde35947bde215e1f715a12
|
7
|
+
data.tar.gz: 726ba9174f826c6b4a35bccc65168db2d6ca4bae6c31a5f1fd01df07a06f6107a0b492a78ec160141cc4a8655a8f078dba080fd7ff8ed27ae0503da9e1125ee0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 2.3.1
|
5
|
+
- 2.4.0
|
6
|
+
before_install: gem install bundler -v 1.12.5
|
7
|
+
script: bundle exec rspec spec
|
8
|
+
notifications:
|
9
|
+
email:
|
10
|
+
recipients:
|
11
|
+
- wootaw@gmail.com
|
12
|
+
on_failure: change
|
13
|
+
on_success: never
|
14
|
+
addons:
|
15
|
+
code_climate:
|
16
|
+
repo_token: fb779cb868a2fd4ecb41df8db0e57472f977682ca9ac7e85ac63e9bdd79a0032
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at wootaw@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 wootaw
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
# Restwoods
|
2
|
+
|
3
|
+
[](https://travis-ci.org/wootaw/restwoods)
|
4
|
+
[](http://badge.fury.io/rb/restwoods)
|
5
|
+
[](https://codeclimate.com/github/wootaw/restwoods)
|
6
|
+
[](https://codeclimate.com/github/wootaw/restwoods/coverage)
|
7
|
+
|
8
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/restwoods`. To experiment with that code, run `bin/console` for an interactive prompt.
|
9
|
+
|
10
|
+
TODO: Delete this and the text above, and describe your gem
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'restwoods'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install restwoods
|
27
|
+
|
28
|
+
## Basic Usage
|
29
|
+
|
30
|
+
RESTWoods is a tool for generating RESTful web API documentation by analyzing block comments. Below is a simple example showing some of the more common features of RESTWoods in documenting parts of the Twitter API that created by Grape.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
module Twitter
|
34
|
+
|
35
|
+
=begin
|
36
|
+
@doc (twitter) Twitter
|
37
|
+
This row is a description of this document.
|
38
|
+
Detail: <=#
|
39
|
+
This is document of number one.
|
40
|
+
It do not anything. Just to at here. <=#
|
41
|
+
This is the second paragraph of this document description.
|
42
|
+
It do not anything, too.
|
43
|
+
=end
|
44
|
+
class API < Grape::API
|
45
|
+
version 'v1'
|
46
|
+
format :json
|
47
|
+
prefix :api
|
48
|
+
|
49
|
+
resource :statuses do
|
50
|
+
=begin
|
51
|
+
@res get /api/v1/statuses/public_timeline Return a public timeline
|
52
|
+
|
53
|
+
@res_return {Object[]} data Status List
|
54
|
+
@res_return {String} data.id Status ID
|
55
|
+
@res_return {String} data.status Your status
|
56
|
+
=end
|
57
|
+
get :public_timeline do
|
58
|
+
end
|
59
|
+
|
60
|
+
=begin
|
61
|
+
@res get /api/v1/statuses/home_timeline Return a personal timeline
|
62
|
+
@res_error (401) msg 401 Unauthorized
|
63
|
+
|
64
|
+
@res_return {Object[]} data Status List
|
65
|
+
@res_return {String} data.id Status ID
|
66
|
+
@res_return {String} data.status Your status
|
67
|
+
=end
|
68
|
+
get :home_timeline do
|
69
|
+
end
|
70
|
+
|
71
|
+
=begin
|
72
|
+
@res get /api/v1/statuses/:id Return a status
|
73
|
+
@res_param {Number} id Status id
|
74
|
+
|
75
|
+
@res_return {String} id Status ID
|
76
|
+
@res_return {String} status Your status
|
77
|
+
|
78
|
+
@res_state deprecated
|
79
|
+
=end
|
80
|
+
route_param :id do
|
81
|
+
get do
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
=begin
|
86
|
+
@res post /api/v1/statuses Create a status
|
87
|
+
@res_param {String} status Your status
|
88
|
+
@res_error (401) msg 401 Unauthorized
|
89
|
+
=end
|
90
|
+
post do
|
91
|
+
end
|
92
|
+
|
93
|
+
=begin
|
94
|
+
@res put /api/v1/statuses/:id Update a status
|
95
|
+
@res_param {String} id Status ID
|
96
|
+
@res_param {String} status Your status
|
97
|
+
@res_error (401) msg 401 Unauthorized
|
98
|
+
=end
|
99
|
+
put ':id' do
|
100
|
+
end
|
101
|
+
|
102
|
+
=begin
|
103
|
+
@res delete /api/v1/statuses/:id Delete a status
|
104
|
+
@res_param {String} id Status ID
|
105
|
+
@res_error (401) msg 401 Unauthorized
|
106
|
+
@res_state coming This resource will be coming soon
|
107
|
+
=end
|
108
|
+
delete ':id' do
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
```
|
114
|
+
|
115
|
+
## Supported Programming Languages
|
116
|
+
|
117
|
+
- Java, JavaScript, C#, Go, Dart, PHP, Scala (all DocStyle capable languages):
|
118
|
+
```c
|
119
|
+
/**
|
120
|
+
* @doc (twitter) Twitter
|
121
|
+
*/
|
122
|
+
```
|
123
|
+
|
124
|
+
- ruby
|
125
|
+
```ruby
|
126
|
+
=begin
|
127
|
+
@doc (twitter) Twitter
|
128
|
+
=end
|
129
|
+
```
|
130
|
+
|
131
|
+
- perl
|
132
|
+
```perl
|
133
|
+
#**
|
134
|
+
# @doc (twitter) Twitter
|
135
|
+
#*
|
136
|
+
```
|
137
|
+
|
138
|
+
- python
|
139
|
+
```python
|
140
|
+
"""
|
141
|
+
@doc (twitter) Twitter
|
142
|
+
"""
|
143
|
+
```
|
144
|
+
|
145
|
+
- elixir
|
146
|
+
```elixir
|
147
|
+
@restwoods """
|
148
|
+
@doc (twitter) Twitter
|
149
|
+
"""
|
150
|
+
```
|
151
|
+
|
152
|
+
- coffee
|
153
|
+
```coffee
|
154
|
+
###
|
155
|
+
@doc (twitter) Twitter
|
156
|
+
###
|
157
|
+
```
|
158
|
+
|
159
|
+
- lua
|
160
|
+
```lua
|
161
|
+
--[[
|
162
|
+
@doc (twitter) Twitter
|
163
|
+
]]
|
164
|
+
```
|
165
|
+
|
166
|
+
- erlang
|
167
|
+
```erlang
|
168
|
+
%{
|
169
|
+
% @doc (twitter) Twitter
|
170
|
+
%}
|
171
|
+
```
|
172
|
+
|
173
|
+
## Commands
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
### @doc
|
178
|
+
|
179
|
+
| Year | Temperature (low) | Temperature (high) |
|
180
|
+
| ---- | ----------------- | -------------------|
|
181
|
+
| 1900 | -10 | 25 |
|
182
|
+
| 1910 | -15 | 30 |
|
183
|
+
| 1920 | -10 | 32 |
|
184
|
+
|
185
|
+
### @res
|
186
|
+
|
187
|
+
### @doc_state and @res_state
|
188
|
+
|
189
|
+
### @res_param @res_header @res_return @res_error
|
190
|
+
|
191
|
+
## Descriptions
|
192
|
+
|
193
|
+
## Development
|
194
|
+
|
195
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
196
|
+
|
197
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
198
|
+
|
199
|
+
## Contributing
|
200
|
+
|
201
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/wootaw/restwoods. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
202
|
+
|
203
|
+
|
204
|
+
## License
|
205
|
+
|
206
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "restwoods"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/restwoods.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
module Restwoods
|
2
|
+
class FileParser
|
3
|
+
|
4
|
+
LANGUAGES = {
|
5
|
+
java: [['/**', '*/'], /\A\.(js|jsx|c|cs|java|php?|ts|cpp|go|scala|dart)\Z/],
|
6
|
+
ruby: [['=begin', '=end'], /\A\.(rb)\Z/],
|
7
|
+
perl: [['#**', '#*'], /\A\.(perl|pl|pm)\Z/],
|
8
|
+
python: [['"""', '"""'], /\A\.(py)\Z/],
|
9
|
+
elixir: [['@restwoods """', '"""'], /\A\.(ex|exs?)\Z/],
|
10
|
+
erlang: [['%{', '%}'], /\A\.(erl)\Z/],
|
11
|
+
coffee: [['###', '###'], /\A\.(coffee)\Z/],
|
12
|
+
lua: [['--[[', ']]'], /\A\.(lua)\Z/]
|
13
|
+
}
|
14
|
+
MARKDOWNS = /\A\s*(#+|>|\-\s*|\d+\.|`{3})/
|
15
|
+
|
16
|
+
attr_reader :document_name
|
17
|
+
|
18
|
+
def initialize(filename)
|
19
|
+
@name = filename
|
20
|
+
@type = File.ftype(filename)
|
21
|
+
@ext = File.extname(@name)
|
22
|
+
@document_name = File.basename(filename, @ext)
|
23
|
+
end
|
24
|
+
|
25
|
+
def lang
|
26
|
+
@flang ||= check_lang
|
27
|
+
end
|
28
|
+
|
29
|
+
def results
|
30
|
+
@results ||= parse
|
31
|
+
end
|
32
|
+
|
33
|
+
def parse
|
34
|
+
@results = []
|
35
|
+
File.open(@name, "r") do |f|
|
36
|
+
started = false
|
37
|
+
f.each_line do |s|
|
38
|
+
if s.strip == LANGUAGES[lang][0][0]
|
39
|
+
started = true
|
40
|
+
@source = false
|
41
|
+
next
|
42
|
+
end
|
43
|
+
|
44
|
+
started = false if started && s.strip == LANGUAGES[lang][0][1]
|
45
|
+
process_line(s) if started
|
46
|
+
end
|
47
|
+
end if @type == "file" && !lang.nil?
|
48
|
+
@results
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
def process_line(str)
|
54
|
+
line_parser = Restwoods::LineParser.new(str, lang)
|
55
|
+
hash = line_parser.parse
|
56
|
+
if hash[:type] == :joint
|
57
|
+
return if @recent_command.nil?
|
58
|
+
process_descriptions(branch(@recent_command), hash)
|
59
|
+
else
|
60
|
+
branch(hash, true).merge!(hash[:data])
|
61
|
+
@recent_command = hash.select { |k| k != :data }
|
62
|
+
@recent_command[:space] = line_parser.indentation
|
63
|
+
@linebreak = false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def branch(command, initial=false)
|
68
|
+
@results << {} if initial && (@results.length == 0 || command[:type] == :doc && command[:part] == :main)
|
69
|
+
item = @results.last
|
70
|
+
|
71
|
+
if command[:type] == :res
|
72
|
+
if initial
|
73
|
+
item[:resources] = [] unless item.has_key?(:resources)
|
74
|
+
item[:resources] << {} if command[:part] == :main
|
75
|
+
end
|
76
|
+
item = item[:resources].last
|
77
|
+
end
|
78
|
+
|
79
|
+
case command[:part]
|
80
|
+
when :state
|
81
|
+
item[:state] = {} if initial && !item.has_key?(:state)
|
82
|
+
item = item[:state]
|
83
|
+
when /\A(param|header|return|error|bind)\Z/
|
84
|
+
part = "#{command[:part]}s".to_sym
|
85
|
+
if initial
|
86
|
+
item[part] = [] unless item.has_key?(part)
|
87
|
+
item[part] << {}
|
88
|
+
end
|
89
|
+
item = item[part].last
|
90
|
+
end
|
91
|
+
item
|
92
|
+
end
|
93
|
+
|
94
|
+
def process_descriptions(item, hash)
|
95
|
+
text = hash[:text].to_s.gsub(/\A\s{,#{@recent_command[:space] + 2}}/, '').rstrip
|
96
|
+
if text.length == 0
|
97
|
+
@linebreak = true
|
98
|
+
return
|
99
|
+
end
|
100
|
+
markdown = MARKDOWNS === text || @source
|
101
|
+
@source ^= /\A\s*`{3}/ === text if markdown
|
102
|
+
|
103
|
+
item[:descriptions] = [[]] unless item.has_key?(:descriptions)
|
104
|
+
item[:descriptions] << [] if @linebreak || markdown
|
105
|
+
item[:descriptions].last << text
|
106
|
+
@linebreak = markdown
|
107
|
+
end
|
108
|
+
|
109
|
+
def check_lang
|
110
|
+
LANGUAGES.each { |l, options| return l if options[1] === @ext }
|
111
|
+
nil
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
module Restwoods
|
2
|
+
class LineParser
|
3
|
+
|
4
|
+
PICKS = { java: /\A\s*\*/, erlang: /\A\s*%/, perl: /\A\s*#/ }
|
5
|
+
COMMANDS = /\A@(doc(\_state)?|res(\_(param|header|return|error|state|bind))?|cmd\_(def|use))\Z/
|
6
|
+
|
7
|
+
def initialize(str, clazz)
|
8
|
+
@clazz = clazz
|
9
|
+
pick = PICKS[clazz]
|
10
|
+
@str = pick.nil? ? str : str.gsub(pick, '')
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse
|
14
|
+
parts = @str.strip.split(/\s+/)
|
15
|
+
command = parts[0].to_s.match(COMMANDS)
|
16
|
+
if command.nil? || command[1].nil?
|
17
|
+
{ type: :joint, text: @str }
|
18
|
+
else
|
19
|
+
send(command[1], parts[1..-1], command)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def indentation
|
24
|
+
@indentation ||= @str.match(/\A\s*/)[0].length
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
def cmd(args, cmd)
|
30
|
+
{ type: :cmd, part: cmd[1].split("_")[1].to_sym, data: { name: args[0] } }
|
31
|
+
end
|
32
|
+
|
33
|
+
def doc(args, _cmd)
|
34
|
+
{ type: :doc, part: :main, data: {} }.tap do |result|
|
35
|
+
m = args[0].match(/\((\w+)\)/)
|
36
|
+
result[:data][:summary] = args[[m].compact.length..-1].join(" ")
|
37
|
+
result[:data][:name] = m[1] unless m.nil?
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def res(args, _cmd)
|
42
|
+
{
|
43
|
+
type: :res,
|
44
|
+
part: :main,
|
45
|
+
data: { method: args[0], route: args[1], summary: args[2..-1].join(" ") }
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def res_bind(args, _cmd)
|
50
|
+
{ type: :res, part: :bind, data: {} }.tap do |result|
|
51
|
+
m = args[0].match(/\((param|header|return|error)\)/)
|
52
|
+
result[:data][:scope] = m[1] unless m.nil?
|
53
|
+
result[:data][:command] = args[[m].compact.length]
|
54
|
+
result[:data][:vars] = args[([m].compact.length + 1)..-1]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def state(args, cmd)
|
59
|
+
{
|
60
|
+
type: cmd[1].split("_")[0].to_sym,
|
61
|
+
part: :state,
|
62
|
+
data: { name: args[0], summary: args[1..-1].join(" ") }
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
def analyze_arguments(args)
|
67
|
+
{ group: args[0].to_s.match(/\((\w+)\)/) }.tap do |r|
|
68
|
+
r[:type] = (r[:group].nil? ? args[0] : args[1]).to_s.match(/\{(.+)\}/)
|
69
|
+
r[:names] = args[[r[:group], r[:type]].compact.length].to_s
|
70
|
+
r[:name] = r[:names].match(/\A\[(.+)\]\Z/)
|
71
|
+
r[:default] = (r[:name].nil? ? r[:names] : r[:name][1]).split("=")
|
72
|
+
r[:parent] = r[:default][0].split(".")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def res_io(args, cmd)
|
77
|
+
{ type: :res, part: cmd[4].to_sym, data: {} }.tap do |result|
|
78
|
+
r = analyze_arguments(args)
|
79
|
+
unless r[:type].nil?
|
80
|
+
options = r[:type][1].split("=")
|
81
|
+
array = options[0].match(/(\w+)(\[\])?\Z/)
|
82
|
+
|
83
|
+
result[:data][:options] = options[1].split(",") if options.length == 2
|
84
|
+
unless array.nil?
|
85
|
+
result[:data][:array] = !array[2].nil?
|
86
|
+
result[:data][:type] = array[1]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
result[:data][:group] = r[:group][1] unless r[:group].nil?
|
90
|
+
result[:data][:required] = r[:name].nil?
|
91
|
+
result[:data][:default] = r[:default][1] if r[:default].length == 2
|
92
|
+
result[:data][:parent] = r[:parent][0..-2] if r[:parent].length > 1
|
93
|
+
result[:data][:name] = r[:parent].length == 1 ? r[:default][0] : r[:parent][-1]
|
94
|
+
result[:data][:summary] = args[([r[:group], r[:type]].compact.length + 1)..-1].join(' ')
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
alias_method :res_param, :res_io
|
99
|
+
alias_method :res_header, :res_io
|
100
|
+
alias_method :res_return, :res_io
|
101
|
+
alias_method :res_error, :res_io
|
102
|
+
|
103
|
+
alias_method :doc_state, :state
|
104
|
+
alias_method :res_state, :state
|
105
|
+
|
106
|
+
alias_method :cmd_def, :cmd
|
107
|
+
alias_method :cmd_use, :cmd
|
108
|
+
end
|
109
|
+
end
|
data/restwoods.gemspec
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'restwoods/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "restwoods"
|
8
|
+
spec.version = Restwoods::VERSION
|
9
|
+
spec.authors = ["wootaw"]
|
10
|
+
spec.email = ["wootaw@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "This gem generate RESTful web API documentation."
|
13
|
+
spec.description = "RESTWoods is a tool for generating RESTful web API documentation by analyzing block comments."
|
14
|
+
spec.homepage = "https://github.com/wootaw/restwoods"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = ""
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
# spec.post_install_message = "Thanks for installing!"
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
35
|
+
spec.add_development_dependency "rspec-nc", '~> 0'
|
36
|
+
spec.add_development_dependency "awesome_print", '~> 1.7'
|
37
|
+
spec.add_development_dependency "guard", '~> 2'
|
38
|
+
spec.add_development_dependency "guard-rspec", '~> 4'
|
39
|
+
spec.add_development_dependency "pry", '~> 0'
|
40
|
+
spec.add_development_dependency "pry-remote", '~> 0'
|
41
|
+
spec.add_development_dependency "pry-nav", '~> 0'
|
42
|
+
spec.add_development_dependency "codeclimate-test-reporter", '~> 0.4.8'
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,215 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: restwoods
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- wootaw
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-nc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: awesome_print
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.7'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '4'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '4'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry-remote
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: pry-nav
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: codeclimate-test-reporter
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 0.4.8
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 0.4.8
|
167
|
+
description: RESTWoods is a tool for generating RESTful web API documentation by analyzing
|
168
|
+
block comments.
|
169
|
+
email:
|
170
|
+
- wootaw@gmail.com
|
171
|
+
executables: []
|
172
|
+
extensions: []
|
173
|
+
extra_rdoc_files: []
|
174
|
+
files:
|
175
|
+
- ".gitignore"
|
176
|
+
- ".rspec"
|
177
|
+
- ".travis.yml"
|
178
|
+
- CODE_OF_CONDUCT.md
|
179
|
+
- Gemfile
|
180
|
+
- Guardfile
|
181
|
+
- LICENSE.txt
|
182
|
+
- README.md
|
183
|
+
- Rakefile
|
184
|
+
- bin/console
|
185
|
+
- bin/setup
|
186
|
+
- lib/restwoods.rb
|
187
|
+
- lib/restwoods/file_parser.rb
|
188
|
+
- lib/restwoods/line_parser.rb
|
189
|
+
- lib/restwoods/version.rb
|
190
|
+
- restwoods.gemspec
|
191
|
+
homepage: https://github.com/wootaw/restwoods
|
192
|
+
licenses:
|
193
|
+
- MIT
|
194
|
+
metadata: {}
|
195
|
+
post_install_message:
|
196
|
+
rdoc_options: []
|
197
|
+
require_paths:
|
198
|
+
- lib
|
199
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
200
|
+
requirements:
|
201
|
+
- - ">="
|
202
|
+
- !ruby/object:Gem::Version
|
203
|
+
version: '0'
|
204
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
requirements: []
|
210
|
+
rubyforge_project:
|
211
|
+
rubygems_version: 2.5.1
|
212
|
+
signing_key:
|
213
|
+
specification_version: 4
|
214
|
+
summary: This gem generate RESTful web API documentation.
|
215
|
+
test_files: []
|