Class: SupportTableData::Documentation::RbsDoc

Inherits:
Object
  • Object
show all
Defined in:
lib/support_table_data/documentation/rbs_doc.rb

Overview

Generates RBS type signatures for the dynamically-defined named instance helper methods on a support table model.

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ RbsDoc

Returns a new instance of RbsDoc.

Parameters:

  • klass (Class)

    The model class to generate signatures for



9
10
11
# File 'lib/support_table_data/documentation/rbs_doc.rb', line 9

def initialize(klass)
  @klass = klass
end

Instance Method Details

#signaturesString?

Render the full RBS file content for the model, including the class declaration. Returns nil when the model has no named instances.

Returns:

  • (String, nil)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/support_table_data/documentation/rbs_doc.rb', line 17

def signatures
  instance_names = klass.instance_names
  return nil if instance_names.empty?

  body_lines = []
  instance_names.sort.each_with_index do |name, idx|
    body_lines << "" unless idx.zero?
    body_lines.concat(instance_signatures(name))
  end

  <<~RBS
    # Generated by support_table_data - do not edit by hand.
    # To update, run `bundle exec rake support_table_data:rbs`.
    class #{klass.name}
    #{body_lines.map { |line| line.empty? ? "" : "  #{line}" }.join("\n")}
    end
  RBS
end