Class: Mortymer::Contract
- Inherits:
-
Dry::Validation::Contract
- Object
- Dry::Validation::Contract
- Mortymer::Contract
show all
- Includes:
- Moldeable, Types
- Defined in:
- lib/mortymer/contract.rb
Overview
A base model for defining schemas
Defined Under Namespace
Classes: ContractError
Constant Summary
Constants included
from Types
Types::UploadedFile, Types::UploadedFiles
Class Method Summary
collapse
Class Method Details
.__internal_struct_repr__ ⇒ Object
26
27
28
|
# File 'lib/mortymer/contract.rb', line 26
def self.__internal_struct_repr__
@__internal_struct_repr__ ||= StructCompiler.new.compile(schema.json_schema)
end
|
.compile! ⇒ Object
46
47
48
49
50
51
52
53
|
# File 'lib/mortymer/contract.rb', line 46
def self.compile!
__internal_struct_repr__
end
|
.structify(params) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/mortymer/contract.rb', line 34
def self.structify(params)
return params if params.instance_of?(__internal_struct_repr__)
params = params.to_h if params.is_a?(Dry::Struct)
result = new.call(params)
raise ContractError, result.errors.to_h unless result.errors.empty?
__internal_struct_repr__.new(**result.to_h)
end
|