sleeping_king_studios-docs 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE +22 -0
- data/README.md +101 -0
- data/lib/sleeping_king_studios/docs/commands/generate.rb +268 -0
- data/lib/sleeping_king_studios/docs/commands/generators/base.rb +97 -0
- data/lib/sleeping_king_studios/docs/commands/generators/data_generator.rb +68 -0
- data/lib/sleeping_king_studios/docs/commands/generators/reference_generator.rb +59 -0
- data/lib/sleeping_king_studios/docs/commands/generators.rb +15 -0
- data/lib/sleeping_king_studios/docs/commands/installation/install_jekyll.rb +273 -0
- data/lib/sleeping_king_studios/docs/commands/installation/install_templates.rb +125 -0
- data/lib/sleeping_king_studios/docs/commands/installation/install_workflow.rb +121 -0
- data/lib/sleeping_king_studios/docs/commands/installation.rb +15 -0
- data/lib/sleeping_king_studios/docs/commands/parse.rb +51 -0
- data/lib/sleeping_king_studios/docs/commands/write_file.rb +89 -0
- data/lib/sleeping_king_studios/docs/commands.rb +14 -0
- data/lib/sleeping_king_studios/docs/data/base.rb +48 -0
- data/lib/sleeping_king_studios/docs/data/class_object.rb +119 -0
- data/lib/sleeping_king_studios/docs/data/constant_object.rb +161 -0
- data/lib/sleeping_king_studios/docs/data/metadata.rb +196 -0
- data/lib/sleeping_king_studios/docs/data/method_object.rb +555 -0
- data/lib/sleeping_king_studios/docs/data/module_object.rb +234 -0
- data/lib/sleeping_king_studios/docs/data/namespace_object.rb +375 -0
- data/lib/sleeping_king_studios/docs/data/root_object.rb +40 -0
- data/lib/sleeping_king_studios/docs/data/see_tags/base.rb +35 -0
- data/lib/sleeping_king_studios/docs/data/see_tags/class_method_tag.rb +99 -0
- data/lib/sleeping_king_studios/docs/data/see_tags/constant_tag.rb +60 -0
- data/lib/sleeping_king_studios/docs/data/see_tags/definition_tag.rb +52 -0
- data/lib/sleeping_king_studios/docs/data/see_tags/instance_method_tag.rb +69 -0
- data/lib/sleeping_king_studios/docs/data/see_tags/link_tag.rb +53 -0
- data/lib/sleeping_king_studios/docs/data/see_tags/namespace_item_tag.rb +56 -0
- data/lib/sleeping_king_studios/docs/data/see_tags/reference_tag.rb +92 -0
- data/lib/sleeping_king_studios/docs/data/see_tags/text_tag.rb +30 -0
- data/lib/sleeping_king_studios/docs/data/see_tags/unstructured_tag.rb +37 -0
- data/lib/sleeping_king_studios/docs/data/see_tags.rb +101 -0
- data/lib/sleeping_king_studios/docs/data/types/grammar.treetop +49 -0
- data/lib/sleeping_king_studios/docs/data/types/key_value_type.rb +54 -0
- data/lib/sleeping_king_studios/docs/data/types/parameterized_type.rb +57 -0
- data/lib/sleeping_king_studios/docs/data/types/parser.rb +143 -0
- data/lib/sleeping_king_studios/docs/data/types/type.rb +100 -0
- data/lib/sleeping_king_studios/docs/data/types.rb +19 -0
- data/lib/sleeping_king_studios/docs/data.rb +29 -0
- data/lib/sleeping_king_studios/docs/errors/file_already_exists.rb +22 -0
- data/lib/sleeping_king_studios/docs/errors/file_error.rb +30 -0
- data/lib/sleeping_king_studios/docs/errors/file_not_found.rb +22 -0
- data/lib/sleeping_king_studios/docs/errors/invalid_directory.rb +22 -0
- data/lib/sleeping_king_studios/docs/errors/invalid_file.rb +22 -0
- data/lib/sleeping_king_studios/docs/errors.rb +19 -0
- data/lib/sleeping_king_studios/docs/registry.rb +22 -0
- data/lib/sleeping_king_studios/docs/registry_query.rb +93 -0
- data/lib/sleeping_king_studios/docs/tasks/base.rb +20 -0
- data/lib/sleeping_king_studios/docs/tasks/generate.rb +39 -0
- data/lib/sleeping_king_studios/docs/tasks/installation/install_jekyll.rb +67 -0
- data/lib/sleeping_king_studios/docs/tasks/installation/install_templates.rb +39 -0
- data/lib/sleeping_king_studios/docs/tasks/installation/install_workflow.rb +53 -0
- data/lib/sleeping_king_studios/docs/tasks/installation.rb +8 -0
- data/lib/sleeping_king_studios/docs/tasks/update.rb +35 -0
- data/lib/sleeping_king_studios/docs/tasks.rb +14 -0
- data/lib/sleeping_king_studios/docs/templates/config.yml.erb +22 -0
- data/lib/sleeping_king_studios/docs/templates/deploy-pages.yml.erb +67 -0
- data/lib/sleeping_king_studios/docs/templates/includes/breadcrumbs.md +7 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/attribute.md +23 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/attributes/heading.md +15 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/class.md +27 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/constant.md +8 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/constants/heading.md +6 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/constants/inherited.md +4 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/constants/overview.md +60 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/breadcrumbs.md +21 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/class_attributes.md +9 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/class_methods.md +9 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/constants.md +9 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/constructor.md +12 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/definitions.md +23 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/details.md +34 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/instance_attributes.md +9 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/instance_methods.md +17 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/overview.md +74 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/subclasses.md +10 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/table-of-contents/class_attributes.md +10 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/table-of-contents/class_methods.md +10 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/table-of-contents/constants.md +10 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/table-of-contents/instance_attributes.md +10 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/table-of-contents/instance_methods.md +10 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/table-of-contents/overview.md +41 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/table-of-contents.md +27 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/method.md +27 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/aliases.md +4 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/heading.md +14 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/inherited.md +4 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/overload.md +18 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/overloads.md +12 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/overview.md +41 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/parameters.md +31 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/post_overview.md +51 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/raises.md +14 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/return_types.md +9 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/returns.md +14 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/yields.md +42 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/module.md +23 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/namespace.md +33 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/parent_link.md +6 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/reference_link.md +7 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/see_link.md +7 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/type.md +14 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/type_list.md +4 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/types/array_type.md +1 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/types/hash_type.md +1 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/types/ordered_type.md +1 -0
- data/lib/sleeping_king_studios/docs/templates/pages/index.md.erb +22 -0
- data/lib/sleeping_king_studios/docs/templates/pages/reference.md.erb +14 -0
- data/lib/sleeping_king_studios/docs/templates/pages/versions.md.erb +13 -0
- data/lib/sleeping_king_studios/docs/version.rb +59 -0
- data/lib/sleeping_king_studios/docs.rb +27 -0
- metadata +243 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sleeping_king_studios/docs/data/types'
|
4
|
+
|
5
|
+
module SleepingKingStudios::Docs::Data::Types
|
6
|
+
# Represents a YARD type with lists of key types and value types.
|
7
|
+
class KeyValueType < SleepingKingStudios::Docs::Data::Types::Type
|
8
|
+
# @param keys [Array<SleepingKingStudios::Docs::Data::Types::Type>] the key
|
9
|
+
# types.
|
10
|
+
# @param name [String] the name of the type.
|
11
|
+
# @param values [Array<SleepingKingStudios::Docs::Data::Types::Type>] the
|
12
|
+
# value types.
|
13
|
+
def initialize(keys:, name:, values:)
|
14
|
+
super(name:)
|
15
|
+
|
16
|
+
@keys = keys
|
17
|
+
@values = values
|
18
|
+
end
|
19
|
+
|
20
|
+
# Generates a JSON-compatible representation of the parameterized type.
|
21
|
+
#
|
22
|
+
# Returns a Hash with the following keys:
|
23
|
+
#
|
24
|
+
# - 'name': The name of the type.
|
25
|
+
# - 'keys': A JSON representation of the parameterized keys.
|
26
|
+
# - 'values': A JSON representation of the parameterized values.
|
27
|
+
# - (Optional) 'path': The relative path to the referenced class or module,
|
28
|
+
# if the class or module is documented by YARD.
|
29
|
+
#
|
30
|
+
# @return [Hash] the JSON representation.
|
31
|
+
def as_json
|
32
|
+
super.merge(
|
33
|
+
'keys' => keys.map(&:as_json),
|
34
|
+
'values' => values.map(&:as_json)
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
# @return [Array<SleepingKingStudios::Docs::Data::Types::Type>] the key
|
39
|
+
# types.
|
40
|
+
attr_reader :keys
|
41
|
+
|
42
|
+
# @return [Array<SleepingKingStudios::Docs::Data::Types::Type>] the value
|
43
|
+
# types.
|
44
|
+
attr_reader :values
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def inspect_attributes
|
49
|
+
"#{super} " \
|
50
|
+
"@keys=[#{keys.map(&:inspect).join(', ')}] " \
|
51
|
+
"@values=[#{values.map(&:inspect).join(', ')}]"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sleeping_king_studios/docs/data/types'
|
4
|
+
|
5
|
+
module SleepingKingStudios::Docs::Data::Types
|
6
|
+
# Represents a YARD type with a list of child types.
|
7
|
+
class ParameterizedType < SleepingKingStudios::Docs::Data::Types::Type
|
8
|
+
# @param items [Array<SleepingKingStudios::Docs::Data::Types::Type>] the
|
9
|
+
# child types.
|
10
|
+
# @param name [String] the name of the type.
|
11
|
+
# @param ordered [Boolean] if true, indicates the type represents an order-
|
12
|
+
# dependent list.
|
13
|
+
def initialize(items:, name:, ordered: false)
|
14
|
+
super(name:)
|
15
|
+
|
16
|
+
@items = items
|
17
|
+
@ordered = ordered
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [Array<SleepingKingStudios::Docs::Data::Types::Type>] the child
|
21
|
+
# types.
|
22
|
+
attr_reader :items
|
23
|
+
|
24
|
+
# Generates a JSON-compatible representation of the parameterized type.
|
25
|
+
#
|
26
|
+
# Returns a Hash with the following keys:
|
27
|
+
#
|
28
|
+
# - 'name': The name of the type.
|
29
|
+
# - 'items': A JSON representation of the parameterized items.
|
30
|
+
# - (Optional) 'ordered': If true, indicates the type represents an order-
|
31
|
+
# dependent list.
|
32
|
+
# - (Optional) 'path': The relative path to the referenced class or module,
|
33
|
+
# if the class or module is documented by YARD.
|
34
|
+
#
|
35
|
+
# @return [Hash] the JSON representation.
|
36
|
+
def as_json
|
37
|
+
json = super.merge('items' => items.map(&:as_json))
|
38
|
+
|
39
|
+
return json unless ordered?
|
40
|
+
|
41
|
+
json.merge('ordered' => true)
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [Boolean] if true, indicates the type represents an order-
|
45
|
+
# dependent list.
|
46
|
+
def ordered?
|
47
|
+
@ordered
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def inspect_attributes
|
53
|
+
"#{super} @ordered=#{ordered?} " \
|
54
|
+
"@items=[#{items.map(&:inspect).join(', ')}]"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sleeping_king_studios/tools/toolbelt'
|
4
|
+
require 'treetop'
|
5
|
+
|
6
|
+
require 'sleeping_king_studios/docs/data/types'
|
7
|
+
require 'sleeping_king_studios/docs/data/types/grammar'
|
8
|
+
|
9
|
+
module SleepingKingStudios::Docs::Data::Types
|
10
|
+
# Parses a YARD type list into a nested data object.
|
11
|
+
#
|
12
|
+
# @note Certain combinations of comparable methods and parameterized types are
|
13
|
+
# known not to parse: list types with `#<=` or `#>` methods, and hash types
|
14
|
+
# with `#<`, `#==`, or `#>` keys. As a workaround, add trailing whitespace
|
15
|
+
# between the method name and any subsequent control characters.
|
16
|
+
#
|
17
|
+
# @see https://www.rubydoc.info/gems/yard/file/docs/Tags.md#types-specifier-list
|
18
|
+
class Parser
|
19
|
+
# Exception raised when encountering an invalid type string.
|
20
|
+
class ParseError < StandardError; end
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@parser = TypesSpecifierListParser.new
|
24
|
+
|
25
|
+
generate_node_map
|
26
|
+
end
|
27
|
+
|
28
|
+
# Parses a YARD type list.
|
29
|
+
#
|
30
|
+
# @return [Array<[SleepingKingStudios::Docs::Data::Types::Type]>] the parsed
|
31
|
+
# types.
|
32
|
+
#
|
33
|
+
# @raise [ParserError] if unable to parse the type.
|
34
|
+
def parse(type)
|
35
|
+
return [] if type.nil? || type.empty?
|
36
|
+
|
37
|
+
result = parser.parse(type)
|
38
|
+
|
39
|
+
raise ParseError, "unable to parse type `#{type}'" if result.nil?
|
40
|
+
|
41
|
+
Array(handle_node(result))
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
attr_reader :node_map
|
47
|
+
|
48
|
+
attr_reader :parser
|
49
|
+
|
50
|
+
def build_array(name:, values:, ordered: false)
|
51
|
+
SleepingKingStudios::Docs::Data::Types::ParameterizedType.new(
|
52
|
+
items: values,
|
53
|
+
name:,
|
54
|
+
ordered:
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
def build_basic(name:)
|
59
|
+
SleepingKingStudios::Docs::Data::Types::Type.new(name:)
|
60
|
+
end
|
61
|
+
|
62
|
+
def build_hash(name:, keys:, values:)
|
63
|
+
SleepingKingStudios::Docs::Data::Types::KeyValueType.new(
|
64
|
+
keys:,
|
65
|
+
name:,
|
66
|
+
values:
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
def generate_node_map # rubocop:disable Metrics/MethodLength
|
71
|
+
@node_map =
|
72
|
+
TypesSpecifierList
|
73
|
+
.constants
|
74
|
+
.select { |const_name| const_name.to_s.end_with?('0') }
|
75
|
+
.sort
|
76
|
+
.to_h \
|
77
|
+
do |const_name|
|
78
|
+
ext = TypesSpecifierList.const_get(const_name)
|
79
|
+
value = tools.string_tools.underscore(const_name.to_s[0...-1]).intern
|
80
|
+
|
81
|
+
[ext, value]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def handle_key_value_type(node)
|
86
|
+
name = node.elements.first.text_value
|
87
|
+
keys = Array(handle_node(node.elements[2]))
|
88
|
+
values = Array(handle_node(node.elements[4]))
|
89
|
+
|
90
|
+
build_hash(name:, keys:, values:)
|
91
|
+
end
|
92
|
+
|
93
|
+
def handle_identifier_with_whitespace(node)
|
94
|
+
name = node.text_value.strip
|
95
|
+
|
96
|
+
build_basic(name:)
|
97
|
+
end
|
98
|
+
|
99
|
+
def handle_node(node)
|
100
|
+
node_type = identify_node_type(node)
|
101
|
+
handler = :"handle_#{node_type}"
|
102
|
+
|
103
|
+
send(handler, node)
|
104
|
+
end
|
105
|
+
|
106
|
+
def handle_ordered_type(node)
|
107
|
+
name = node.elements.first.text_value
|
108
|
+
values = Array(handle_node(node.elements[2]))
|
109
|
+
|
110
|
+
build_array(name:, ordered: true, values:)
|
111
|
+
end
|
112
|
+
|
113
|
+
def handle_parameterized_type(node)
|
114
|
+
name = node.elements.first.text_value
|
115
|
+
values = Array(handle_node(node.elements[2]))
|
116
|
+
|
117
|
+
build_array(name:, values:)
|
118
|
+
end
|
119
|
+
|
120
|
+
def handle_type_list(node)
|
121
|
+
if identify_node_type(node.elements.last) == :type_list
|
122
|
+
return [
|
123
|
+
handle_node(node.elements.first),
|
124
|
+
*handle_type_list(node.elements.last)
|
125
|
+
]
|
126
|
+
end
|
127
|
+
|
128
|
+
[handle_node(node.elements.first), *handle_node(node.elements.last)]
|
129
|
+
end
|
130
|
+
|
131
|
+
def identify_node_type(node)
|
132
|
+
return :text if node.extension_modules.empty?
|
133
|
+
|
134
|
+
node_map
|
135
|
+
.find { |type, _| node.extension_modules.include?(type) }
|
136
|
+
&.last || :unknown_type
|
137
|
+
end
|
138
|
+
|
139
|
+
def tools
|
140
|
+
SleepingKingStudios::Tools::Toolbelt.instance
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sleeping_king_studios/tools/toolbelt'
|
4
|
+
|
5
|
+
require 'sleeping_king_studios/docs/data/types'
|
6
|
+
|
7
|
+
module SleepingKingStudios::Docs::Data::Types
|
8
|
+
# Base class for a YARD type.
|
9
|
+
class Type
|
10
|
+
LOWERCASE_LETTER = /\A[[:lower:]]/
|
11
|
+
private_constant :LOWERCASE_LETTER
|
12
|
+
|
13
|
+
# @param name [String] the name of the type.
|
14
|
+
def initialize(name:)
|
15
|
+
@name = name
|
16
|
+
@registry = SleepingKingStudios::Docs::Registry.instance
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [String] the name of the type.
|
20
|
+
attr_reader :name
|
21
|
+
|
22
|
+
# @return [Boolean] true if the other object is an instance of the same Type
|
23
|
+
# class and has the same JSON representation; otherwise false.
|
24
|
+
def ==(other)
|
25
|
+
return false unless other.instance_of?(self.class)
|
26
|
+
|
27
|
+
other.as_json == as_json
|
28
|
+
end
|
29
|
+
|
30
|
+
# Generates a JSON-compatible representation of the type.
|
31
|
+
#
|
32
|
+
# Returns a Hash with the following keys:
|
33
|
+
#
|
34
|
+
# - 'name': The name of the type.
|
35
|
+
# - (Optional) 'path': The relative path to the referenced class or module,
|
36
|
+
# if the class or module is documented by YARD.
|
37
|
+
#
|
38
|
+
# @return [Hash] the JSON representation.
|
39
|
+
def as_json
|
40
|
+
json = { 'name' => name }
|
41
|
+
|
42
|
+
return json unless exists?
|
43
|
+
|
44
|
+
json.merge('path' => path)
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [Boolean] true if the type is a class or module documented by
|
48
|
+
# YARD; otherwise false.
|
49
|
+
def exists?
|
50
|
+
return @exists unless @exists.nil?
|
51
|
+
|
52
|
+
return @exists = false if literal? || method?
|
53
|
+
|
54
|
+
@exists =
|
55
|
+
SleepingKingStudios::Docs::RegistryQuery
|
56
|
+
.new(registry:)
|
57
|
+
.definition_exists?(name)
|
58
|
+
end
|
59
|
+
|
60
|
+
# @return [String] a user-friendly representation of the Type.
|
61
|
+
def inspect
|
62
|
+
"#<#{self.class.name.split('::').last} #{inspect_attributes}>"
|
63
|
+
end
|
64
|
+
|
65
|
+
# @return [Boolean] true if the type is a literal value; otherwise false.
|
66
|
+
def literal?
|
67
|
+
name.match?(LOWERCASE_LETTER)
|
68
|
+
end
|
69
|
+
|
70
|
+
# @return [Boolean] true if the name is a method name, otherwise false.
|
71
|
+
def method?
|
72
|
+
name.start_with?('.') || name.start_with?('#')
|
73
|
+
end
|
74
|
+
|
75
|
+
# @return [String, nil] the qualified relative path of the definition, or
|
76
|
+
# nil if the type is not a class or module or it is not documented by
|
77
|
+
# YARD.
|
78
|
+
def path
|
79
|
+
return nil unless exists?
|
80
|
+
|
81
|
+
@path ||= name.split('::').map { |str| slugify(str) }.join('/')
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
attr_reader :registry
|
87
|
+
|
88
|
+
def inspect_attributes
|
89
|
+
"@name=#{name.inspect}"
|
90
|
+
end
|
91
|
+
|
92
|
+
def slugify(str)
|
93
|
+
tools.string_tools.underscore(str).tr('_', '-')
|
94
|
+
end
|
95
|
+
|
96
|
+
def tools
|
97
|
+
SleepingKingStudios::Tools::Toolbelt.instance
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sleeping_king_studios/docs/data'
|
4
|
+
|
5
|
+
module SleepingKingStudios::Docs::Data
|
6
|
+
# Namespace for types, which represent a YARD type list.
|
7
|
+
#
|
8
|
+
# @see https://www.rubydoc.info/gems/yard/file/docs/Tags.md#types-specifier-list
|
9
|
+
module Types
|
10
|
+
autoload :KeyValueType,
|
11
|
+
'sleeping_king_studios/docs/data/types/key_value_type'
|
12
|
+
autoload :ParameterizedType,
|
13
|
+
'sleeping_king_studios/docs/data/types/parameterized_type'
|
14
|
+
autoload :Parser,
|
15
|
+
'sleeping_king_studios/docs/data/types/parser'
|
16
|
+
autoload :Type,
|
17
|
+
'sleeping_king_studios/docs/data/types/type'
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sleeping_king_studios/docs'
|
4
|
+
|
5
|
+
module SleepingKingStudios::Docs
|
6
|
+
# Namespace for data objects, which represent documented code.
|
7
|
+
module Data
|
8
|
+
autoload :Base,
|
9
|
+
'sleeping_king_studios/docs/data/base'
|
10
|
+
autoload :ClassObject,
|
11
|
+
'sleeping_king_studios/docs/data/class_object'
|
12
|
+
autoload :ConstantObject,
|
13
|
+
'sleeping_king_studios/docs/data/constant_object'
|
14
|
+
autoload :Metadata,
|
15
|
+
'sleeping_king_studios/docs/data/metadata'
|
16
|
+
autoload :MethodObject,
|
17
|
+
'sleeping_king_studios/docs/data/method_object'
|
18
|
+
autoload :ModuleObject,
|
19
|
+
'sleeping_king_studios/docs/data/module_object'
|
20
|
+
autoload :NamespaceObject,
|
21
|
+
'sleeping_king_studios/docs/data/namespace_object'
|
22
|
+
autoload :RootObject,
|
23
|
+
'sleeping_king_studios/docs/data/root_object'
|
24
|
+
autoload :SeeTags,
|
25
|
+
'sleeping_king_studios/docs/data/see_tags'
|
26
|
+
autoload :Types,
|
27
|
+
'sleeping_king_studios/docs/data/types'
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sleeping_king_studios/docs/errors'
|
4
|
+
|
5
|
+
module SleepingKingStudios::Docs::Errors
|
6
|
+
# Error returned when attempting to create an existing file.
|
7
|
+
class FileAlreadyExists < SleepingKingStudios::Docs::Errors::FileError
|
8
|
+
# Short string used to identify the type of error.
|
9
|
+
TYPE = 'sleeping_king_studios.docs.errors.file_already_exists'
|
10
|
+
|
11
|
+
# @param path [String] the invalid file path.
|
12
|
+
def initialize(path:)
|
13
|
+
super(message: default_message(path), path:)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def default_message(path)
|
19
|
+
"file already exists at #{path.inspect}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cuprum/error'
|
4
|
+
|
5
|
+
require 'sleeping_king_studios/docs/errors'
|
6
|
+
|
7
|
+
module SleepingKingStudios::Docs::Errors
|
8
|
+
# Abstract base class for errors interacting with the file system.
|
9
|
+
class FileError < Cuprum::Error
|
10
|
+
# Short string used to identify the type of error.
|
11
|
+
TYPE = 'sleeping_king_studios.docs.errors.file_error'
|
12
|
+
|
13
|
+
# @param message [String] message describing the nature of the error.
|
14
|
+
# @param path [String] the invalid file or directory path.
|
15
|
+
def initialize(message:, path:)
|
16
|
+
super(message:)
|
17
|
+
|
18
|
+
@path = path
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return [String] the invalid file or directory path.
|
22
|
+
attr_reader :path
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def as_json_data
|
27
|
+
{ 'path' => path.to_s }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sleeping_king_studios/docs/errors'
|
4
|
+
|
5
|
+
module SleepingKingStudios::Docs::Errors
|
6
|
+
# Error returned when attempting to parse an invalid file or directory.
|
7
|
+
class FileNotFound < SleepingKingStudios::Docs::Errors::FileError
|
8
|
+
# Short string used to identify the type of error.
|
9
|
+
TYPE = 'sleeping_king_studios.docs.errors.file_not_found'
|
10
|
+
|
11
|
+
# @param path [String] the invalid file path.
|
12
|
+
def initialize(path:)
|
13
|
+
super(message: default_message(path), path:)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def default_message(path)
|
19
|
+
"file or directory not found at #{path.inspect}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sleeping_king_studios/docs/errors'
|
4
|
+
|
5
|
+
module SleepingKingStudios::Docs::Errors
|
6
|
+
# Error returned when attempting to create an invalid directory.
|
7
|
+
class InvalidDirectory < SleepingKingStudios::Docs::Errors::FileError
|
8
|
+
# Short string used to identify the type of error.
|
9
|
+
TYPE = 'sleeping_king_studios.docs.errors.invalid_directory'
|
10
|
+
|
11
|
+
# @param path [String] the invalid directory path.
|
12
|
+
def initialize(path:)
|
13
|
+
super(message: default_message(path), path:)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def default_message(path)
|
19
|
+
"file already exists at #{path.inspect}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sleeping_king_studios/docs/errors'
|
4
|
+
|
5
|
+
module SleepingKingStudios::Docs::Errors
|
6
|
+
# Error returned when attempting to create an invalid file.
|
7
|
+
class InvalidFile < SleepingKingStudios::Docs::Errors::FileError
|
8
|
+
# Short string used to identify the type of error.
|
9
|
+
TYPE = 'sleeping_king_studios.docs.errors.invalid_file'
|
10
|
+
|
11
|
+
# @param path [String] the invalid file path.
|
12
|
+
def initialize(path:)
|
13
|
+
super(message: default_message(path), path:)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def default_message(path)
|
19
|
+
"directory already exists at #{path.inspect}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sleeping_king_studios/docs'
|
4
|
+
|
5
|
+
module SleepingKingStudios::Docs
|
6
|
+
# Namespace for error objects, which encapsulate command failure states.
|
7
|
+
module Errors
|
8
|
+
autoload :FileAlreadyExists,
|
9
|
+
'sleeping_king_studios/docs/errors/file_already_exists'
|
10
|
+
autoload :FileError,
|
11
|
+
'sleeping_king_studios/docs/errors/file_error'
|
12
|
+
autoload :FileNotFound,
|
13
|
+
'sleeping_king_studios/docs/errors/file_not_found'
|
14
|
+
autoload :InvalidDirectory,
|
15
|
+
'sleeping_king_studios/docs/errors/invalid_directory'
|
16
|
+
autoload :InvalidFile,
|
17
|
+
'sleeping_king_studios/docs/errors/invalid_file'
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yard'
|
4
|
+
|
5
|
+
require 'sleeping_king_studios/docs'
|
6
|
+
|
7
|
+
module SleepingKingStudios::Docs
|
8
|
+
# Dependency injection provider wrapping the YARD registry.
|
9
|
+
module Registry
|
10
|
+
# Clears the cached registry, if any.
|
11
|
+
def self.clear
|
12
|
+
@instance = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
# Caches and returns the contents of the YARD registry.
|
16
|
+
#
|
17
|
+
# @return [Array] the cached registry.
|
18
|
+
def self.instance
|
19
|
+
@instance ||= [::YARD::Registry.root, *::YARD::Registry.to_a]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sleeping_king_studios/docs'
|
4
|
+
|
5
|
+
module SleepingKingStudios::Docs
|
6
|
+
# Checks for the presence of requested data in the YARD registry.
|
7
|
+
class RegistryQuery
|
8
|
+
# @param registry [Enumerable] the YARD registry.
|
9
|
+
def initialize(registry:)
|
10
|
+
@registry = registry
|
11
|
+
end
|
12
|
+
|
13
|
+
# Checks if the given class method is defined in the registry.
|
14
|
+
#
|
15
|
+
# @param method_name [String] the name of the method and defining namespace,
|
16
|
+
# if any.
|
17
|
+
#
|
18
|
+
# @return [Boolean] true if the class method exists, otherwise false.
|
19
|
+
def class_method_exists?(method_name)
|
20
|
+
# Handle top-level class methods.
|
21
|
+
if method_name.start_with?('.')
|
22
|
+
return top_level_class_method_exists?(method_name)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Handle legacy ::class_method format.
|
26
|
+
unless method_name.include?('.')
|
27
|
+
return legacy_class_method_exists?(method_name)
|
28
|
+
end
|
29
|
+
|
30
|
+
registry.any? do |obj|
|
31
|
+
obj.type == :method && obj.scope == :class && obj.title == method_name
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Checks if the given constant is defined in the registry.
|
36
|
+
#
|
37
|
+
# @param constant_name [String] the name of the constant and defining
|
38
|
+
# namespace, if any.
|
39
|
+
#
|
40
|
+
# @return [Boolean] true if the constant exists, otherwise false.
|
41
|
+
def constant_exists?(constant_name)
|
42
|
+
registry.any? do |obj|
|
43
|
+
obj.type == :constant && obj.title == constant_name
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Checks if the given class or module is defined in the registry.
|
48
|
+
#
|
49
|
+
# @param module_name [String] the name of the class or module and defining
|
50
|
+
# namespace, if any.
|
51
|
+
#
|
52
|
+
# @return [Boolean] true if the class or module exists, otherwise false.
|
53
|
+
def definition_exists?(module_name)
|
54
|
+
registry.any? do |obj|
|
55
|
+
(obj.type == :module || obj.type == :class) && obj.title == module_name # rubocop:disable Style/MultipleComparison
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Checks if the given instance method is defined in the registry.
|
60
|
+
#
|
61
|
+
# @param method_name [String] the name of the method and defining namespace,
|
62
|
+
# if any.
|
63
|
+
#
|
64
|
+
# @return [Boolean] true if the instance method exists, otherwise false.
|
65
|
+
def instance_method_exists?(method_name)
|
66
|
+
registry.any? do |obj|
|
67
|
+
obj.type == :method &&
|
68
|
+
obj.scope == :instance &&
|
69
|
+
obj.title == method_name
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
attr_reader :registry
|
76
|
+
|
77
|
+
def legacy_class_method_exists?(method_name)
|
78
|
+
method_name = method_name.reverse.sub('::', '.').reverse
|
79
|
+
|
80
|
+
registry.any? do |obj|
|
81
|
+
obj.type == :method && obj.scope == :class && obj.title == method_name
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def top_level_class_method_exists?(method_name)
|
86
|
+
method_name = "::#{method_name[1..]}"
|
87
|
+
|
88
|
+
registry.any? do |obj|
|
89
|
+
obj.type == :method && obj.scope == :class && obj.title == method_name
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
|
5
|
+
require 'sleeping_king_studios/tools/toolbelt'
|
6
|
+
|
7
|
+
require 'sleeping_king_studios/docs'
|
8
|
+
|
9
|
+
module SleepingKingStudios::Docs
|
10
|
+
module Tasks
|
11
|
+
# Generic base CLI task.
|
12
|
+
class Base < Thor
|
13
|
+
private
|
14
|
+
|
15
|
+
def tools
|
16
|
+
SleepingKingStudios::Tools::Toolbelt.instance
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|