Class: Rucoa::Yard::DefinitionGenerators::MethodDefinitionGenerator

Inherits:
Base
  • Object
show all
Defined in:
lib/rucoa/yard/definition_generators/method_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 method definition for def node

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

returns method definition for defs node

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

returns method definition for another style of singleton def node

definitions = Rucoa::Source.new(
  content: <<~RUBY,
    class Foo
      class << self
        def bar
        end
      end
    end
  RUBY
  uri: '/path/to/foo.rb'
).definitions
expect(definitions[1].qualified_name).to eq('Foo.bar')


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rucoa/yard/definition_generators/method_definition_generator.rb', line 38

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

  [
    Definitions::MethodDefinition.new(
      description: description,
      kind: @node.singleton? ? :singleton : :instance,
      location: location,
      method_name: @node.name,
      namespace: @node.namespace,
      types: return_types.map do |type|
        Types::MethodType.new(
          parameters_string: '', # TODO
          return_type: type
        )
      end
    )
  ]
end