Class: Rucoa::Yard::DefinitionsLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/rucoa/yard/definitions_loader.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(associations:, root_node:) ⇒ DefinitionsLoader

Returns a new instance of DefinitionsLoader.

Parameters:



26
27
28
29
30
31
32
# File 'lib/rucoa/yard/definitions_loader.rb', line 26

def initialize(
  associations:,
  root_node:
)
  @associations = associations
  @root_node = root_node
end

Class Method Details

.call(associations:, root_node:) ⇒ Object

Parameters:



13
14
15
16
17
18
19
20
21
# File 'lib/rucoa/yard/definitions_loader.rb', line 13

def call(
  associations:,
  root_node:
)
  new(
    associations: associations,
    root_node: root_node
  ).call
end

Instance Method Details

#callArray<Rucoa::Definition::Base>

Returns:

  • (Array<Rucoa::Definition::Base>)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rucoa/yard/definitions_loader.rb', line 35

def call
  [
    @root_node,
    *@root_node.descendant_nodes
  ].flat_map do |node|
    [
      DefinitionGenerators::ClassDefinitionGenerator,
      DefinitionGenerators::ConstantAssignmentDefinitionGenerator,
      DefinitionGenerators::MethodDefinitionGenerator,
      DefinitionGenerators::ModuleDefinitionGenerator,
      DefinitionGenerators::AttributeReaderDefinitionGenerator,
      DefinitionGenerators::AttributeWriterDefinitionGenerator
    ].flat_map do |generator|
      generator.call(
        comment: comment_for(node),
        node: node
      )
    end
  end
end

#comment_for(node) ⇒ String

Returns:

  • (String)


57
58
59
60
61
# File 'lib/rucoa/yard/definitions_loader.rb', line 57

def comment_for(node)
  @associations[node.location].map do |parser_comment|
    parser_comment.text.gsub(/^#\s*/m, '')
  end.join("\n")
end