Class: TypedConfig::RBIBuilder
- Inherits:
-
Object
- Object
- TypedConfig::RBIBuilder
- Extended by:
- T::Sig
- Defined in:
- lib/typed_config/rbi_builder.rb
Instance Method Summary collapse
- #add_const(struct, name, type) ⇒ Object
- #add_struct(struct) ⇒ Object
- #build(schema_const_name) ⇒ Object
-
#initialize ⇒ RBIBuilder
constructor
A new instance of RBIBuilder.
Constructor Details
#initialize ⇒ RBIBuilder
Returns a new instance of RBIBuilder.
11 12 13 14 15 16 17 18 19 |
# File 'lib/typed_config/rbi_builder.rb', line 11 def initialize @structs = T.let( {}, T::Hash[ String, T::Array[{ name: Symbol, type: String }], ], ) end |
Instance Method Details
#add_const(struct, name, type) ⇒ Object
27 28 29 30 |
# File 'lib/typed_config/rbi_builder.rb', line 27 def add_const(struct, name, type) add_struct(struct) T.must(@structs[T.must(struct.name)]).push({ name: name, type: type.name }) end |
#add_struct(struct) ⇒ Object
22 23 24 |
# File 'lib/typed_config/rbi_builder.rb', line 22 def add_struct(struct) @structs[T.must(struct.name)] ||= [] end |
#build(schema_const_name) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/typed_config/rbi_builder.rb', line 33 def build(schema_const_name) b = binding b.local_variable_set(:schema_const_name, schema_const_name) b.local_variable_set(:structs, @structs) template_file = File.read(File.join(File.dirname(__FILE__), 'structs.rbi.erb')) ERB.new(template_file, trim_mode: '>').result(b) end |