Class: ViewComponent::DocsBuilderComponent::MethodDoc

Inherits:
Base
  • Object
show all
Defined in:
lib/view_component/docs_builder_component.rb

Constant Summary

Constants inherited from Base

Base::RESERVED_PARAMETER, Base::ViewContextCalledBeforeRenderError

Constants included from Translatable

Translatable::HTML_SAFE_TRANSLATION_KEY

Constants included from SlotableV2

SlotableV2::RESERVED_NAMES

Instance Attribute Summary

Attributes inherited from Base

#__vc_original_view_context

Instance Method Summary collapse

Methods inherited from Base

_after_compile, _deprecated_generate_mattr_accessor, #_output_postamble, _sidecar_files, #before_render, #before_render_check, collection_counter_parameter, collection_iteration_parameter, collection_parameter, compile, compiled?, compiler, #controller, counter_argument_present?, format, #format, #generate_distinct_locale_files, #generate_locale, #generate_sidecar, #generate_stimulus_controller, #helpers, identifier, inherited, iteration_argument_present?, #perform_render, #render, #render?, #render_in, #render_parent, #render_template_for, #request, short_identifier, type, validate_collection_parameter!, validate_initialization_parameters!, #view_cache_dependencies, #virtual_path, with_collection, with_collection_parameter, #with_variant

Methods included from WithContentHelper

#with_content

Methods included from Translatable

#html_safe_translation, #i18n_scope, #translate

Methods included from SlotableV2

#get_slot, #set_slot

Methods included from ContentAreas

#with

Constructor Details

#initialize(method, section: Section.new(show_types: true)) ⇒ MethodDoc

Returns a new instance of MethodDoc.



13
14
15
16
# File 'lib/view_component/docs_builder_component.rb', line 13

def initialize(method, section: Section.new(show_types: true))
  @method = method
  @section = section
end

Instance Method Details

#callObject



58
59
60
61
62
63
64
# File 'lib/view_component/docs_builder_component.rb', line 58

def call
  <<~DOCS.chomp
    #{separator}#{signature_or_name}#{types}#{suffix}

    #{docstring_and_deprecation_text}
  DOCS
end

#deprecated?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/view_component/docs_builder_component.rb', line 22

def deprecated?
  @method.tag(:deprecated).present?
end

#deprecation_textObject



46
47
48
# File 'lib/view_component/docs_builder_component.rb', line 46

def deprecation_text
  @method.tag(:deprecated)&.text
end

#docstringObject



42
43
44
# File 'lib/view_component/docs_builder_component.rb', line 42

def docstring
  @method.docstring
end

#docstring_and_deprecation_textObject



50
51
52
53
54
55
56
# File 'lib/view_component/docs_builder_component.rb', line 50

def docstring_and_deprecation_text
  <<~DOCS.strip
    #{docstring}

    #{"_#{deprecation_text}_" if deprecated?}
  DOCS
end

#separatorObject



38
39
40
# File 'lib/view_component/docs_builder_component.rb', line 38

def separator
  @method.sep
end

#show_types?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/view_component/docs_builder_component.rb', line 18

def show_types?
  @section.show_types
end

#signature_or_nameObject



34
35
36
# File 'lib/view_component/docs_builder_component.rb', line 34

def signature_or_name
  @method.signature ? @method.signature.gsub("def ", "") : @method.name
end

#suffixObject



26
27
28
# File 'lib/view_component/docs_builder_component.rb', line 26

def suffix
  " (Deprecated)" if deprecated?
end

#typesObject



30
31
32
# File 'lib/view_component/docs_builder_component.rb', line 30

def types
  " → [#{@method.tag(:return).types.join(',')}]" if @method.tag(:return)&.types && show_types?
end