yard-api 1.0.1 → 1.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/lib/yard-api/options.rb +1 -0
- data/lib/yard-api/verifier.rb +3 -2
- data/lib/yard-api/version.rb +1 -1
- data/spec/fulldoc_spec.rb +0 -20
- data/spec/spec_helper.rb +26 -1
- data/spec/tags/internal_spec.rb +66 -0
- data/templates/api/fulldoc/html/setup.rb +1 -1
- data/templates/api/fulldoc/json/setup.rb +2 -8
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f9ac4cbeffaa2de7978493a2dee567b2961429daf4c44e36d88f799939b3951
|
4
|
+
data.tar.gz: d163d480697d3b23b479baec1087594d54f229813fd60de1b9f995146471b90f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5874aed23062b569f0703382f9fc50149322cf3c67a22123d68c8bcbfe1c46f42ea2760797e79551d4a89fc4d63246a8e72bbed00c002b7aee03c4ef5ca6993
|
7
|
+
data.tar.gz: d58e05d26f0a95c937c3deab4a985e4e7b2cc2bd5ec5153cee9385a29a1548dad1ea01d529e24c7862d86841ef8388c20bc833067345de47d7c46625567e19f8
|
data/lib/yard-api/options.rb
CHANGED
data/lib/yard-api/verifier.rb
CHANGED
@@ -22,13 +22,14 @@ module YARD
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def relevant_object?(object)
|
25
|
+
doc_include_internal = !!YARD::APIPlugin.options[:include_internal]
|
25
26
|
case object.type
|
26
27
|
when :root, :module, :constant
|
27
28
|
false
|
28
29
|
when :api
|
29
30
|
true
|
30
31
|
when :method
|
31
|
-
return false if object.has_tag?(:internal) || !object.has_tag?(:API)
|
32
|
+
return false if object.has_tag?(:internal) && !doc_include_internal || !object.has_tag?(:API)
|
32
33
|
routes = @routes[object.object_id]
|
33
34
|
routes ||= begin
|
34
35
|
@routes[object.object_id] = YARD::Templates::Helpers::RouteHelper.routes_for_yard_object(object)
|
@@ -43,7 +44,7 @@ module YARD
|
|
43
44
|
|
44
45
|
routes.any?
|
45
46
|
when :class
|
46
|
-
return false if object.has_tag?(:internal) || !object.has_tag?(:API)
|
47
|
+
return false if object.has_tag?(:internal) && !doc_include_internal || !object.has_tag?(:API)
|
47
48
|
true
|
48
49
|
else
|
49
50
|
object.parent.nil? && relevant_object?(object.parent)
|
data/lib/yard-api/version.rb
CHANGED
data/spec/fulldoc_spec.rb
CHANGED
@@ -1,25 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
module YARD
|
4
|
-
module Serializers
|
5
|
-
# A serializer that writes data to standard output.
|
6
|
-
class SpecSerializer < Base
|
7
|
-
# Creates a serializer to print text to stdout
|
8
|
-
#
|
9
|
-
# @param [Fixnum, nil] wrap if wrap is a number, wraps text to +wrap+
|
10
|
-
# columns, otherwise no wrapping is done.
|
11
|
-
def initialize(buffer)
|
12
|
-
@buffer = buffer
|
13
|
-
end
|
14
|
-
|
15
|
-
# Overrides serialize behaviour to write data to standard output
|
16
|
-
def serialize(object, data)
|
17
|
-
@buffer << data
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
3
|
describe YARD::Templates::Engine.template(:api, :fulldoc) do
|
24
4
|
before do
|
25
5
|
Registry.clear
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'pry'
|
3
|
+
|
1
4
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
5
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
6
|
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
@@ -15,7 +18,6 @@
|
|
15
18
|
#
|
16
19
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
20
|
RSpec.configure do |config|
|
18
|
-
|
19
21
|
require File.join(File.dirname(__FILE__), '..', 'lib', 'yard-api')
|
20
22
|
|
21
23
|
# rspec-expectations config goes here. You can use an alternate
|
@@ -123,3 +125,26 @@ RSpec.configure do |config|
|
|
123
125
|
YARD.parse_string str if str
|
124
126
|
end
|
125
127
|
end
|
128
|
+
|
129
|
+
|
130
|
+
module YARD
|
131
|
+
module Serializers
|
132
|
+
# A serializer that writes data to standard output.
|
133
|
+
class SpecSerializer < Base
|
134
|
+
attr_writer :basepath
|
135
|
+
|
136
|
+
# Creates a serializer to print text to stdout
|
137
|
+
#
|
138
|
+
# @param [Fixnum, nil] wrap if wrap is a number, wraps text to +wrap+
|
139
|
+
# columns, otherwise no wrapping is done.
|
140
|
+
def initialize(buffer)
|
141
|
+
@buffer = buffer
|
142
|
+
end
|
143
|
+
|
144
|
+
# Overrides serialize behaviour to write data to standard output
|
145
|
+
def serialize(object, data)
|
146
|
+
@buffer << data
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe YARD::Templates::Engine.template(:api, :fulldoc) do
|
4
|
+
before(:each) do
|
5
|
+
YARD::Registry.clear
|
6
|
+
end
|
7
|
+
|
8
|
+
after(:each) do
|
9
|
+
YARD::Registry.clear
|
10
|
+
end
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
populate <<-'eof'
|
14
|
+
# @API Quizzes
|
15
|
+
# @internal
|
16
|
+
class QuizzesController < ApplicationController
|
17
|
+
end
|
18
|
+
eof
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:serializer) { YARD::Serializers::SpecSerializer.new([]) }
|
22
|
+
let(:verifier) { YARD::APIPlugin::Verifier.new }
|
23
|
+
|
24
|
+
it 'should hide entities marked with @internal' do
|
25
|
+
entities = YARD::Registry.all
|
26
|
+
|
27
|
+
YARD::Templates::Engine.render({
|
28
|
+
objects: entities,
|
29
|
+
type: :fulldoc,
|
30
|
+
template: :api,
|
31
|
+
format: :json,
|
32
|
+
serializer: serializer
|
33
|
+
})
|
34
|
+
|
35
|
+
expect(entities.size).to be > 0
|
36
|
+
expect(verifier.run(entities).size).to be == 0
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when the "include_internal" option is turned on...' do
|
40
|
+
before(:each) do
|
41
|
+
set_option(:include_internal, true)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should not hide entities marked with @internal' do
|
45
|
+
populate <<-'eof'
|
46
|
+
# @API Quizzes
|
47
|
+
# @internal
|
48
|
+
class QuizzesController < ApplicationController
|
49
|
+
end
|
50
|
+
eof
|
51
|
+
|
52
|
+
entities = YARD::Registry.all
|
53
|
+
|
54
|
+
YARD::Templates::Engine.render({
|
55
|
+
objects: entities,
|
56
|
+
type: :fulldoc,
|
57
|
+
template: :api,
|
58
|
+
format: :json,
|
59
|
+
serializer: serializer
|
60
|
+
})
|
61
|
+
|
62
|
+
expect(entities.size).to be > 0
|
63
|
+
expect(verifier.run(entities).size).to eq(entities.size)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -7,7 +7,7 @@ include YARD::Templates::Helpers::FilterHelper
|
|
7
7
|
def init
|
8
8
|
logger.info "YARD-API: starting."
|
9
9
|
|
10
|
-
options.serializer
|
10
|
+
options.serializer ||= YARD::APIPlugin::Serializer.new
|
11
11
|
options.serializer.basepath = api_options.output
|
12
12
|
|
13
13
|
options[:resources] = options.objects.
|
@@ -129,15 +129,9 @@ def get_route(object)
|
|
129
129
|
route = routes.first
|
130
130
|
|
131
131
|
if route.present?
|
132
|
-
verb = if route.verb.source =~ /\^?(\w*)\$/
|
133
|
-
$1.upcase
|
134
|
-
else
|
135
|
-
route.verb.source
|
136
|
-
end
|
137
|
-
|
138
132
|
{
|
139
|
-
path:
|
140
|
-
verb:
|
133
|
+
path: RouteHelper.get_route_path(route),
|
134
|
+
verb: RouteHelper.get_route_verb(route)
|
141
135
|
}
|
142
136
|
end
|
143
137
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yard-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ahmad Amireh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- spec/helpers/html_helper_spec.rb
|
83
83
|
- spec/spec_helper.rb
|
84
84
|
- spec/tags/argument_spec.rb
|
85
|
+
- spec/tags/internal_spec.rb
|
85
86
|
- tasks/yard_api.rake
|
86
87
|
- templates/api/appendix/html/setup.rb
|
87
88
|
- templates/api/appendix/json/setup.rb
|
@@ -206,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
207
|
version: '0'
|
207
208
|
requirements: []
|
208
209
|
rubyforge_project:
|
209
|
-
rubygems_version: 2.7.6
|
210
|
+
rubygems_version: 2.7.6.2
|
210
211
|
signing_key:
|
211
212
|
specification_version: 4
|
212
213
|
summary: A YARD plugin for documenting APIs in Rails projects.
|