lib/yard/handlers/base.rb in yard-0.9.5 vs lib/yard/handlers/base.rb in yard-0.9.6

- old
+ new

@@ -1,5 +1,6 @@ +# frozen_string_literal: true module YARD module Handlers # Raise this error when a handler should exit before completing. # The exception will be silenced, allowing the next handler(s) in the # queue to be executed. @@ -187,11 +188,11 @@ # (match from the beginning of the line), and all # token matches match only the first token of the # statement. # def handles(*matches) - (@handlers ||= []).push(*matches) + (@handlers ||= []).concat(matches) end # This class is implemented by {Ruby::Base} and {Ruby::Legacy::Base}. # To implement a base handler class for another language, implement # this method to return true if the handler should process the given @@ -199,11 +200,11 @@ # for the handler class. # # @param statement a statement object or node (depends on language type) # @return [Boolean] whether or not this handler object should process # the given statement - def handles?(statement) + def handles?(statement) # rubocop:disable Lint/UnusedMethodArgument raise NotImplementedError, "override #handles? in a subclass" end # @return [Array] a list of matchers for the handler object. # @see handles? @@ -220,11 +221,11 @@ end # @return [Boolean] whether the handler should only be processed inside # a namespace. def namespace_only? - (@namespace_only ||= false) ? true : false + @namespace_only ||= false end # Declares that a handler should only be called when inside a filename # by its basename or a regex match for the full path. # @@ -298,11 +299,11 @@ end # Parses the semantic "block" contained in the statement node. # # @abstract Subclasses should call {Processor#process parser.process} - def parse_block(*args) + def parse_block(*) raise NotImplementedError, "#{self} did not implement a #parse_block method for handling" end # @return [Processor] the processor object that manages all global state # during handling. @@ -334,17 +335,17 @@ undef owner, owner=, namespace, namespace= undef visibility, visibility=, scope, scope= undef globals, extra_state def owner; parser.owner end - def owner=(v) parser.owner=(v) end + def owner=(v) parser.owner = v end def namespace; parser.namespace end - def namespace=(v); parser.namespace=(v) end + def namespace=(v); parser.namespace = v end def visibility; parser.visibility end - def visibility=(v); parser.visibility=(v) end + def visibility=(v); parser.visibility = v end def scope; parser.scope end - def scope=(v); parser.scope=(v) end + def scope=(v); parser.scope = v end def globals; parser.globals end def extra_state; parser.extra_state end # Aborts a handler by raising {Handlers::HandlerAborted}. # An exception will only be logged in debugging mode for @@ -356,28 +357,30 @@ end # Executes a given block with specific state values for {#owner}, # {#namespace} and {#scope}. # - # @param [Proc] block the block to execute with specific state # @option opts [CodeObjects::NamespaceObject] :namespace (value of #namespace) # the namespace object that {#namespace} will be equal to for the # duration of the block. # @option opts [Symbol] :scope (:instance) # the scope for the duration of the block. # @option opts [CodeObjects::Base] :owner (value of #owner) # the owner object (method) for the duration of the block # @yield a block to execute with the given state values. - def push_state(opts = {}, &block) + def push_state(opts = {}) opts = { :namespace => namespace, :scope => :instance, :owner => owner || namespace, :visibility => nil }.update(opts) - ns, vis, sc, oo = namespace, visibility, scope, owner + ns = namespace + vis = visibility + sc = scope + oo = owner self.namespace = opts[:namespace] self.visibility = opts[:visibility] || :public self.scope = opts[:scope] self.owner = opts[:owner] @@ -422,15 +425,14 @@ # # @param [CodeObjects::Base] object the object to register # @return [void] # @since 0.8.0 def register_ensure_loaded(object) - begin - ensure_loaded!(object.namespace) - object.namespace.children << object - rescue NamespaceMissingError - end + ensure_loaded!(object.namespace) + object.namespace.children << object + rescue NamespaceMissingError + nil # noop end # Registers the file/line of the declaration with the object # # @param [CodeObjects::Base] object the object to register @@ -521,11 +523,11 @@ def register_module_function(object) return unless object.is_a?(MethodObject) return unless object.module_function? modobj = MethodObject.new(object.namespace, object.name) object.copy_to(modobj) - modobj.visibility = :private + modobj.visibility = :private # rubocop:disable Lint/UselessSetterCall end # Registers the object as dynamic if the object is defined inside # a method or block (owner != namespace) # @@ -560,15 +562,12 @@ return if object.root? return object unless object.is_a?(Proxy) retries = 0 while object.is_a?(Proxy) - if retries <= max_retries - log.debug "Missing object #{object} in file `#{parser.file}', moving it to the back of the line." - parser.parse_remaining_files - else - raise NamespaceMissingError, object - end + raise NamespaceMissingError, object if retries > max_retries + log.debug "Missing object #{object} in file `#{parser.file}', moving it to the back of the line." + parser.parse_remaining_files retries += 1 end object end