Class: Lookbook::SourceInspector
- Inherits:
-
Object
- Object
- Lookbook::SourceInspector
show all
- Includes:
- Utils
- Defined in:
- lib/lookbook/source_inspector.rb
Constant Summary
Constants included
from Utils
Utils::FRONTMATTER_REGEX, Utils::POSITION_PREFIX_REGEX
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(code_object, eval_scope: nil) ⇒ SourceInspector
Returns a new instance of SourceInspector.
8
9
10
11
|
# File 'lib/lookbook/source_inspector.rb', line 8
def initialize(code_object, eval_scope: nil)
@code_object = code_object
@eval_scope = eval_scope
end
|
Instance Attribute Details
#code_object ⇒ Object
Returns the value of attribute code_object.
5
6
7
|
# File 'lib/lookbook/source_inspector.rb', line 5
def code_object
@code_object
end
|
Instance Method Details
#components ⇒ Object
37
38
39
|
# File 'lib/lookbook/source_inspector.rb', line 37
def components
@components ||= Array(code_object.tags(:component)).map(&:value)
end
|
#display_options ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/lookbook/source_inspector.rb', line 46
def display_options
return @display_options unless @display_options.nil?
display_tags = Array(code_object.tags(:display)).select do |tag|
!(tag.value.is_a?(Array) || tag.value.is_a?(Hash))
end
display_tags.map { |tag| [tag.key.to_sym, tag.value] }.to_h
end
|
#group ⇒ Object
29
30
31
|
# File 'lib/lookbook/source_inspector.rb', line 29
def group
@group ||= code_object.group
end
|
#hidden? ⇒ Boolean
13
14
15
|
# File 'lib/lookbook/source_inspector.rb', line 13
def hidden?
@hidden ||= tag_value(:hidden) || false
end
|
#id ⇒ Object
17
18
19
|
# File 'lib/lookbook/source_inspector.rb', line 17
def id
@id ||= tag_value(:id)
end
|
#label ⇒ Object
21
22
23
|
# File 'lib/lookbook/source_inspector.rb', line 21
def label
@label ||= tag_value(:label)
end
|
#logical_path ⇒ Object
41
42
43
44
|
# File 'lib/lookbook/source_inspector.rb', line 41
def logical_path
path = tag_value(:logical_path)
path&.delete_prefix("/")&.delete_suffix("/")
end
|
#methods ⇒ Object
58
59
60
|
# File 'lib/lookbook/source_inspector.rb', line 58
def methods
@methods ||= code_object.meths
end
|
#notes ⇒ Object
25
26
27
|
# File 'lib/lookbook/source_inspector.rb', line 25
def notes
@notes ||= code_object.docstring&.to_s&.strip
end
|
#position ⇒ Object
33
34
35
|
# File 'lib/lookbook/source_inspector.rb', line 33
def position
@position ||= tag_value(:position) || 10000
end
|
#tag(name = nil) ⇒ Object
66
67
68
|
# File 'lib/lookbook/source_inspector.rb', line 66
def tag(name = nil)
tags(name).first
end
|
62
63
64
|
# File 'lib/lookbook/source_inspector.rb', line 62
def tags(name = nil)
code_object.tags(name)
end
|