Class: Yattho::YARD::RegistryEntry

Inherits:
Object
  • Object
show all
Includes:
DocsHelper
Defined in:
lib/yattho/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

#link_to_accessibility, #link_to_component, #link_to_heading_practices, #link_to_octicons, #link_to_system_arguments_docs, #link_to_typography_docs, #one_of, #pretty_value, #status_module_and_short_name

Constructor Details

#initialize(component, docs) ⇒ RegistryEntry

Returns a new instance of RegistryEntry.



20
21
22
23
# File 'lib/yattho/yard/registry.rb', line 20

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

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component.



16
17
18
# File 'lib/yattho/yard/registry.rb', line 16

def component
  @component
end

#docsObject (readonly)

Returns the value of attribute docs.



16
17
18
# File 'lib/yattho/yard/registry.rb', line 16

def docs
  @docs
end

Instance Method Details

#a11y_reviewed?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/yattho/yard/registry.rb', line 89

def a11y_reviewed?
  [:a11y_reviewed]
end

#component_idObject



73
74
75
# File 'lib/yattho/yard/registry.rb', line 73

def component_id
  [:component_id]
end

#constructorObject



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

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

#includes_examples?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/yattho/yard/registry.rb', line 97

def includes_examples?
  manifest.components_with_examples.include?(component)
end

#metadataObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/yattho/yard/registry.rb', line 25

def 
  @metadata ||= begin
    status_module, short_name, class_name = status_module_and_short_name(component)
    status = component.status.to_s
    a11y_reviewed = component.audited_at.nil? ? "false" : "true"

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

#non_slot_methodsObject



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

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

#paramsObject



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

def params
  constructor.tags(:param)
end

#public_methodsObject



62
63
64
65
66
67
# File 'lib/yattho/yard/registry.rb', line 62

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 { |mtd| mtd.tag(:private) || mtd.name == :initialize }
end

#requires_js?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/yattho/yard/registry.rb', line 93

def requires_js?
  manifest.components_requiring_js.include?(component)
end

#short_nameObject



85
86
87
# File 'lib/yattho/yard/registry.rb', line 85

def short_name
  [:short_name]
end

#slot_method?(mtd) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/yattho/yard/registry.rb', line 58

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

#slot_methodsObject



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

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

#statusObject



77
78
79
# File 'lib/yattho/yard/registry.rb', line 77

def status
  [:status]
end

#status_moduleObject



81
82
83
# File 'lib/yattho/yard/registry.rb', line 81

def status_module
  [:status_module]
end

#titleObject



69
70
71
# File 'lib/yattho/yard/registry.rb', line 69

def title
  [:title]
end