Class: Ariadne::Yard::ComponentRef

Inherits:
Object
  • Object
show all
Defined in:
lib/ariadne/yard/component_ref.rb

Overview

:nodoc:

Constant Summary collapse

ATTR_DEFAULTS =
{
  js: false,
  examples: true,
  form_component: false,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, attrs) ⇒ ComponentRef

Returns a new instance of ComponentRef.



16
17
18
19
# File 'lib/ariadne/yard/component_ref.rb', line 16

def initialize(klass, attrs)
  @klass = klass
  @attrs = attrs
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



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

def attrs
  @attrs
end

#klassObject (readonly)

Returns the value of attribute klass.



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

def klass
  @klass
end

Instance Method Details

#form_component?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/ariadne/yard/component_ref.rb', line 29

def form_component?
  @attrs.fetch(:form_component, ATTR_DEFAULTS[:form_component])
end

#lookbook_urlObject



40
41
42
43
44
45
# File 'lib/ariadne/yard/component_ref.rb', line 40

def lookbook_url
  @lookbook_url ||= begin
    path = klass.name.underscore.gsub("_component", "")
    "https://ariadne.style/view-components/lookbook/inspect/#{path}/default/"
  end
end

#requires_js?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/ariadne/yard/component_ref.rb', line 21

def requires_js?
  @attrs.fetch(:js, ATTR_DEFAULTS[:js])
end

#should_have_examples?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/ariadne/yard/component_ref.rb', line 25

def should_have_examples?
  @attrs.fetch(:examples, ATTR_DEFAULTS[:examples])
end

#source_urlObject



33
34
35
36
37
38
# File 'lib/ariadne/yard/component_ref.rb', line 33

def source_url
  @source_url ||= begin
    path = klass.name.split("::").map(&:underscore).join("/")
    "https://github.com/primer/view_components/tree/main/app/components/#{path}.rb"
  end
end