Class: Rucoa::Yard::DefinitionGenerators::ClassDefinitionGenerator

Inherits:
ModuleDefinitionGenerator show all
Defined in:
lib/rucoa/yard/definition_generators/class_definition_generator.rb

Instance Method Summary collapse

Methods inherited from Base

call, #initialize

Constructor Details

This class inherits a constructor from Rucoa::Yard::DefinitionGenerators::Base

Instance Method Details

#callObject

Examples:

returns class definition for class node

definitions = Rucoa::Source.new(
  content: <<~RUBY,
    class Foo
    end
  RUBY
  uri: '/path/to/foo.rb'
).definitions
expect(definitions[0]).to be_a(Rucoa::Definitions::ClassDefinition)

detects single-argument include

definitions = Rucoa::Source.new(
  content: <<~RUBY,
    class Foo
      include Bar
    end
  RUBY
  uri: '/path/to/foo.rb'
).definitions
expect(definitions[0].included_module_unqualified_names.map(&:chained_name)).to eq(%w[Bar])

detects multi-arguments include

definitions = Rucoa::Source.new(
  content: <<~RUBY,
    class Foo
      include Bar, Baz
    end
  RUBY
  uri: '/path/to/foo.rb'
).definitions
expect(definitions[0].included_module_unqualified_names.map(&:chained_name)).to eq(%w[Bar Baz])

ignores non-simple include

definitions = Rucoa::Source.new(
  content: <<~RUBY,
    class Foo
      include foo
    end
  RUBY
  uri: '/path/to/foo.rb'
).definitions
expect(definitions[0].included_module_unqualified_names.map(&:chained_name)).to eq([])


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rucoa/yard/definition_generators/class_definition_generator.rb', line 46

def call
  return [] unless @node.is_a?(Nodes::ClassNode)

  [
    Definitions::ClassDefinition.new(
      description: description,
      extended_module_unqualified_names: extended_module_unqualified_names,
      included_module_unqualified_names: included_module_unqualified_names,
      location: location,
      prepended_module_unqualified_names: prepended_module_unqualified_names,
      qualified_name: @node.qualified_name,
      super_class_unqualified_name: UnqualifiedName.new(
        chained_name: @node.super_class_chained_name,
        module_nesting: @node.module_nesting
      )
    )
  ]
end