Module: Scheming::DSL::TypeSpecs

Included in:
DataBuilder
Defined in:
lib/scheming/dsl/type_specs.rb

Overview

Type Specifications

These helpers allow for a more ergonomic resolution of types

Instance Method Summary collapse

Instance Method Details

#Enum(*values) ⇒ Object

rubocop:disable Naming/MethodName



9
10
11
# File 'lib/scheming/dsl/type_specs.rb', line 9

def Enum(*values) # rubocop:disable Naming/MethodName
  Scheming::DSL::TypeResolver.resolve(values.to_set)
end

#Nullable(type_spec) ⇒ Object

rubocop:disable Naming/MethodName



25
26
27
28
# File 'lib/scheming/dsl/type_specs.rb', line 25

def Nullable(type_spec) # rubocop:disable Naming/MethodName
  type = Scheming::DSL::TypeResolver.resolve(type_spec)
  Scheming::Type::Nullable.new(type)
end

#Object(**attributes) ⇒ Object

rubocop:disable Naming/MethodName



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/scheming/dsl/type_specs.rb', line 13

def Object(**attributes) # rubocop:disable Naming/MethodName
  attrs = attributes.map do |field_name, type_spec|
    Scheming::Attribute.new(
      field_name:,
      type: Scheming::DSL::TypeResolver.resolve(type_spec),
      is_required: true
    )
  end
  list = Scheming::Attribute::List.new(attrs)
  Scheming::Type::Object.new(list)
end