class Brainstem::ApiDocs::Formatters::OpenApiSpecification::Version2::TagsFormatter
Attributes
controllers[RW]
ignore_tagging[RW]
output[RW]
Public Class Methods
new(controllers, options = {})
click to toggle source
Calls superclass method
Brainstem::ApiDocs::Formatters::AbstractFormatter::new
# File lib/brainstem/api_docs/formatters/open_api_specification/version_2/tags_formatter.rb, line 26 def initialize(controllers, options = {}) self.output = ActiveSupport::HashWithIndifferentAccess.new self.controllers = controllers self.ignore_tagging = false super options end
Public Instance Methods
call()
click to toggle source
# File lib/brainstem/api_docs/formatters/open_api_specification/version_2/tags_formatter.rb, line 34 def call return {} if ignore_tagging || controllers.blank? format_tags! format_tag_groups! output end
valid_options()
click to toggle source
Declares the options that are permissable to set on this instance.
Calls superclass method
Brainstem::Concerns::Optional#valid_options
# File lib/brainstem/api_docs/formatters/open_api_specification/version_2/tags_formatter.rb, line 15 def valid_options super | [ :controllers, :ignore_tagging ] end
Private Instance Methods
documentable_controllers()
click to toggle source
Override #
# File lib/brainstem/api_docs/formatters/open_api_specification/version_2/tags_formatter.rb, line 60 def documentable_controllers @documentable_controllers ||= controllers. select { |controller| !controller.nodoc? && controller.endpoints.only_documentable.any? } end
format_tag_data(controller)
click to toggle source
Returns formatted tag object for a given controller.
# File lib/brainstem/api_docs/formatters/open_api_specification/version_2/tags_formatter.rb, line 109 def format_tag_data(controller) { name: tag_name(controller), description: format_sentence(controller.description), }.reject { |_, v| v.blank? } end
format_tag_groups()
click to toggle source
# File lib/brainstem/api_docs/formatters/open_api_specification/version_2/tags_formatter.rb, line 77 def format_tag_groups groups = Hash.new.tap do |result| documentable_controllers.each do |controller| controller_tag = tag_name(controller) controller_tag_groups = tag_groups(controller).presence || [controller_tag] controller_tag_groups.each do |tag_group_name| result[tag_group_name] ||= [] result[tag_group_name] << controller_tag end end end groups.keys.sort.map do |tag_group_name| { name: tag_group_name, tags: groups[tag_group_name].sort }.with_indifferent_access end end
format_tag_groups!()
click to toggle source
# File lib/brainstem/api_docs/formatters/open_api_specification/version_2/tags_formatter.rb, line 50 def format_tag_groups! return unless tag_groups_specified?(documentable_controllers) output.merge!( 'x-tagGroups' => format_tag_groups ) end
tag_groups(controller)
click to toggle source
# File lib/brainstem/api_docs/formatters/open_api_specification/version_2/tags_formatter.rb, line 102 def tag_groups(controller) controller.tag_groups.presence end
tag_groups_specified?(controllers)
click to toggle source
# File lib/brainstem/api_docs/formatters/open_api_specification/version_2/tags_formatter.rb, line 71 def tag_groups_specified?(controllers) documentable_controllers.any? { |controller| controller.tag_groups.present? } end
tag_name(controller)
click to toggle source
# File lib/brainstem/api_docs/formatters/open_api_specification/version_2/tags_formatter.rb, line 98 def tag_name(controller) controller.tag.presence || format_tag_name(controller.name) end