foobara 0.0.22 → 0.0.24

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc681307752b396bf7baaf20856fbdf5107da406b112b5c15039ca915859a497
4
- data.tar.gz: d779a8020d0e65156965a9a32c7f8b9f1c0daebbcedb3795917701feb3b7c845
3
+ metadata.gz: 53375c9393cbdf5594959c3233650f0cd08b78fc2bf3a07863debcdf12c4f2d9
4
+ data.tar.gz: 388d748e47be7c602bd79661f1265ecb276b290f067e7c8114231d8a8cb5319f
5
5
  SHA512:
6
- metadata.gz: fafb15435c334846fdd3f1d233abfbe8a93b02bba7374f91026555fcd7a3fd97b47fa24825a0e72dcafa0ac64688c9accead19c9c44d427ec62c707e70986016
7
- data.tar.gz: 9ff12cb0f19aaf131808200a6196681c9c9ddec9febbf0fae0c7ff008439895243da0cf4cb068cb10bb2a162f58049eb35437aaa777a1724d5a3adf1df6d5f4f
6
+ metadata.gz: 7ce8fdd0b10b5ab7935c8f41dd461be81bbcd9805ead1c81619abafb4f169bf8e38c592818da7f0a0969fde1da214ba7f718e78d70e042b3279facf4224d8c30
7
+ data.tar.gz: 72beca35aa357bb745d2fdf61b910d8aeba8f51d7fd897e1f94cba02191a41cdacf1c08ff38085da8f094d6e8bf56629bd4a607fc7a1b49ff38d162c6a7c0a5f
data/CHANGELOG.md CHANGED
@@ -1,6 +1,8 @@
1
- ## [0.0.22] - 2024-12-03
1
+ ## [0.0.24] - 2024-12-03
2
2
 
3
+ - Allow passing all Error subclass parameters into possible_*error calls
3
4
  - Allow creating entity types from declaration without model_module
5
+ - Make model classes with an mutable of false have instances that default to immutable
4
6
 
5
7
  ## [0.0.21] - 2024-12-02
6
8
 
@@ -41,8 +41,13 @@ module Foobara
41
41
  # :nocov:
42
42
  end
43
43
  when 2
44
- symbol, error_class_or_context_type_declaration, data = args
45
- error_class = to_runtime_error_class(symbol, error_class_or_context_type_declaration)
44
+ symbol, subclass_parameters, data = args
45
+
46
+ error_class = Foobara::RuntimeError.subclass(
47
+ **subclass_parameters,
48
+ symbol:
49
+ )
50
+
46
51
  PossibleError.new(error_class, symbol:, data:)
47
52
  else
48
53
  # :nocov:
@@ -56,20 +61,18 @@ module Foobara
56
61
  def possible_input_error(
57
62
  path,
58
63
  symbol_or_error_class,
59
- error_class_or_context_type_declaration = {},
64
+ error_class_or_subclass_parameters = {},
60
65
  data = nil
61
66
  )
62
- error_class, symbol = if symbol_or_error_class.is_a?(Class)
63
- [symbol_or_error_class, symbol_or_error_class.symbol]
64
- else
65
- [
66
- to_input_error_class(
67
- symbol_or_error_class,
68
- error_class_or_context_type_declaration
69
- ),
70
- symbol_or_error_class
71
- ]
72
- end
67
+ error_class = if symbol_or_error_class.is_a?(Class)
68
+ symbol_or_error_class
69
+ else
70
+ Foobara::DataError.subclass(
71
+ **error_class_or_subclass_parameters, symbol: symbol_or_error_class
72
+ )
73
+ end
74
+
75
+ symbol = error_class.symbol
73
76
 
74
77
  possible_error = PossibleError.new(error_class, symbol:, data:)
75
78
  possible_error.prepend_path!(path)
@@ -102,21 +105,6 @@ module Foobara
102
105
  key = possible_error.key.to_s
103
106
  error_context_type_map.delete(key)
104
107
  end
105
-
106
- # TODO: should we cache these???
107
- def to_input_error_class(symbol, context_type_declaration)
108
- Foobara::Value::DataError.subclass(
109
- symbol:,
110
- context_type_declaration:
111
- )
112
- end
113
-
114
- def to_runtime_error_class(symbol, context_type_declaration)
115
- Foobara::RuntimeError.subclass(
116
- symbol:,
117
- context_type_declaration:
118
- )
119
- end
120
108
  end
121
109
  end
122
110
  end
@@ -93,7 +93,7 @@ module Foobara
93
93
 
94
94
  def subclass(
95
95
  # TODO: technically context_type_declaration doesn't belong here. But maybe it should.
96
- context_type_declaration:,
96
+ context: {},
97
97
  name: nil,
98
98
  symbol: nil,
99
99
  message: nil,
@@ -120,7 +120,7 @@ module Foobara
120
120
  end
121
121
 
122
122
  singleton_class.define_method :context_type_declaration do
123
- context_type_declaration
123
+ context
124
124
  end
125
125
 
126
126
  if message
@@ -207,8 +207,14 @@ module Foobara
207
207
  end
208
208
  end
209
209
 
210
- # why do we default to true here but false in the transformers?
211
- mutable = options.key?(:mutable) ? options[:mutable] : true
210
+ mutable = if options.key?(:mutable)
211
+ options[:mutable]
212
+ elsif self.class.model_type.declaration_data.key?(:mutable)
213
+ self.class.model_type.declaration_data[:mutable]
214
+ else
215
+ # why do we default to true here but false in the transformers?
216
+ true
217
+ end
212
218
 
213
219
  self.mutable = if mutable.is_a?(::Array)
214
220
  mutable.map(&:to_sym)
@@ -228,7 +234,7 @@ module Foobara
228
234
  def write_attribute(attribute_name, value)
229
235
  attribute_name = attribute_name.to_sym
230
236
 
231
- if mutable == true || mutable&.include?(attribute_name)
237
+ if mutable == true || (mutable != false && mutable&.include?(attribute_name))
232
238
  outcome = cast_attribute(attribute_name, value)
233
239
  attributes[attribute_name] = outcome.success? ? outcome.result : value
234
240
  else
@@ -24,4 +24,6 @@ module Foobara
24
24
  end
25
25
  end
26
26
  end
27
+
28
+ DataError = Value::DataError
27
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.22
4
+ version: 0.0.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi