lib/yard/code_objects/macro_object.rb in yard-0.9.5 vs lib/yard/code_objects/macro_object.rb in yard-0.9.6

- old
+ new

@@ -1,5 +1,6 @@ +# frozen_string_literal: true require 'ostruct' module YARD module CodeObjects # A MacroObject represents a docstring defined through +@!macro NAME+ and can be @@ -66,15 +67,11 @@ # @return [MacroObject] the newly created or existing macro, depending # on whether the @!macro tag was a new tag or not. # @return [nil] if the +data+ has no macro tag or if the macro is # not new and no macro by the macro name is found. def find_or_create(macro_name, data, method_object = nil) - if macro = find(name) - macro - else - create(macro_name, data, method_object) - end + find(name) || create(macro_name, data, method_object) end alias create_docstring find_or_create # Expands +macro_data+ using the interpolation parameters. # @@ -91,14 +88,17 @@ # interpolated as \$* # @param [String] block_source Currently unused. Will support # interpolating the block data as a variable. # @return [String] the expanded macro data # @param [String] macro_data the macro data to expand (taken from {#macro_data}) - def expand(macro_data, call_params = [], full_source = '', block_source = '') + def expand(macro_data, call_params = [], full_source = '', block_source = '') # rubocop:disable Lint/UnusedMethodArgument macro_data = macro_data.all if macro_data.is_a?(Docstring) macro_data.gsub(MACRO_MATCH) do - escape, first, last, rng = $1, $2 || $5, $4, $3 ? true : false + escape = $1 + first = $2 || $5 + last = $4 + rng = $3 ? true : false next $&[1..-1] if escape if first == '*' last ? $& : full_source else first_i = first.to_i @@ -115,11 +115,11 @@ # on the new macro object. # # @param [Docstring] docstring the docstring to create a macro out of # @!macro macro.expand # @see find_or_create - def apply(docstring, call_params = [], full_source = '', block_source = '', method_object = nil) + def apply(docstring, call_params = [], full_source = '', block_source = '', _method_object = nil) # rubocop:disable Lint/UnusedMethodArgument docstring = docstring.all if Docstring === docstring parser = Docstring.parser handler = OpenStruct.new handler.call_params = call_params[1..-1] handler.caller_method = call_params.first @@ -131,11 +131,11 @@ # docstring and appending any extra local docstring data that was in # the original +docstring+ object. # # @param [MacroObject] macro the macro object # @!macro macro.expand - def apply_macro(macro, docstring, call_params = [], full_source = '', block_source = '') + def apply_macro(macro, docstring, call_params = [], full_source = '', block_source = '') # rubocop:disable Lint/UnusedMethodArgument apply(docstring, call_params, full_source, block_source) end end # @return [String] the macro data stored on the object @@ -167,6 +167,6 @@ def expand(call_params = [], full_source = '', block_source = '') self.class.expand(macro_data, call_params, full_source, block_source) end end end -end \ No newline at end of file +end