lx_docs 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/lx_docs/railtie.rb +55 -0
- data/lib/lx_docs/use_case.rb +82 -0
- data/lib/lx_docs/version.rb +3 -0
- data/lib/lx_docs.rb +5 -0
- data/lx_docs.gemspec +28 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7d1894d79732ca28d38fe2447923d6273bdbf0a7c38b72629fae2c996036e2d0
|
4
|
+
data.tar.gz: 74bdca2fba40b9b34bd6445b6d9972ae3c4efad194003157728eb1e9902d9d55
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 49fd12044815f6c13a2134598ec93c76c2a75d7f5af466fbb3865296d55966ca05792748b4c9c2f403646e6f9fd0d3d91e1f5d282db31f5a9c1f2f9d1d17a3a2
|
7
|
+
data.tar.gz: 2b1159ad7c4cdd06da8bbab74b8d93897461eb81599dc5ae5b3e414de9afbd0e41da9c04fe653ebebf0edbd19b2303a7f64bade13e4b9507fa29cef68ea3254f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
lx_docs (0.1.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.7.0)
|
12
|
+
rspec-core (~> 3.7.0)
|
13
|
+
rspec-expectations (~> 3.7.0)
|
14
|
+
rspec-mocks (~> 3.7.0)
|
15
|
+
rspec-core (3.7.1)
|
16
|
+
rspec-support (~> 3.7.0)
|
17
|
+
rspec-expectations (3.7.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.7.0)
|
20
|
+
rspec-mocks (3.7.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.7.0)
|
23
|
+
rspec-support (3.7.1)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.16)
|
30
|
+
lx_docs!
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.0)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Alex Clink
|
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,37 @@
|
|
1
|
+
# LxDocs
|
2
|
+
|
3
|
+
Generate automatic documentation for rails
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'lx_docs'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install lx_docs
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
`rake lx_docs:generate`
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
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.
|
28
|
+
|
29
|
+
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).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sleepinginsomniac/lx_docs.
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
The gem is available as open source under the terms of the [MIT License](https://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 "lx_docs"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module LxDocs
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
|
4
|
+
rake_tasks do
|
5
|
+
namespace :lx_docs do
|
6
|
+
desc "Generate"
|
7
|
+
task :generate => :environment do
|
8
|
+
|
9
|
+
versions = {}
|
10
|
+
|
11
|
+
routes = Rails.application.routes.routes.map do |route|
|
12
|
+
next unless route.defaults[:controller]
|
13
|
+
controller_path = route.defaults[:controller] + '_controller'
|
14
|
+
controller_class = controller_path.classify.constantize
|
15
|
+
controller_file_path = Rails.root.join('app', 'controllers', controller_path + '.rb').to_s
|
16
|
+
|
17
|
+
next unless File.exists?(controller_file_path)
|
18
|
+
|
19
|
+
defined_in = controller_class.to_s.split('::').tap{ |a| a.pop }.join('/').downcase
|
20
|
+
defined_in = 'root' if defined_in.blank?
|
21
|
+
|
22
|
+
versions[defined_in] ||= { controllers: {} }
|
23
|
+
controllers = versions[defined_in][:controllers]
|
24
|
+
|
25
|
+
action_name = route.defaults[:action].to_sym
|
26
|
+
action_method = controller_class.instance_method(action_name)
|
27
|
+
|
28
|
+
controllers[controller_path] ||= {
|
29
|
+
controller: controller_path.classify,
|
30
|
+
source_location: {
|
31
|
+
file: controller_file_path[Rails.root.to_s.length..-1]
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
controllers[controller_path][:actions] ||= {}
|
36
|
+
controllers[controller_path][:actions][action_name] ||= { paths: [], verbs: [], formats: [] }
|
37
|
+
controllers[controller_path][:actions][action_name][:paths].push(route.path.spec.to_s).uniq!
|
38
|
+
controllers[controller_path][:actions][action_name][:verbs].push(route.verb).uniq!
|
39
|
+
controllers[controller_path][:actions][action_name][:formats].push(route.defaults[:format]).uniq!
|
40
|
+
|
41
|
+
action_file, action_file_line = action_method.source_location
|
42
|
+
|
43
|
+
controllers[controller_path][:actions][action_name][:source_location] ||= {
|
44
|
+
file: action_file[Rails.root.to_s.length..-1],
|
45
|
+
line: action_file_line
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
puts JSON.pretty_generate(versions)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module LxDocs
|
4
|
+
class UseCase
|
5
|
+
def self.defined
|
6
|
+
@use_cases ||= {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.add(title, version, *args, &block)
|
10
|
+
self.defined[version] ||= {}
|
11
|
+
self.defined[version][title] = new(title, version, *args).tap do |use_case|
|
12
|
+
use_case.instance_eval(&block)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :info
|
17
|
+
|
18
|
+
def initialize(title, version, controller = nil, action = nil)
|
19
|
+
@version = version
|
20
|
+
@controller = controller
|
21
|
+
@action = action
|
22
|
+
@info = {
|
23
|
+
title: title,
|
24
|
+
description: '',
|
25
|
+
parameters: {},
|
26
|
+
responses: [],
|
27
|
+
examples: [],
|
28
|
+
includes: []
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def description(value)
|
33
|
+
@info[:description] = value
|
34
|
+
end
|
35
|
+
|
36
|
+
def parameter(name, **opts)
|
37
|
+
@info[:parameters][name.to_sym] = opts
|
38
|
+
end
|
39
|
+
|
40
|
+
def example(value)
|
41
|
+
@info[:examples] << value
|
42
|
+
end
|
43
|
+
|
44
|
+
def response(code, body = nil, description = nil)
|
45
|
+
@info[:responses] << {
|
46
|
+
code: code,
|
47
|
+
body: body,
|
48
|
+
description: description
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def includes(other)
|
53
|
+
@info[:includes] << other
|
54
|
+
other = LxDocs::UseCase.defined[@version][other]
|
55
|
+
@info[:parameters].merge!(other.info[:parameters])
|
56
|
+
@info[:responses] |= other.info[:responses]
|
57
|
+
@info[:examples] |= other.info[:examples]
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_json(*args)
|
61
|
+
@info.to_json(*args)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# LxDocs::UseCase.add('pagination', 'Api::V1') do
|
67
|
+
# parameter :page, type: 'integer', default: 1
|
68
|
+
# parameter :limit, type: 'integer', default: 10
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
# LxDocs::UseCase.add('listing shoes', 'Api::V1', 'Shoes', :index) do
|
72
|
+
# description "Get an index of shoes"
|
73
|
+
#
|
74
|
+
# example "api/v1/shoes?page=1&limit=10"
|
75
|
+
#
|
76
|
+
# response 200
|
77
|
+
# response 403, { error: 'Forbidden' }.to_json, "When the user is not logged in"
|
78
|
+
#
|
79
|
+
# includes 'pagination'
|
80
|
+
# end
|
81
|
+
#
|
82
|
+
# puts JSON.pretty_generate(LxDocs::UseCase.defined)
|
data/lib/lx_docs.rb
ADDED
data/lx_docs.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "lx_docs/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "lx_docs"
|
8
|
+
spec.version = LxDocs::VERSION
|
9
|
+
spec.authors = ["Alex Clink"]
|
10
|
+
spec.email = ["code@alexclink.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{TODO: Write a short summary, because RubyGems requires one.}
|
13
|
+
spec.summary = "Generate docs for your rails api"
|
14
|
+
spec.description = "Automatically gathers your routes into a machine readable json file and provides a DSL for docs"
|
15
|
+
spec.homepage = "https://pixelfaucet.com/software/rails_api_docs"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.bindir = "bin"
|
22
|
+
spec.executables = []
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lx_docs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Clink
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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
|
+
description: Automatically gathers your routes into a machine readable json file and
|
56
|
+
provides a DSL for docs
|
57
|
+
email:
|
58
|
+
- code@alexclink.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- lib/lx_docs.rb
|
74
|
+
- lib/lx_docs/railtie.rb
|
75
|
+
- lib/lx_docs/use_case.rb
|
76
|
+
- lib/lx_docs/version.rb
|
77
|
+
- lx_docs.gemspec
|
78
|
+
homepage: https://pixelfaucet.com/software/rails_api_docs
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.7.6
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Generate docs for your rails api
|
102
|
+
test_files: []
|