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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1733f673e867c239bda30efbc34f45f7452ebbee12a702e201dffbcbb02f621
4
- data.tar.gz: 9ff44dd993b2ed7a82971437048731e80cb97b1a15d96fbdeb758d9797b6f3e4
3
+ metadata.gz: c0eb00a3e60d92a8d272157afe72dbb9512fbf9b7ccb8cfa2ea5304f9e058081
4
+ data.tar.gz: b9810cdf3c4e15d4942c18656b3d45aaefdde2798304610543adb739e67c97a8
5
5
  SHA512:
6
- metadata.gz: cd31959f30b91390ad9c40efb0fd18154e78829057df484a4b67c8efc5630f0ce97b3bfc47bff4c557bed421226311c6ad5cab077e1aa89da24d9b193defba51
7
- data.tar.gz: b9b604148b9ff54cde6cb26bc15d2752e2f8542a9df414cc1d9feb466d8f5e803697336fbfbffab1fb51d8de7b14a5c8a69f53ce3a50638b9df1e4fc36943814
6
+ metadata.gz: 669eeff9fa6da0866cbed09bf7e1f52b31b2a8451db278d40f7b8b4be184bfd3abae04307f750287a70aa6ce83429da74452d284cbc03d81a09adccb37d52be7
7
+ data.tar.gz: '09d2c7aba2808274d6a2a034b8227e622a5cb42104423e4545ba307c8021ae3e3d73461a5eece2e33d02f12f22f45bc343dd28e63ec1ee6c3f49c96d7daef8af'
@@ -24,7 +24,7 @@ module Mortymer
24
24
  end
25
25
 
26
26
  def self.__internal_struct_repr__
27
- @__internal_struct_repr__ || StructCompiler.new.compile(schema.json_schema)
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
 
@@ -24,7 +24,13 @@ module Mortymer
24
24
  end
25
25
 
26
26
  def [](key)
27
- @attributes[key.to_sym]
27
+ public_send(key)
28
28
  end
29
+
30
+ def key?(attr)
31
+ attributes.key?(attr.to_sym)
32
+ end
33
+
34
+ alias has_key? key?
29
35
  end
30
36
  end
@@ -45,7 +45,15 @@ module Mortymer
45
45
  end
46
46
 
47
47
  begin
48
- procced_args << (type.respond_to?(:structify) ? type.structify(arg) : type.call(arg))
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
- return return_type.respond_to?(:structify) ? return_type.structify(result) : return_type.call(result)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mortymer
4
- VERSION = "0.0.12"
4
+ VERSION = "0.0.13"
5
5
  end
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.12
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-05 00:00:00.000000000 Z
10
+ date: 2025-04-08 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: dry-struct