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::VC_INTERNAL_DEFAULT_FORMAT

Constants included from Translatable

Translatable::HTML_SAFE_TRANSLATION_KEY, Translatable::TRANSLATION_EXTENSIONS

Constants included from Slotable

Slotable::RESERVED_NAMES

Instance Attribute Summary

Attributes inherited from Base

#__vc_original_view_context

Instance Method Summary collapse

Methods inherited from Base

#__vc_request, #before_render, collection_counter_parameter, collection_iteration_parameter, collection_parameter, compile, compiled?, compiler, config, #content, #content?, #controller, counter_argument_present?, ensure_compiled, #format, #helpers, inherited, iteration_argument_present?, #method_missing, #output_postamble, #output_preamble, #render, #render?, #render_in, #render_parent, #render_parent_to_string, #request, #set_original_view_context, sidecar_files, strip_trailing_whitespace, strip_trailing_whitespace?, validate_collection_parameter!, validate_initialization_parameters!, #view_cache_dependencies, #virtual_path, with_collection, with_collection_parameter

Methods included from WithContentHelper

#with_content

Methods included from Translatable

#i18n_scope, #translate

Methods included from Slotable

#get_slot, #set_polymorphic_slot, #set_slot

Constructor Details

#initialize(method, show_types = true) ⇒ MethodDoc

Returns a new instance of MethodDoc.



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

def initialize(method, show_types = true)
  @method = method
  @show_types = show_types
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ViewComponent::Base

Instance Method Details

#callObject



77
78
79
80
81
82
83
# File 'lib/view_component/docs_builder_component.rb', line 77

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

    #{docstring_and_deprecation_text}
  DOCS
end

#deprecated?Boolean

Returns:

  • (Boolean)


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

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

#deprecation_textObject



65
66
67
# File 'lib/view_component/docs_builder_component.rb', line 65

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

#docstringObject



61
62
63
# File 'lib/view_component/docs_builder_component.rb', line 61

def docstring
  @method.docstring
end

#docstring_and_deprecation_textObject



69
70
71
72
73
74
75
# File 'lib/view_component/docs_builder_component.rb', line 69

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

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

#separatorObject



57
58
59
# File 'lib/view_component/docs_builder_component.rb', line 57

def separator
  @method.sep
end

#signature_or_nameObject



53
54
55
# File 'lib/view_component/docs_builder_component.rb', line 53

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

#suffixObject



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

def suffix
  " (Deprecated)" if deprecated?
end

#typesObject



49
50
51
# File 'lib/view_component/docs_builder_component.rb', line 49

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