Class: TypedConfig::SchemaBuilder

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/typed_config/schema_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(struct, rbi_builder: RBIBuilder.new) ⇒ SchemaBuilder

Returns a new instance of SchemaBuilder.



12
13
14
15
# File 'lib/typed_config/schema_builder.rb', line 12

def initialize(struct, rbi_builder: RBIBuilder.new)
  @rbi_builder = rbi_builder
  @struct = T.let(create_struct(Structs, struct), Class)
end

Instance Method Details

#build_rbi(schema_const_name) ⇒ Object



35
36
37
# File 'lib/typed_config/schema_builder.rb', line 35

def build_rbi(schema_const_name)
  rbi_builder.build(schema_const_name)
end

#const(name, type = nil, &blk) ⇒ Object

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
# File 'lib/typed_config/schema_builder.rb', line 24

def const(name, type = nil, &blk)
  clazz = retrieve_class(name: name, type: type, &blk)
  raise ArgumentError, "Attribute '#{name}' must receive a type or block." if clazz.nil?

  rbi_builder.add_const(struct, name, clazz)
  struct.tap do |scope|
    scope.const name, clazz
  end
end