mortymer 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mortymer/contract.rb +6 -1
- data/lib/mortymer/model.rb +7 -1
- data/lib/mortymer/sigil.rb +21 -2
- data/lib/mortymer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0eb00a3e60d92a8d272157afe72dbb9512fbf9b7ccb8cfa2ea5304f9e058081
|
4
|
+
data.tar.gz: b9810cdf3c4e15d4942c18656b3d45aaefdde2798304610543adb739e67c97a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 669eeff9fa6da0866cbed09bf7e1f52b31b2a8451db278d40f7b8b4be184bfd3abae04307f750287a70aa6ce83429da74452d284cbc03d81a09adccb37d52be7
|
7
|
+
data.tar.gz: '09d2c7aba2808274d6a2a034b8227e622a5cb42104423e4545ba307c8021ae3e3d73461a5eece2e33d02f12f22f45bc343dd28e63ec1ee6c3f49c96d7daef8af'
|
data/lib/mortymer/contract.rb
CHANGED
@@ -24,7 +24,7 @@ module Mortymer
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.__internal_struct_repr__
|
27
|
-
@__internal_struct_repr__
|
27
|
+
@__internal_struct_repr__ ||= StructCompiler.new.compile(schema.json_schema)
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.json_schema
|
@@ -32,6 +32,11 @@ module Mortymer
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.structify(params)
|
35
|
+
# If params are already built using the internal struct, then there is
|
36
|
+
# no need to re-validate it
|
37
|
+
return params if params.instance_of?(__internal_struct_repr__)
|
38
|
+
|
39
|
+
params = params.to_h if params.is_a?(Dry::Struct)
|
35
40
|
result = new.call(params)
|
36
41
|
raise ContractError, result.errors.to_h unless result.errors.empty?
|
37
42
|
|
data/lib/mortymer/model.rb
CHANGED
data/lib/mortymer/sigil.rb
CHANGED
@@ -45,7 +45,15 @@ module Mortymer
|
|
45
45
|
end
|
46
46
|
|
47
47
|
begin
|
48
|
-
procced_args <<
|
48
|
+
procced_args << if type.respond_to?(:structify)
|
49
|
+
type.structify(arg)
|
50
|
+
elsif type.respond_to?(:call)
|
51
|
+
type.call(arg)
|
52
|
+
elsif arg.is_a?(type)
|
53
|
+
arg
|
54
|
+
else
|
55
|
+
raise TypeError, "Invalid type for argument #{idx}: expected #{type}, got #{arg.class}"
|
56
|
+
end
|
49
57
|
rescue Dry::Types::CoercionError => e
|
50
58
|
raise TypeError, "Invalid type for argument #{idx}: expected #{type}, got #{arg.class} - #{e.message}"
|
51
59
|
end
|
@@ -72,7 +80,18 @@ module Mortymer
|
|
72
80
|
# Validate return type if specified
|
73
81
|
if (return_type = signature[:returns])
|
74
82
|
begin
|
75
|
-
|
83
|
+
# A mortymer model or contract
|
84
|
+
if return_type.respond_to?(:structify)
|
85
|
+
return return_type.structify(result)
|
86
|
+
# A dry type
|
87
|
+
elsif return_type.respond_to?(:call)
|
88
|
+
return return_type.call(result)
|
89
|
+
# A custom object
|
90
|
+
elsif result.is_a?(return_type)
|
91
|
+
return result
|
92
|
+
else
|
93
|
+
raise TypeError, "Invalid return type: expected #{return_type}, got #{result.class}"
|
94
|
+
end
|
76
95
|
rescue Dry::Types::CoercionError => e
|
77
96
|
raise TypeError, "Invalid return type: expected #{return_type}, got #{result.class} - #{e.message}"
|
78
97
|
end
|
data/lib/mortymer/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mortymer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Gonzalez
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-04-
|
10
|
+
date: 2025-04-08 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: dry-struct
|