class Tapioca::Compilers::Dsl::FrozenRecord
~~~
end
def last_name?; end
sig { returns(T::Boolean) }
def last_name; end
sig { returns(T.untyped) }
def id?; end
sig { returns(T::Boolean) }
def id; end
sig { returns(T.untyped) }
def first_name?; end
sig { returns(T::Boolean) }
def first_name; end
sig { returns(T.untyped) }
module Student::FrozenRecordAttributeMethods
end
include Student::FrozenRecordAttributeMethods
class Student
# typed: strong
# Student.rbi
~~~rbi
this generator will produce the RBI file ‘student.rbi` with the following content:
~~~
last_name: Lord
first_name: Dan
- id: 2
last_name: Smith
first_name: John
- id: 1
# students.yml
~~~ yaml
and the following YAML file:
~~~
end
class Student < FrozenRecord::Base
# student.rb
~~~rb
For example, with the following FrozenRecord class:
(see github.com/byroot/frozen_record).
`Tapioca::Compilers::Dsl::FrozenRecord` generates RBI files for subclasses of `FrozenRecord::Base`
def decorate(root, constant)
def decorate(root, constant) attributes = constant.attributes return if attributes.empty? module_name = "#{constant}::FrozenRecordAttributeMethods" root.create_module(module_name) do |mod| attributes.each do |attribute| create_method(mod, "#{attribute}?", return_type: 'T::Boolean') create_method(mod, attribute.to_s, return_type: 'T.untyped') end end root.path(constant) do |klass| klass.create_include(module_name) end end
def gather_constants
def gather_constants ::FrozenRecord::Base.descendants.reject(&:abstract_class?) end