rspec-api-docs 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rspec_api_docs/after.rb +1 -1
- data/lib/rspec_api_docs/after/type_checker.rb +1 -1
- data/lib/rspec_api_docs/formatter.rb +11 -8
- data/lib/rspec_api_docs/formatter/resource.rb +13 -4
- data/lib/rspec_api_docs/formatter/resource/example.rb +5 -3
- data/lib/rspec_api_docs/resource_collection.rb +25 -0
- data/lib/rspec_api_docs/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 921c43cbac7e32c779901db4a5519ad6b5fefbc0
|
4
|
+
data.tar.gz: 68cb6ae49fbf805cb4786ef8494a9466693ea143
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97c817ca345c1a021d701fea14a7881ff58f6b57f283ae413067287ff0b0dc7ebc46b9e8fd08761c79f84437b9a4e071b4a02a5f4154178740df3d064fec50ca
|
7
|
+
data.tar.gz: f3ce3df2074ed3032314b78d2c1ec6cdd27f8fccbf31cee4431f98032662bfba8b693cdd8408496de1b3e155e7b082bdbc85de4750e5cdaae66ab63e80fec004
|
data/lib/rspec_api_docs/after.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rspec/core/formatters/base_formatter'
|
2
2
|
|
3
3
|
require 'rspec_api_docs'
|
4
|
+
require 'rspec_api_docs/resource_collection'
|
4
5
|
require 'rspec_api_docs/formatter/resource'
|
5
6
|
require 'rspec_api_docs/formatter/renderer/json_renderer'
|
6
7
|
require 'rspec_api_docs/formatter/renderer/raddocs_renderer'
|
@@ -18,10 +19,10 @@ module RspecApiDocs
|
|
18
19
|
class Formatter < RSpec::Core::Formatters::BaseFormatter
|
19
20
|
RSpec::Core::Formatters.register self, :example_passed, :close
|
20
21
|
|
21
|
-
attr_reader :
|
22
|
+
attr_reader :renderer
|
22
23
|
|
23
|
-
def initialize(*args)
|
24
|
-
@
|
24
|
+
def initialize(*args, renderer: default_renderer)
|
25
|
+
@renderer = renderer
|
25
26
|
super args
|
26
27
|
end
|
27
28
|
|
@@ -31,21 +32,23 @@ module RspecApiDocs
|
|
31
32
|
def example_passed(example_notification)
|
32
33
|
rspec_example = example_notification.example
|
33
34
|
return unless rspec_example.metadata[METADATA_NAMESPACE]
|
34
|
-
|
35
|
-
resources[resource.name] ||= resource
|
36
|
-
resources[resource.name].add_example Resource::Example.new(rspec_example)
|
35
|
+
resource_collection.add_example(rspec_example)
|
37
36
|
end
|
38
37
|
|
39
38
|
# Calls the configured renderer with the stored {Resource}s.
|
40
39
|
#
|
41
40
|
# @return [void]
|
42
41
|
def close(null_notification)
|
43
|
-
renderer.new(
|
42
|
+
renderer.new(resource_collection.all).render
|
44
43
|
end
|
45
44
|
|
46
45
|
private
|
47
46
|
|
48
|
-
def
|
47
|
+
def resource_collection
|
48
|
+
@resource_collection ||= ResourceCollection.new
|
49
|
+
end
|
50
|
+
|
51
|
+
def default_renderer
|
49
52
|
value = RspecApiDocs.configuration.renderer
|
50
53
|
|
51
54
|
case value
|
@@ -4,6 +4,8 @@ require 'rspec_api_docs/formatter/resource/response_field'
|
|
4
4
|
|
5
5
|
module RspecApiDocs
|
6
6
|
class Resource
|
7
|
+
MAX_PRECEDENCE = 9_999
|
8
|
+
|
7
9
|
attr_reader :rspec_example
|
8
10
|
|
9
11
|
def initialize(rspec_example)
|
@@ -17,7 +19,7 @@ module RspecApiDocs
|
|
17
19
|
#
|
18
20
|
# @return [String]
|
19
21
|
def name
|
20
|
-
metadata.fetch(:resource_name
|
22
|
+
metadata.fetch(:resource_name) { rspec_example.metadata[:example_group][:description] }
|
21
23
|
end
|
22
24
|
|
23
25
|
# The description of the resource.
|
@@ -33,7 +35,7 @@ module RspecApiDocs
|
|
33
35
|
#
|
34
36
|
# @return [Array<Example>]
|
35
37
|
def examples
|
36
|
-
@examples.sort_by { |example| [example.precedence, example.name]
|
38
|
+
@examples.sort_by { |example| [example.precedence, example.name] }
|
37
39
|
end
|
38
40
|
|
39
41
|
# Add an example
|
@@ -43,9 +45,16 @@ module RspecApiDocs
|
|
43
45
|
@examples << example
|
44
46
|
end
|
45
47
|
|
46
|
-
# @return [
|
48
|
+
# @return [Integer]
|
47
49
|
def precedence
|
48
|
-
metadata
|
50
|
+
@precedence ||= metadata.fetch(:resource_precedence, MAX_PRECEDENCE)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Set the resource precedence
|
54
|
+
#
|
55
|
+
# @return [void]
|
56
|
+
def precedence=(value)
|
57
|
+
@precedence = value
|
49
58
|
end
|
50
59
|
|
51
60
|
def inspect
|
@@ -4,6 +4,8 @@ require 'rspec_api_docs/formatter/resource/example/deep_hash_set'
|
|
4
4
|
module RspecApiDocs
|
5
5
|
class Resource
|
6
6
|
class Example
|
7
|
+
MAX_PRECEDENCE = 9_999
|
8
|
+
|
7
9
|
attr_reader :example
|
8
10
|
|
9
11
|
def initialize(example)
|
@@ -90,13 +92,13 @@ module RspecApiDocs
|
|
90
92
|
metadata.fetch(:note, {})
|
91
93
|
end
|
92
94
|
|
93
|
-
# @return [
|
95
|
+
# @return [Integer]
|
94
96
|
def precedence
|
95
|
-
metadata
|
97
|
+
metadata.fetch(:example_precedence, MAX_PRECEDENCE)
|
96
98
|
end
|
97
99
|
|
98
100
|
def inspect
|
99
|
-
"#<RspecApiDocs::Resource::Example #{name.inspect}>"
|
101
|
+
"#<RspecApiDocs::Resource::Example #{name.inspect}, precedence: #{precedence.inspect}>"
|
100
102
|
end
|
101
103
|
|
102
104
|
private
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RspecApiDocs
|
2
|
+
class ResourceCollection
|
3
|
+
def initialize(resources = {})
|
4
|
+
@resources = resources
|
5
|
+
end
|
6
|
+
|
7
|
+
def all
|
8
|
+
@resources.values.sort_by { |resource| [resource.precedence, resource.name] }
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_example(rspec_example)
|
12
|
+
resource = Resource.new(rspec_example)
|
13
|
+
|
14
|
+
existing_resource = @resources[resource.name]
|
15
|
+
if existing_resource
|
16
|
+
existing_resource.precedence = [existing_resource.precedence, resource.precedence].min
|
17
|
+
resource = existing_resource
|
18
|
+
else
|
19
|
+
@resources[resource.name] = resource
|
20
|
+
end
|
21
|
+
|
22
|
+
resource.add_example Resource::Example.new(rspec_example)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-api-docs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Odin Dutton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -154,6 +154,7 @@ files:
|
|
154
154
|
- lib/rspec_api_docs/formatter/resource/parameter.rb
|
155
155
|
- lib/rspec_api_docs/formatter/resource/response_field.rb
|
156
156
|
- lib/rspec_api_docs/rake_task.rb
|
157
|
+
- lib/rspec_api_docs/resource_collection.rb
|
157
158
|
- lib/rspec_api_docs/version.rb
|
158
159
|
- rspec-api-docs.gemspec
|
159
160
|
homepage: https://github.com/twe4ked
|