lib/yard/cli/yardoc.rb in yard-0.8.0 vs lib/yard/cli/yardoc.rb in yard-0.8.1

- old
+ new

@@ -181,10 +181,15 @@ # Keep track of which visibilities are to be shown # @return [Array<Symbol>] a list of visibilities # @since 0.5.6 attr_accessor :visibilities + # Keep track of which APIs are to be shown + # @return [Array<String>] a list of APIs + # @since 0.8.1 + attr_accessor :apis + # @return [Array<Symbol>] a list of tags to hide from templates # @since 0.6.0 attr_accessor :hidden_tags # @return [Boolean] whether to print statistics after parsing @@ -203,10 +208,11 @@ def initialize super @options = YardocOptions.new @options.reset_defaults @visibilities = [:public] + @apis = [] @assets = {} @excluded = [] @files = [] @hidden_tags = [] @use_cache = false @@ -285,10 +291,11 @@ options.readme ||= CodeObjects::ExtraFileObject.new(readme) if readme options.files.unshift(options.readme).uniq! if options.readme Tags::Library.visible_tags -= hidden_tags add_visibility_verifier + add_api_verifier # US-ASCII is invalid encoding for onefile if defined?(::Encoding) && options.onefile if ::Encoding.default_internal == ::Encoding::US_ASCII log.warn "--one-file is not compatible with US-ASCII encoding, using ASCII-8BIT" @@ -462,14 +469,25 @@ # Adds verifier rule for visibilities # @return [void] # @since 0.5.6 def add_visibility_verifier - vis_expr = "object.type != :method || #{visibilities.uniq.inspect}.include?(object.visibility)" + vis_expr = "#{visibilities.uniq.inspect}.include?(object.visibility)" options.verifier.add_expressions(vis_expr) end + # Adds verifier rule for APIs + # @return [void] + # @since 0.8.1 + def add_api_verifier + return if apis.empty? + no_api = true if apis.delete('') + expr = "#{apis.uniq.inspect}.include?(@api.text)" + expr += " || !@api" if no_api + options.verifier.add_expressions(expr) + end + # (see Templates::Helpers::BaseHelper#run_verifier) def run_verifier(list) options.verifier ? options.verifier.run(list) : list end @@ -594,9 +612,17 @@ end opts.on('--no-private', "Hide objects with @private tag") do options.verifier.add_expressions '!object.tag(:private) && (object.namespace.is_a?(CodeObjects::Proxy) || !object.namespace.tag(:private))' + end + + opts.on('--[no-]api API', 'Generates documentation for a given API', + '(objects which define the correct @api tag).', + 'If --no-api is given, displays objects with', + 'no @api tag.') do |api| + api = '' if api == false + apis.push(api) end opts.on('--embed-mixins', "Embeds mixin methods into class documentation") do options.embed_mixins << '*' end