class Tapioca::Dsl::Compilers::Kredis

: [ConstantType = (Class & ::Kredis::Attributes::ClassMethods & Extensions::Kredis)]
~~~
end
end
end
def bright?; end
sig { returns(T::Boolean) }
def bright!; end
sig { void }
def blue?; end
sig { returns(T::Boolean) }
def blue!; end
sig { void }
def black?; end
sig { returns(T::Boolean) }
def black!; end
sig { void }
class PrivateEnumMorning < Kredis::Types::Enum
def steps; end
sig { returns(Kredis::Types::Counter) }
def names; end
sig { returns(Kredis::Types::List) }
def morning; end
sig { returns(PrivateEnumMorning) }
def awesome?; end
sig { returns(T::Boolean) }
def awesome; end
sig { returns(Kredis::Types::Flag) }
module GeneratedKredisAttributeMethods
class Person
# typed: true
~~~rbi
this compiler will produce an RBI file with the following content:
~~~
end
kredis_enum :morning, values: %w[ bright blue black ], default: “bright”
kredis_counter :steps, expires_in: 1.hour
kredis_flag :awesome
kredis_list :names
class Person < ApplicationRecord
~~~rb
For example, with the following class:
classes that include [‘Kredis::Attributes`](github.com/rails/kredis/blob/main/lib/kredis/attributes.rb).
`Tapioca::Dsl::Compilers::Kredis` decorates RBI files for all

def create_enum_class(mod, klass_name, values)

: (RBI::Scope mod, String klass_name, Array[untyped] values) -> void
def create_enum_class(mod, klass_name, values)
  klass = mod.create_class(klass_name, superclass_name: "Kredis::Types::Enum")
  values.each do |value|
    klass.create_method("#{value}!", return_type: "void")
    klass.create_method("#{value}?", return_type: "T::Boolean")
  end
end

def decorate

: -> void
@override
def decorate
  return if constant.__tapioca_kredis_types.nil?
  module_name = "GeneratedKredisAttributeMethods"
  root.create_path(constant) do |model|
    model.create_module(module_name) do |mod|
      constant.__tapioca_kredis_types.each do |method, data|
        generate_methods(mod, method, data)
      end
    end
    model.create_include(module_name)
  end
end

def gather_constants

: -> T::Enumerable[Module]
@override
def gather_constants
  all_classes
    .grep(::Kredis::Attributes::ClassMethods)
    .reject { |klass| klass.to_s == "ActiveRecord::Base" || klass.try(:abstract_class?) }
end

def generate_methods(mod, method, data)

: (RBI::Scope mod, String method, Hash[Symbol, untyped] data) -> void
def generate_methods(mod, method, data)
  return_type = data.fetch(:type)
  case return_type
  when "Kredis::Types::Enum"
    klass_name = "PrivateEnum#{method.split("_").map(&:capitalize).join}"
    create_enum_class(mod, klass_name, data.fetch(:values))
    return_type = klass_name
  when "Kredis::Types::Flag"
    mod.create_method("#{method}?", return_type: "T::Boolean")
  end
  mod.create_method(method, return_type: return_type)
end