Apply suggestions from code review
This commit is contained in:
parent
e4a1f3319c
commit
db39e939b0
@ -2,32 +2,26 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative "../../../global"
|
require_relative "../../../global"
|
||||||
require_relative "../../../utils/tty"
|
require "utils/tty"
|
||||||
|
|
||||||
module Tapioca
|
module Tapioca
|
||||||
module Compilers
|
module Compilers
|
||||||
class Tty < Tapioca::Dsl::Compiler
|
class Tty < Tapioca::Dsl::Compiler
|
||||||
# FIXME: Enable cop again when https://github.com/sorbet/sorbet/issues/3532 is fixed.
|
# FIXME: Enable cop again when https://github.com/sorbet/sorbet/issues/3532 is fixed.
|
||||||
# rubocop:disable Style/MutableConstant
|
# rubocop:disable Style/MutableConstant
|
||||||
# This should be a module whose singleton class contains RuboCop::AST::NodePattern::Macros,
|
|
||||||
# but I don't know how to express that in Sorbet.
|
|
||||||
ConstantType = type_member { { fixed: Module } }
|
ConstantType = type_member { { fixed: Module } }
|
||||||
# rubocop:enable Style/MutableConstant
|
# rubocop:enable Style/MutableConstant
|
||||||
|
|
||||||
sig { override.returns(T::Enumerable[Module]) }
|
sig { override.returns(T::Enumerable[Module]) }
|
||||||
def self.gather_constants
|
def self.gather_constants = [::Tty]
|
||||||
[::Tty]
|
|
||||||
end
|
|
||||||
|
|
||||||
sig { override.void }
|
sig { override.void }
|
||||||
def decorate
|
def decorate
|
||||||
root.create_module(constant.name) do |mod|
|
root.create_module(T.must(constant.name)) do |mod|
|
||||||
dynamic_methods = ::Tty::COLOR_CODES.keys + ::Tty::STYLE_CODES.keys + ::Tty::SPECIAL_CODES.keys
|
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|
|
dynamic_methods.each do |method|
|
||||||
return_type = (method.to_s.end_with?("?") ? "T::Boolean" : "String")
|
mod.create_method(method.to_s, return_type: "String", class_method: true)
|
||||||
mod.create_method(method.to_s, return_type:, class_method: true)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user