Method: YARD::CodeObjects::MacroObject.find_or_create

Defined in:
lib/yard/code_objects/macro_object.rb

.find_or_create(data, method_object = nil) ⇒ MacroObject? Also known as: create_docstring

Parses a given docstring and determines if the macro is “new” or not. If the macro has $variable names or if it has a @macro tag with the [new] or [attached] flag, it is considered new.

If a new macro is found, the macro is created and registered. Otherwise the macro name is searched and returned. If a macro is not found, nil is returned.

Parameters:

  • method_object (CodeObjects::Base) (defaults to: nil)

    an optional method to attach the macro to. Only used if the macro is being created, otherwise this argument is ignored.

Returns:

  • (MacroObject)

    the newly created or existing macro, depending on whether the @macro tag was a new tag or not.

  • (nil)

    if the data has no macro tag or if the macro is not new and no macro by the macro name is found.



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/yard/code_objects/macro_object.rb', line 66

def find_or_create(data, method_object = nil)
  docstring = Docstring === data ? data : Docstring.new(data)
  return unless docstring.tag(:macro)
  return unless name = macro_name(docstring)
  if new_macro?(docstring)
    method_object = nil unless attached_macro?(docstring, method_object)
    create(name, macro_data(docstring), method_object)
  else
    find(name)
  end
end