Module: StructuraidCore::DesignCodes::Utils::SchemaDefinition::ClassMethods

Defined in:
lib/structuraid_core/design_codes/utils/schema_definition.rb

Instance Method Summary collapse

Instance Method Details

#enum_paramsObject



37
38
39
# File 'lib/structuraid_core/design_codes/utils/schema_definition.rb', line 37

def enum_params
  @enum_params
end

#optionalObject



33
34
35
# File 'lib/structuraid_core/design_codes/utils/schema_definition.rb', line 33

def optional
  @optional
end

#requiredObject



29
30
31
# File 'lib/structuraid_core/design_codes/utils/schema_definition.rb', line 29

def required
  @required
end

#structurize(params) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/structuraid_core/design_codes/utils/schema_definition.rb', line 20

def structurize(params)
  structured_args_names = [*required, *optional]
  structured_klass = Struct.new(*structured_args_names, :schema, keyword_init: true)
  sliced_params = params.slice(*structured_args_names)
  sliced_params.merge!(schema: name)

  structured_klass.new(sliced_params)
end

#validate!(params) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/structuraid_core/design_codes/utils/schema_definition.rb', line 12

def validate!(params)
  validate_required_params!(params)
  validate_optional_params!(params)
  validate_enum_params!(params)

  true
end