
- The preferred way of doing RBI generation is via Tapioca. So I am trying to stop being intimidated by it, by learning how it works. - This is very WIP still, currently failing with the following message because the `module` name is missing in the generated RBI file. ``` There are parse errors in the generated RBI files. Errors: sorbet/rbi/dsl/tty.rbi:8: unexpected token tNL (2001) sorbet/rbi/dsl/tty.rbi:64: unexpected token "end" (2001) ```
32 lines
890 B
Ruby
32 lines
890 B
Ruby
# typed: strict
|
|
# frozen_string_literal: true
|
|
|
|
require_relative "../../../global"
|
|
require_relative "../../../utils/tty"
|
|
|
|
module Tapioca
|
|
module Compilers
|
|
class Tty < Tapioca::Dsl::Compiler
|
|
ConstantType = type_member { { fixed: Module } }
|
|
|
|
sig { override.returns(T::Enumerable[Module]) }
|
|
def self.gather_constants
|
|
[::Tty]
|
|
end
|
|
|
|
sig { override.void }
|
|
def decorate
|
|
root.create_path(constant) do |klass|
|
|
dynamic_methods = ::Tty::COLOR_CODES.keys + ::Tty::STYLE_CODES.keys + ::Tty::SPECIAL_CODES.keys
|
|
methods = ::Tty.methods(false).sort.select { |method| dynamic_methods.include?(method) }
|
|
|
|
methods.each do |method|
|
|
return_type = (method.to_s.end_with?("?") ? "T::Boolean" : "String")
|
|
klass.create_method(method.to_s, return_type:)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|