brainstem 1.4.1 → 2.0.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/CHANGELOG.md +77 -0
- data/README.md +119 -0
- data/docs/api_doc_generator.markdown +45 -4
- data/docs/brainstem_executable.markdown +1 -1
- data/docs/oas_2_docgen.png +0 -0
- data/docs/oas_2_docgen_ascii.txt +78 -0
- data/lib/brainstem/api_docs.rb +23 -9
- data/lib/brainstem/api_docs/abstract_collection.rb +0 -13
- data/lib/brainstem/api_docs/atlas.rb +0 -14
- data/lib/brainstem/api_docs/builder.rb +0 -14
- data/lib/brainstem/api_docs/controller.rb +7 -16
- data/lib/brainstem/api_docs/controller_collection.rb +0 -3
- data/lib/brainstem/api_docs/endpoint.rb +73 -19
- data/lib/brainstem/api_docs/endpoint_collection.rb +0 -7
- data/lib/brainstem/api_docs/formatters/abstract_formatter.rb +0 -2
- data/lib/brainstem/api_docs/formatters/markdown/controller_formatter.rb +1 -9
- data/lib/brainstem/api_docs/formatters/markdown/endpoint_collection_formatter.rb +1 -9
- data/lib/brainstem/api_docs/formatters/markdown/endpoint_formatter.rb +39 -24
- data/lib/brainstem/api_docs/formatters/markdown/helper.rb +0 -13
- data/lib/brainstem/api_docs/formatters/markdown/presenter_formatter.rb +22 -35
- data/lib/brainstem/api_docs/formatters/open_api_specification/helper.rb +66 -0
- data/lib/brainstem/api_docs/formatters/open_api_specification/version_2/controller_formatter.rb +57 -0
- data/lib/brainstem/api_docs/formatters/open_api_specification/version_2/endpoint/param_definitions_formatter.rb +311 -0
- data/lib/brainstem/api_docs/formatters/open_api_specification/version_2/endpoint/response_definitions_formatter.rb +197 -0
- data/lib/brainstem/api_docs/formatters/open_api_specification/version_2/endpoint_collection_formatter.rb +60 -0
- data/lib/brainstem/api_docs/formatters/open_api_specification/version_2/endpoint_formatter.rb +162 -0
- data/lib/brainstem/api_docs/formatters/open_api_specification/version_2/info_formatter.rb +126 -0
- data/lib/brainstem/api_docs/formatters/open_api_specification/version_2/presenter_formatter.rb +132 -0
- data/lib/brainstem/api_docs/formatters/open_api_specification/version_2/security_definitions_formatter.rb +99 -0
- data/lib/brainstem/api_docs/formatters/open_api_specification/version_2/tags_formatter.rb +123 -0
- data/lib/brainstem/api_docs/introspectors/abstract_introspector.rb +0 -7
- data/lib/brainstem/api_docs/introspectors/rails_introspector.rb +1 -20
- data/lib/brainstem/api_docs/presenter.rb +21 -27
- data/lib/brainstem/api_docs/presenter_collection.rb +1 -11
- data/lib/brainstem/api_docs/resolver.rb +1 -8
- data/lib/brainstem/api_docs/sinks/abstract_sink.rb +0 -4
- data/lib/brainstem/api_docs/sinks/controller_presenter_multifile_sink.rb +0 -9
- data/lib/brainstem/api_docs/sinks/open_api_specification_sink.rb +234 -0
- data/lib/brainstem/api_docs/sinks/stdout_sink.rb +0 -5
- data/lib/brainstem/cli.rb +0 -13
- data/lib/brainstem/cli/abstract_command.rb +0 -7
- data/lib/brainstem/cli/generate_api_docs_command.rb +48 -24
- data/lib/brainstem/concerns/controller_dsl.rb +288 -145
- data/lib/brainstem/concerns/formattable.rb +0 -5
- data/lib/brainstem/concerns/optional.rb +0 -1
- data/lib/brainstem/concerns/presenter_dsl.rb +2 -21
- data/lib/brainstem/dsl/configuration.rb +0 -11
- data/lib/brainstem/presenter.rb +0 -4
- data/lib/brainstem/version.rb +1 -1
- data/spec/brainstem/api_docs/abstract_collection_spec.rb +0 -11
- data/spec/brainstem/api_docs/atlas_spec.rb +0 -6
- data/spec/brainstem/api_docs/builder_spec.rb +0 -4
- data/spec/brainstem/api_docs/controller_collection_spec.rb +0 -2
- data/spec/brainstem/api_docs/controller_spec.rb +29 -18
- data/spec/brainstem/api_docs/endpoint_collection_spec.rb +0 -6
- data/spec/brainstem/api_docs/endpoint_spec.rb +343 -13
- data/spec/brainstem/api_docs/formatters/abstract_formatter_spec.rb +0 -2
- data/spec/brainstem/api_docs/formatters/markdown/controller_formatter_spec.rb +0 -1
- data/spec/brainstem/api_docs/formatters/markdown/endpoint_collection_formatter_spec.rb +0 -5
- data/spec/brainstem/api_docs/formatters/markdown/endpoint_formatter_spec.rb +94 -8
- data/spec/brainstem/api_docs/formatters/markdown/helper_spec.rb +0 -8
- data/spec/brainstem/api_docs/formatters/markdown/presenter_formatter_spec.rb +0 -7
- data/spec/brainstem/api_docs/formatters/open_api_specification/helper_spec.rb +210 -0
- data/spec/brainstem/api_docs/formatters/open_api_specification/version_2/controller_formatter_spec.rb +81 -0
- data/spec/brainstem/api_docs/formatters/open_api_specification/version_2/endpoint/param_definitions_formatter_spec.rb +672 -0
- data/spec/brainstem/api_docs/formatters/open_api_specification/version_2/endpoint/response_definitions_formatter_spec.rb +335 -0
- data/spec/brainstem/api_docs/formatters/open_api_specification/version_2/endpoint_collection_formatter_spec.rb +59 -0
- data/spec/brainstem/api_docs/formatters/open_api_specification/version_2/endpoint_formatter_spec.rb +308 -0
- data/spec/brainstem/api_docs/formatters/open_api_specification/version_2/info_formatter_spec.rb +89 -0
- data/spec/brainstem/api_docs/formatters/open_api_specification/version_2/presenter_formatter_spec.rb +430 -0
- data/spec/brainstem/api_docs/formatters/open_api_specification/version_2/security_definitions_formatter_spec.rb +190 -0
- data/spec/brainstem/api_docs/formatters/open_api_specification/version_2/tags_formatter_spec.rb +217 -0
- data/spec/brainstem/api_docs/introspectors/abstract_introspector_spec.rb +0 -2
- data/spec/brainstem/api_docs/introspectors/rails_introspector_spec.rb +0 -2
- data/spec/brainstem/api_docs/presenter_collection_spec.rb +0 -2
- data/spec/brainstem/api_docs/presenter_spec.rb +58 -18
- data/spec/brainstem/api_docs/resolver_spec.rb +0 -1
- data/spec/brainstem/api_docs/sinks/controller_presenter_multifile_sink_spec.rb +0 -2
- data/spec/brainstem/api_docs/sinks/open_api_specification_sink_spec.rb +371 -0
- data/spec/brainstem/api_docs_spec.rb +2 -0
- data/spec/brainstem/cli/abstract_command_spec.rb +0 -4
- data/spec/brainstem/cli/generate_api_docs_command_spec.rb +53 -2
- data/spec/brainstem/concerns/controller_dsl_spec.rb +430 -64
- data/spec/brainstem/concerns/presenter_dsl_spec.rb +0 -20
- data/spec/brainstem/preloader_spec.rb +0 -7
- data/spec/brainstem/presenter_spec.rb +0 -1
- data/spec/dummy/rails.rb +0 -1
- data/spec/spec_helpers/db.rb +0 -1
- metadata +37 -2
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
require 'brainstem/api_docs/formatters/abstract_formatter'
|
|
2
|
+
|
|
3
|
+
module Brainstem
|
|
4
|
+
module ApiDocs
|
|
5
|
+
module Formatters
|
|
6
|
+
module OpenApiSpecification
|
|
7
|
+
module Version2
|
|
8
|
+
class SecurityDefinitionsFormatter < AbstractFormatter
|
|
9
|
+
|
|
10
|
+
attr_accessor :output
|
|
11
|
+
|
|
12
|
+
def initialize(options = {})
|
|
13
|
+
self.output = ActiveSupport::HashWithIndifferentAccess.new
|
|
14
|
+
|
|
15
|
+
super options
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def call
|
|
19
|
+
format_basic_auth_definitions!
|
|
20
|
+
format_apikey_auth_definitions!
|
|
21
|
+
format_oauth_definitions!
|
|
22
|
+
format_security_object!
|
|
23
|
+
|
|
24
|
+
output
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
#####################################################################
|
|
28
|
+
private
|
|
29
|
+
#####################################################################
|
|
30
|
+
|
|
31
|
+
def format_basic_auth_definitions!
|
|
32
|
+
add_security_definition(basic_auth_definitions)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def format_apikey_auth_definitions!
|
|
36
|
+
add_security_definition(apikey_auth_definitions)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def format_oauth_definitions!
|
|
40
|
+
add_security_definition(oauth_definitions)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def format_security_object!
|
|
44
|
+
return if security_object.blank?
|
|
45
|
+
|
|
46
|
+
output.merge!('security' => security_object)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def add_security_definition(security_definition)
|
|
50
|
+
return if security_definition.blank?
|
|
51
|
+
|
|
52
|
+
output['securityDefinitions'] ||= {}
|
|
53
|
+
output['securityDefinitions'].merge!(security_definition)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
#####################################################################
|
|
57
|
+
# Override with custom values #
|
|
58
|
+
#####################################################################
|
|
59
|
+
|
|
60
|
+
def basic_auth_definitions
|
|
61
|
+
{}
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def apikey_auth_definitions
|
|
65
|
+
{
|
|
66
|
+
'api_key' => {
|
|
67
|
+
'type' => 'apiKey',
|
|
68
|
+
'name' => 'api_key',
|
|
69
|
+
'in' => 'header'
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def oauth_definitions
|
|
75
|
+
{
|
|
76
|
+
'petstore_auth' => {
|
|
77
|
+
'type' => 'oauth2',
|
|
78
|
+
'authorizationUrl' => 'http://petstore.swagger.io/oauth/dialog',
|
|
79
|
+
'flow' => 'implicit',
|
|
80
|
+
'scopes' => {
|
|
81
|
+
'write:pets' => 'modify pets in your account',
|
|
82
|
+
'read:pets' => 'read your pets'
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def security_object
|
|
89
|
+
{}
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
Brainstem::ApiDocs::FORMATTERS[:security][:oas_v2] =
|
|
99
|
+
Brainstem::ApiDocs::Formatters::OpenApiSpecification::Version2::SecurityDefinitionsFormatter.method(:call)
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
require 'brainstem/api_docs/formatters/abstract_formatter'
|
|
2
|
+
require 'brainstem/api_docs/formatters/open_api_specification/helper'
|
|
3
|
+
|
|
4
|
+
module Brainstem
|
|
5
|
+
module ApiDocs
|
|
6
|
+
module Formatters
|
|
7
|
+
module OpenApiSpecification
|
|
8
|
+
module Version2
|
|
9
|
+
class TagsFormatter < AbstractFormatter
|
|
10
|
+
include Helper
|
|
11
|
+
|
|
12
|
+
#
|
|
13
|
+
# Declares the options that are permissable to set on this instance.
|
|
14
|
+
#
|
|
15
|
+
def valid_options
|
|
16
|
+
super | [
|
|
17
|
+
:controllers,
|
|
18
|
+
:ignore_tagging
|
|
19
|
+
]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
attr_accessor :output,
|
|
23
|
+
:controllers,
|
|
24
|
+
:ignore_tagging
|
|
25
|
+
|
|
26
|
+
def initialize(controllers, options = {})
|
|
27
|
+
self.output = ActiveSupport::HashWithIndifferentAccess.new
|
|
28
|
+
self.controllers = controllers
|
|
29
|
+
self.ignore_tagging = false
|
|
30
|
+
|
|
31
|
+
super options
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def call
|
|
35
|
+
return {} if ignore_tagging || controllers.blank?
|
|
36
|
+
|
|
37
|
+
format_tags!
|
|
38
|
+
format_tag_groups!
|
|
39
|
+
output
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
#####################################################################
|
|
43
|
+
private
|
|
44
|
+
#####################################################################
|
|
45
|
+
|
|
46
|
+
def format_tags!
|
|
47
|
+
output.merge!( 'tags' => format_tags_data )
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def format_tag_groups!
|
|
51
|
+
return unless tag_groups_specified?(documentable_controllers)
|
|
52
|
+
|
|
53
|
+
output.merge!( 'x-tagGroups' => format_tag_groups )
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
#####################################################################
|
|
57
|
+
# Override #
|
|
58
|
+
#####################################################################
|
|
59
|
+
|
|
60
|
+
def documentable_controllers
|
|
61
|
+
@documentable_controllers ||= controllers.
|
|
62
|
+
select { |controller| !controller.nodoc? && controller.endpoints.only_documentable.any? }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def format_tags_data
|
|
66
|
+
documentable_controllers
|
|
67
|
+
.map { |controller| format_tag_data(controller) }
|
|
68
|
+
.sort_by { |tag_data| tag_data[:name] }
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def tag_groups_specified?(controllers)
|
|
72
|
+
documentable_controllers.any? { |controller|
|
|
73
|
+
controller.tag_groups.present?
|
|
74
|
+
}
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def format_tag_groups
|
|
78
|
+
groups = Hash.new.tap do |result|
|
|
79
|
+
documentable_controllers.each do |controller|
|
|
80
|
+
controller_tag = tag_name(controller)
|
|
81
|
+
controller_tag_groups = tag_groups(controller).presence || [controller_tag]
|
|
82
|
+
|
|
83
|
+
controller_tag_groups.each do |tag_group_name|
|
|
84
|
+
result[tag_group_name] ||= []
|
|
85
|
+
result[tag_group_name] << controller_tag
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
groups.keys.sort.map do |tag_group_name|
|
|
91
|
+
{
|
|
92
|
+
name: tag_group_name,
|
|
93
|
+
tags: groups[tag_group_name].sort
|
|
94
|
+
}.with_indifferent_access
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def tag_name(controller)
|
|
99
|
+
controller.tag.presence || format_tag_name(controller.name)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def tag_groups(controller)
|
|
103
|
+
controller.tag_groups.presence
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
#
|
|
107
|
+
# Returns formatted tag object for a given controller.
|
|
108
|
+
#
|
|
109
|
+
def format_tag_data(controller)
|
|
110
|
+
{
|
|
111
|
+
name: tag_name(controller),
|
|
112
|
+
description: format_description(controller.description),
|
|
113
|
+
}.reject { |_, v| v.blank? }
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
Brainstem::ApiDocs::FORMATTERS[:tags][:oas_v2] =
|
|
123
|
+
Brainstem::ApiDocs::Formatters::OpenApiSpecification::Version2::TagsFormatter.method(:call)
|
|
@@ -19,7 +19,6 @@ module Brainstem
|
|
|
19
19
|
new(options).tap(&:load_environment!)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
|
|
23
22
|
# Override to return a collection of all controller classes.
|
|
24
23
|
#
|
|
25
24
|
# @return [Array<Class>] all controller classes to document
|
|
@@ -27,7 +26,6 @@ module Brainstem
|
|
|
27
26
|
raise NotImplementedError
|
|
28
27
|
end
|
|
29
28
|
|
|
30
|
-
|
|
31
29
|
# Override to return a collection of all presenter classes.
|
|
32
30
|
#
|
|
33
31
|
# @return [Array<Class>] all presenter classes to document
|
|
@@ -35,7 +33,6 @@ module Brainstem
|
|
|
35
33
|
raise NotImplementedError
|
|
36
34
|
end
|
|
37
35
|
|
|
38
|
-
|
|
39
36
|
# Override to return a collection of hashes with the minimum following
|
|
40
37
|
# keys:
|
|
41
38
|
#
|
|
@@ -48,7 +45,6 @@ module Brainstem
|
|
|
48
45
|
raise NotImplementedError
|
|
49
46
|
end
|
|
50
47
|
|
|
51
|
-
|
|
52
48
|
# Provides both a sanity check to ensure that output confirms to
|
|
53
49
|
# interface and also confirms that there is actually something to
|
|
54
50
|
# generate docs for.
|
|
@@ -58,7 +54,6 @@ module Brainstem
|
|
|
58
54
|
valid_controllers? && valid_presenters? && valid_routes?
|
|
59
55
|
end
|
|
60
56
|
|
|
61
|
-
|
|
62
57
|
#######################################################################
|
|
63
58
|
private
|
|
64
59
|
#######################################################################
|
|
@@ -67,14 +62,12 @@ module Brainstem
|
|
|
67
62
|
# instantiation happens through +with_loaded_environment.
|
|
68
63
|
private_class_method :new
|
|
69
64
|
|
|
70
|
-
|
|
71
65
|
# Loads the host application environment.
|
|
72
66
|
# @api private
|
|
73
67
|
def load_environment!
|
|
74
68
|
raise NotImplementedError
|
|
75
69
|
end
|
|
76
70
|
|
|
77
|
-
|
|
78
71
|
def valid_controllers?
|
|
79
72
|
controllers.is_a?(Array) &&
|
|
80
73
|
controllers.count > 0 &&
|
|
@@ -24,7 +24,6 @@ module Brainstem
|
|
|
24
24
|
"You may have to manually specify an Introspector (#{e.message})."
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
|
|
28
27
|
#
|
|
29
28
|
# Returns a list of presenters that descend from the base presenter
|
|
30
29
|
# class.
|
|
@@ -35,7 +34,6 @@ module Brainstem
|
|
|
35
34
|
base_presenter_class.constantize.descendants
|
|
36
35
|
end
|
|
37
36
|
|
|
38
|
-
|
|
39
37
|
#
|
|
40
38
|
# Returns a list of controllers that descend from the base controller
|
|
41
39
|
# class.
|
|
@@ -46,7 +44,6 @@ module Brainstem
|
|
|
46
44
|
base_controller_class.constantize.descendants
|
|
47
45
|
end
|
|
48
46
|
|
|
49
|
-
|
|
50
47
|
#
|
|
51
48
|
# Returns the alternate application class or defaults to Rails.application
|
|
52
49
|
#
|
|
@@ -56,7 +53,6 @@ module Brainstem
|
|
|
56
53
|
base_application_class.present? ? base_application_class.constantize : ::Rails.application
|
|
57
54
|
end
|
|
58
55
|
|
|
59
|
-
|
|
60
56
|
#
|
|
61
57
|
# Returns an array of hashes describing the endpoints of the
|
|
62
58
|
# application. See +routes_method+ for the keys of those hashes.
|
|
@@ -68,12 +64,10 @@ module Brainstem
|
|
|
68
64
|
routes_method.call
|
|
69
65
|
end
|
|
70
66
|
|
|
71
|
-
|
|
72
67
|
#######################################################################
|
|
73
68
|
private
|
|
74
69
|
#######################################################################
|
|
75
70
|
|
|
76
|
-
|
|
77
71
|
def valid_options
|
|
78
72
|
super | [
|
|
79
73
|
:routes_method,
|
|
@@ -84,7 +78,6 @@ module Brainstem
|
|
|
84
78
|
]
|
|
85
79
|
end
|
|
86
80
|
|
|
87
|
-
|
|
88
81
|
#
|
|
89
82
|
# Used to short-circuit loading if Rails is already loaded, which
|
|
90
83
|
# reduces start-up time substantially.
|
|
@@ -94,7 +87,6 @@ module Brainstem
|
|
|
94
87
|
defined? Rails
|
|
95
88
|
end
|
|
96
89
|
|
|
97
|
-
|
|
98
90
|
# Returns the path of the Rails +config/environment.rb+ file - by
|
|
99
91
|
# default, +#{Dir.pwd}/config/environment.rb+.
|
|
100
92
|
#
|
|
@@ -106,7 +98,6 @@ module Brainstem
|
|
|
106
98
|
)
|
|
107
99
|
end
|
|
108
100
|
|
|
109
|
-
|
|
110
101
|
#
|
|
111
102
|
# Allows a custom location to be set for the environment file if - for
|
|
112
103
|
# example - the command were to be called from a cron task that cannot
|
|
@@ -114,7 +105,6 @@ module Brainstem
|
|
|
114
105
|
#
|
|
115
106
|
attr_writer :rails_environment_file
|
|
116
107
|
|
|
117
|
-
|
|
118
108
|
#
|
|
119
109
|
# Returns the name of the base presenter class.
|
|
120
110
|
#
|
|
@@ -130,7 +120,6 @@ module Brainstem
|
|
|
130
120
|
proc_or_string.respond_to?(:call) ? proc_or_string.call : proc_or_string
|
|
131
121
|
end
|
|
132
122
|
|
|
133
|
-
|
|
134
123
|
#
|
|
135
124
|
# Allows for the specification for an alternate base presenter class
|
|
136
125
|
# if - for example - only documentation of children of +MyBasePresenter+
|
|
@@ -149,7 +138,6 @@ module Brainstem
|
|
|
149
138
|
#
|
|
150
139
|
attr_writer :base_presenter_class
|
|
151
140
|
|
|
152
|
-
|
|
153
141
|
#
|
|
154
142
|
# Returns the name of the base controller class.
|
|
155
143
|
#
|
|
@@ -165,7 +153,6 @@ module Brainstem
|
|
|
165
153
|
proc_or_string.respond_to?(:call) ? proc_or_string.call : proc_or_string
|
|
166
154
|
end
|
|
167
155
|
|
|
168
|
-
|
|
169
156
|
#
|
|
170
157
|
# Allows for the specification for an alternate base controller class
|
|
171
158
|
# if - for example - only documentation of children of ApiController
|
|
@@ -185,7 +172,6 @@ module Brainstem
|
|
|
185
172
|
#
|
|
186
173
|
attr_writer :base_controller_class
|
|
187
174
|
|
|
188
|
-
|
|
189
175
|
#
|
|
190
176
|
# Returns the name of the alternate application or engine to get routes from.
|
|
191
177
|
#
|
|
@@ -200,7 +186,6 @@ module Brainstem
|
|
|
200
186
|
proc_or_string.respond_to?(:call) ? proc_or_string.call : proc_or_string
|
|
201
187
|
end
|
|
202
188
|
|
|
203
|
-
|
|
204
189
|
#
|
|
205
190
|
# Allows for the specification for an alternate base application name
|
|
206
191
|
#
|
|
@@ -208,7 +193,6 @@ module Brainstem
|
|
|
208
193
|
#
|
|
209
194
|
attr_writer :base_application_class
|
|
210
195
|
|
|
211
|
-
|
|
212
196
|
#
|
|
213
197
|
# Returns the proc that is called to format and retrieve routes.
|
|
214
198
|
# The proc's return must be an array of hashes that contains the
|
|
@@ -244,7 +228,6 @@ module Brainstem
|
|
|
244
228
|
end
|
|
245
229
|
end
|
|
246
230
|
|
|
247
|
-
|
|
248
231
|
#
|
|
249
232
|
# Allows setting the routes method used to retrieve the routes if - for
|
|
250
233
|
# example - your application needs to retrieve additional data or if it
|
|
@@ -252,13 +235,11 @@ module Brainstem
|
|
|
252
235
|
#
|
|
253
236
|
attr_writer :routes_method
|
|
254
237
|
|
|
255
|
-
|
|
256
238
|
#
|
|
257
239
|
# Throws an error if the introspector did not produce valid results.
|
|
258
240
|
#
|
|
259
241
|
def validate!
|
|
260
|
-
raise InvalidIntrospectorError, "Introspector is not valid."
|
|
261
|
-
unless valid?
|
|
242
|
+
raise InvalidIntrospectorError, "Introspector is not valid." unless valid?
|
|
262
243
|
end
|
|
263
244
|
end
|
|
264
245
|
end
|
|
@@ -14,7 +14,6 @@ module Brainstem
|
|
|
14
14
|
include Concerns::Optional
|
|
15
15
|
include Concerns::Formattable
|
|
16
16
|
|
|
17
|
-
|
|
18
17
|
def valid_options
|
|
19
18
|
super | [
|
|
20
19
|
:const,
|
|
@@ -37,7 +36,6 @@ module Brainstem
|
|
|
37
36
|
alias_method :document_empty_associations?, :document_empty_associations
|
|
38
37
|
alias_method :document_empty_filters?, :document_empty_filters
|
|
39
38
|
|
|
40
|
-
|
|
41
39
|
def initialize(atlas, options = {})
|
|
42
40
|
self.atlas = atlas
|
|
43
41
|
self.document_empty_associations = Brainstem::ApiDocs.document_empty_presenter_associations
|
|
@@ -47,63 +45,51 @@ module Brainstem
|
|
|
47
45
|
yield self if block_given?
|
|
48
46
|
end
|
|
49
47
|
|
|
50
|
-
|
|
51
48
|
def suggested_filename(format)
|
|
52
49
|
filename_pattern
|
|
53
50
|
.gsub('{{name}}', target_class.to_s.underscore)
|
|
54
51
|
.gsub('{{extension}}', extension)
|
|
55
52
|
end
|
|
56
53
|
|
|
57
|
-
|
|
58
54
|
def suggested_filename_link(format)
|
|
59
55
|
filename_link_pattern
|
|
60
56
|
.gsub('{{name}}', target_class.to_s.underscore)
|
|
61
57
|
.gsub('{{extension}}', extension)
|
|
62
58
|
end
|
|
63
59
|
|
|
64
|
-
|
|
65
60
|
attr_accessor :atlas
|
|
66
61
|
|
|
67
|
-
|
|
68
62
|
def extension
|
|
69
63
|
@extension ||= Brainstem::ApiDocs.output_extension
|
|
70
64
|
end
|
|
71
65
|
|
|
72
|
-
|
|
73
66
|
def filename_pattern
|
|
74
67
|
@filename_pattern ||= Brainstem::ApiDocs.presenter_filename_pattern
|
|
75
68
|
end
|
|
76
69
|
|
|
77
|
-
|
|
78
70
|
def filename_link_pattern
|
|
79
71
|
@filename_link_pattern ||= Brainstem::ApiDocs.presenter_filename_link_pattern
|
|
80
72
|
end
|
|
81
73
|
|
|
82
|
-
|
|
83
74
|
delegate :configuration => :const
|
|
84
75
|
delegate :find_by_class => :atlas
|
|
85
76
|
|
|
86
|
-
|
|
87
77
|
def nodoc?
|
|
88
78
|
configuration[:nodoc]
|
|
89
79
|
end
|
|
90
80
|
|
|
91
|
-
|
|
92
81
|
def title
|
|
93
82
|
contextual_documentation(:title) || const.to_s.demodulize
|
|
94
83
|
end
|
|
95
84
|
|
|
96
|
-
|
|
97
85
|
def brainstem_keys
|
|
98
86
|
const.possible_brainstem_keys.to_a.sort
|
|
99
87
|
end
|
|
100
88
|
|
|
101
|
-
|
|
102
89
|
def description
|
|
103
90
|
contextual_documentation(:description) || ""
|
|
104
91
|
end
|
|
105
92
|
|
|
106
|
-
|
|
107
93
|
def valid_fields(fields = configuration[:fields])
|
|
108
94
|
fields.to_h.reject do |_, field|
|
|
109
95
|
invalid_field?(field) || (nested_field?(field) && valid_fields_in(field).none?)
|
|
@@ -111,16 +97,32 @@ module Brainstem
|
|
|
111
97
|
end
|
|
112
98
|
alias_method :valid_fields_in, :valid_fields
|
|
113
99
|
|
|
114
|
-
|
|
115
100
|
def invalid_field?(field)
|
|
116
101
|
field.options[:nodoc]
|
|
117
102
|
end
|
|
118
103
|
|
|
119
|
-
|
|
120
104
|
def nested_field?(field)
|
|
121
105
|
field.respond_to?(:configuration)
|
|
122
106
|
end
|
|
123
107
|
|
|
108
|
+
def optional_field?(field)
|
|
109
|
+
field.options[:optional]
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def optional_field_names(fields = configuration[:fields], buffer = [])
|
|
113
|
+
fields.to_h.each do |field_name, field_config|
|
|
114
|
+
next if invalid_field?(field_config)
|
|
115
|
+
|
|
116
|
+
if optional_field?(field_config)
|
|
117
|
+
buffer << field_name
|
|
118
|
+
elsif nested_field?(field_config)
|
|
119
|
+
optional_field_names_in(field_config.configuration, buffer)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
buffer
|
|
124
|
+
end
|
|
125
|
+
alias_method :optional_field_names_in, :optional_field_names
|
|
124
126
|
|
|
125
127
|
def valid_filters
|
|
126
128
|
configuration[:filters]
|
|
@@ -128,7 +130,6 @@ module Brainstem
|
|
|
128
130
|
.keep_if(&method(:documentable_filter?))
|
|
129
131
|
end
|
|
130
132
|
|
|
131
|
-
|
|
132
133
|
def documentable_filter?(_, filter)
|
|
133
134
|
!filter[:nodoc] &&
|
|
134
135
|
(
|
|
@@ -137,20 +138,20 @@ module Brainstem
|
|
|
137
138
|
)
|
|
138
139
|
end
|
|
139
140
|
|
|
141
|
+
def searchable?
|
|
142
|
+
configuration[:search].present?
|
|
143
|
+
end
|
|
140
144
|
|
|
141
145
|
def valid_sort_orders
|
|
142
146
|
configuration[:sort_orders].to_h.reject {|k, v| v[:nodoc] }
|
|
143
147
|
end
|
|
144
148
|
|
|
145
|
-
|
|
146
149
|
def valid_associations
|
|
147
150
|
configuration[:associations]
|
|
148
151
|
.to_h
|
|
149
152
|
.keep_if(&method(:documentable_association?))
|
|
150
153
|
end
|
|
151
154
|
|
|
152
|
-
|
|
153
|
-
|
|
154
155
|
def link_for_association(association)
|
|
155
156
|
if (associated_presenter = find_by_class(association.target_class)) &&
|
|
156
157
|
!associated_presenter.nodoc?
|
|
@@ -160,7 +161,6 @@ module Brainstem
|
|
|
160
161
|
end
|
|
161
162
|
end
|
|
162
163
|
|
|
163
|
-
|
|
164
164
|
#
|
|
165
165
|
# Returns whether this association should be documented based on nodoc
|
|
166
166
|
# and empty description.
|
|
@@ -175,27 +175,22 @@ module Brainstem
|
|
|
175
175
|
)
|
|
176
176
|
end
|
|
177
177
|
|
|
178
|
-
|
|
179
178
|
def conditionals
|
|
180
179
|
configuration[:conditionals]
|
|
181
180
|
end
|
|
182
181
|
|
|
183
|
-
|
|
184
182
|
def default_sort_order
|
|
185
183
|
configuration[:default_sort_order] || ""
|
|
186
184
|
end
|
|
187
185
|
|
|
188
|
-
|
|
189
186
|
def default_sort_field
|
|
190
187
|
@default_sort_field ||= (default_sort_order.split(":")[0] || nil)
|
|
191
188
|
end
|
|
192
189
|
|
|
193
|
-
|
|
194
190
|
def default_sort_direction
|
|
195
191
|
@default_sort_direction ||= (default_sort_order.split(":")[1] || nil)
|
|
196
192
|
end
|
|
197
193
|
|
|
198
|
-
|
|
199
194
|
#
|
|
200
195
|
# Returns a key if it exists and is documentable.
|
|
201
196
|
#
|
|
@@ -205,7 +200,6 @@ module Brainstem
|
|
|
205
200
|
configuration[key][:info]
|
|
206
201
|
end
|
|
207
202
|
|
|
208
|
-
|
|
209
203
|
#
|
|
210
204
|
# Returns the relative path between this presenter and another given
|
|
211
205
|
# presenter.
|