Class: Ariadne::Yard::RegistryEntry

Inherits:
Object
  • Object
show all
Includes:
DocsHelper
Defined in:
lib/ariadne/yard/registry.rb

Overview

A wrapper around a YARD class reference that provides convenience methods for extracting component parameters, accessibility status, etc.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DocsHelper

#component_and_short_name, #link_to_accessibility, #link_to_component, #link_to_heading_practices, #link_to_heroicons, #link_to_html_attrs_docs, #link_to_typography_docs, #one_of, #pretty_default_value, #pretty_value

Constructor Details

#initialize(component, docs) ⇒ RegistryEntry

Returns a new instance of RegistryEntry.



18
19
20
21
# File 'lib/ariadne/yard/registry.rb', line 18

def initialize(component, docs)
  @component = component
  @docs = docs
end

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component.



14
15
16
# File 'lib/ariadne/yard/registry.rb', line 14

def component
  @component
end

#docsObject (readonly)

Returns the value of attribute docs.



14
15
16
# File 'lib/ariadne/yard/registry.rb', line 14

def docs
  @docs
end

Instance Method Details

#a11y_reviewed?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/ariadne/yard/registry.rb', line 86

def a11y_reviewed?
  [:a11y_reviewed]
end

#component_idObject



70
71
72
# File 'lib/ariadne/yard/registry.rb', line 70

def component_id
  [:component_id]
end

#constructorObject



38
39
40
# File 'lib/ariadne/yard/registry.rb', line 38

def constructor
  docs.meths.find(&:constructor?)
end

#manifest_entryObject



90
91
92
# File 'lib/ariadne/yard/registry.rb', line 90

def manifest_entry
  @manifest_entry ||= ComponentManifest.ref_for(component)
end

#metadataObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ariadne/yard/registry.rb', line 23

def 
   ||= begin
    class_name, short_name = component_and_short_name(component)
    a11y_reviewed = component.audited_at.nil? ? "false" : "true"

    {
      title: class_name,
      class_name: class_name,
      component_id: short_name.underscore,
      short_name: short_name,
      a11y_reviewed: a11y_reviewed,
    }
  end
end

#non_slot_methodsObject



50
51
52
# File 'lib/ariadne/yard/registry.rb', line 50

def non_slot_methods
  public_methods.reject { |mtd| slot_method?(mtd) }
end

#paramsObject



42
43
44
# File 'lib/ariadne/yard/registry.rb', line 42

def params
  constructor&.tags(:param) || []
end

#public_methodsObject



58
59
60
61
62
63
64
# File 'lib/ariadne/yard/registry.rb', line 58

def public_methods
  # Returns: only public methods that belong to this class (i.e. no inherited methods)
  # excluding the constructor
  @public_methods ||= docs.meths.reject do |mtd|
    mtd.tag(:private) || mtd.name == :initialize
  end
end

#short_nameObject



82
83
84
# File 'lib/ariadne/yard/registry.rb', line 82

def short_name
  [:short_name]
end

#slot_method?(mtd) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/ariadne/yard/registry.rb', line 54

def slot_method?(mtd)
  mtd[:renders_one] || mtd[:renders_many]
end

#slot_methodsObject



46
47
48
# File 'lib/ariadne/yard/registry.rb', line 46

def slot_methods
  public_methods.select { |mtd| slot_method?(mtd) }
end

#statusObject



74
75
76
# File 'lib/ariadne/yard/registry.rb', line 74

def status
  [:status]
end

#status_moduleObject



78
79
80
# File 'lib/ariadne/yard/registry.rb', line 78

def status_module
  [:status_module]
end

#titleObject



66
67
68
# File 'lib/ariadne/yard/registry.rb', line 66

def title
  [:title]
end