foobara 0.0.49 → 0.0.51

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: c906fa3ff55b19d33976a861a7d249aaf8b869507ba845cd8743459653fc117f
4
- data.tar.gz: 86da929e2ed3d0b478067f27e7605060941a593eb8c5c95298304d3cf048fc45
3
+ metadata.gz: e82271074f7658b6b54239b1ba4e79c944baca14bc63af1fd48e7b5d5c418043
4
+ data.tar.gz: f5f0dcd5bcd9e553dbcdbab70f4e9388ab98c99b4359aca8bfaf4d32fad89e7a
5
5
  SHA512:
6
- metadata.gz: 04424105e5a0d9788839c40c3689ae34d8f1c39192128cf6e30a8c85e326fb3f5aa0b02a11cec7ac374ae62862cd941bb774db423d01e6e912b4a1a21977b3c2
7
- data.tar.gz: 4030da0e998f344b19a453a624481189dbf432654c8af7a63a5197eeeb281d7a64df683c4babfcb59abad342a5b436036d61eda8bb760a0d011aa30cac1b780b
6
+ metadata.gz: 33ce048fb57a1c12811756a5d1b9238b0b79587993d6f45323f65294cca6bcd46d33bc281e9021070c21e6f5852e9066927cb8e78a7f2f62c29b3e705ab95e4c
7
+ data.tar.gz: 59cde8f01b6c5e74e69b78e951ea74cb4f85eecb9f41b1f7a1c79cd6f9f5ce4e492109c8b860aefcfd73f832355e0a912796d10b0e3a67d456921b06a7da62ed
data/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
- ## [0.0.49] - 2025-01-21
1
+ ## [0.0.51] - 2025-01-26
2
+
3
+ - Add a Type#remove_processor_by_symbol method to help with certain situations when defining custom types
4
+
5
+ ## [0.0.50] - 2025-01-22
2
6
 
3
7
  - Fill out more foobara_ model attribute helper methods to further support the ActiveRecordType gem
4
8
 
@@ -25,7 +25,11 @@ module Foobara
25
25
  end
26
26
  end
27
27
 
28
- rawish_type_declaration[:defaults] = defaults unless defaults.empty?
28
+ if defaults.empty?
29
+ rawish_type_declaration.delete(:defaults)
30
+ else
31
+ rawish_type_declaration[:defaults] = defaults
32
+ end
29
33
 
30
34
  rawish_type_declaration
31
35
  end
@@ -40,7 +40,11 @@ module Foobara
40
40
  end
41
41
  end
42
42
 
43
- rawish_type_declaration[:required] = required_attributes unless required_attributes.empty?
43
+ if required_attributes.empty?
44
+ rawish_type_declaration.delete(:required)
45
+ else
46
+ rawish_type_declaration[:required] = required_attributes
47
+ end
44
48
 
45
49
  rawish_type_declaration
46
50
  end
@@ -25,6 +25,16 @@ module Foobara
25
25
  @inputs_type
26
26
  end
27
27
 
28
+ def add_inputs(...)
29
+ new_type = type_for_declaration(...)
30
+ new_declaration = TypeDeclarations::Attributes.merge(
31
+ inputs_type.declaration_data,
32
+ new_type.declaration_data
33
+ )
34
+
35
+ inputs new_declaration
36
+ end
37
+
28
38
  def inputs_type
29
39
  return @inputs_type if defined?(@inputs_type)
30
40
 
@@ -4,7 +4,6 @@ module Foobara
4
4
  module CommandConnectors
5
5
  module Serializers
6
6
  class SuccessSerializer < Serializer
7
- # TODO: always_applicable? instead?
8
7
  def always_applicable?
9
8
  request.outcome.success?
10
9
  end
@@ -25,8 +25,8 @@ module Foobara
25
25
  respond_to?(:foobara_primary_key_attribute)
26
26
  end
27
27
 
28
- def foobara_attributes_for_update
29
- foobara_attributes_for_aggregate_update
28
+ def foobara_attributes_for_update(require_primary_key: false)
29
+ foobara_attributes_for_aggregate_update(require_primary_key:)
30
30
  end
31
31
 
32
32
  # TODO: we should have metadata on the entity about whether it required a primary key
@@ -35,39 +35,24 @@ module Foobara
35
35
  return foobara_attributes_type if includes_primary_key
36
36
  return foobara_attributes_type unless foobara_has_primary_key?
37
37
 
38
- primary_key_attribute = foobara_primary_key_attribute
39
-
40
- declaration = attributes_type.declaration_data
41
- # TODO: just slice out the element type declarations
42
- declaration = Util.deep_dup(declaration)
43
-
44
- declaration[:element_type_declarations].delete(primary_key_attribute)
45
-
46
- if declaration.key?(:required)
47
- declaration[:required].delete(primary_key_attribute)
48
- end
49
-
50
- if declaration.key?(:defaults)
51
- declaration[:defaults].delete(primary_key_attribute)
52
- end
53
-
54
- handler = Domain.global.foobara_type_builder.handler_for_class(
55
- TypeDeclarations::Handlers::ExtendAttributesTypeDeclaration
56
- )
38
+ declaration = foobara_attributes_type.declaration_data
57
39
 
58
- handler.desugarize(declaration)
40
+ Foobara::TypeDeclarations::Attributes.reject(declaration, foobara_primary_key_attribute)
59
41
  end
60
42
 
61
- def foobara_attributes_for_aggregate_update(initial = true)
43
+ def foobara_attributes_for_aggregate_update(require_primary_key: false, initial: true)
62
44
  declaration = foobara_attributes_type.declaration_data
63
- # TODO: just slice out the element type declarations
64
45
  declaration = Util.deep_dup(declaration)
65
46
 
66
47
  declaration.delete(:defaults)
67
48
  declaration.delete(:required)
68
49
 
69
50
  if initial && foobara_has_primary_key?
70
- declaration[:required] = [foobara_primary_key_attribute]
51
+ if require_primary_key
52
+ declaration[:required] = [foobara_primary_key_attribute]
53
+ else
54
+ TypeDeclarations::Attributes.reject(declaration, foobara_primary_key_attribute)
55
+ end
71
56
  end
72
57
 
73
58
  foobara_associations.each_pair do |data_path, type|
@@ -76,21 +61,25 @@ module Foobara
76
61
 
77
62
  entry = foobara_type_declaration_value_at(declaration, DataPath.new(data_path).path)
78
63
  entry.clear
79
- entry.merge!(target_class.foobara_attributes_for_aggregate_update(false))
64
+ entry.merge!(target_class.foobara_attributes_for_aggregate_update(initial: false))
80
65
  end
81
66
  end
82
67
 
83
68
  declaration
84
69
  end
85
70
 
86
- def foobara_attributes_for_atom_update
71
+ def foobara_attributes_for_atom_update(require_primary_key: false)
87
72
  declaration = foobara_attributes_type.declaration_data
88
- # TODO: just slice out the element type declarations
89
73
  declaration = Util.deep_dup(declaration)
90
74
 
91
75
  declaration.delete(:defaults)
76
+
92
77
  if foobara_has_primary_key?
93
- declaration[:required] = [foobara_primary_key_attribute]
78
+ if require_primary_key
79
+ declaration[:required] = [foobara_primary_key_attribute]
80
+ else
81
+ declaration = TypeDeclarations::Attributes.reject(declaration, foobara_primary_key_attribute)
82
+ end
94
83
  end
95
84
 
96
85
  # expect all associations to be expressed as primary key values
@@ -21,12 +21,55 @@ module Foobara
21
21
  end
22
22
  end
23
23
 
24
- {
24
+ handler = Domain.global.foobara_type_builder.handler_for_class(
25
+ TypeDeclarations::Handlers::ExtendAttributesTypeDeclaration
26
+ )
27
+
28
+ handler.desugarize(
25
29
  type: "::attributes",
26
30
  element_type_declarations:,
27
31
  required:,
28
32
  defaults:
29
- }
33
+ )
34
+ end
35
+
36
+ def reject(declaration, *keys)
37
+ declaration = Util.deep_dup(declaration)
38
+
39
+ element_type_declarations = declaration[:element_type_declarations]
40
+ required = declaration[:required]
41
+ defaults = declaration[:defaults]
42
+
43
+ changed = false
44
+
45
+ keys.flatten.each do |key|
46
+ key = key.to_sym
47
+
48
+ if element_type_declarations.key?(key)
49
+ changed = true
50
+ element_type_declarations.delete(key)
51
+ end
52
+
53
+ if required&.include?(key)
54
+ changed = true
55
+ required.delete(key)
56
+ end
57
+
58
+ if defaults&.key?(key)
59
+ changed = true
60
+ defaults.delete(key)
61
+ end
62
+ end
63
+
64
+ if changed
65
+ handler = Domain.global.foobara_type_builder.handler_for_class(
66
+ TypeDeclarations::Handlers::ExtendAttributesTypeDeclaration
67
+ )
68
+
69
+ handler.desugarize(declaration)
70
+ else
71
+ declaration
72
+ end
30
73
  end
31
74
  end
32
75
  end
@@ -47,7 +47,6 @@ module Foobara
47
47
 
48
48
  def _to_declaration(&)
49
49
  instance_eval(&)
50
- _prune_type_declaration
51
50
  _type_declaration
52
51
  end
53
52
 
@@ -163,30 +162,20 @@ module Foobara
163
162
  end
164
163
 
165
164
  def _add_to_required(attribute_name)
165
+ _type_declaration[:required] ||= []
166
166
  _type_declaration[:required] << attribute_name.to_sym
167
167
  end
168
168
 
169
169
  def _add_to_defaults(attribute_name, value)
170
+ _type_declaration[:defaults] ||= {}
170
171
  _type_declaration[:defaults][attribute_name.to_sym] = value
171
172
  end
172
173
 
173
- def _prune_type_declaration
174
- if _type_declaration[:required].empty?
175
- _type_declaration.delete(:required)
176
- end
177
-
178
- if _type_declaration[:defaults].empty?
179
- _type_declaration.delete(:defaults)
180
- end
181
- end
182
-
183
174
  def _type_declaration
184
175
  @_type_declaration ||= begin
185
176
  sugar = {
186
177
  type: "::attributes",
187
- element_type_declarations: {},
188
- required: [],
189
- defaults: {}
178
+ element_type_declarations: {}
190
179
  }
191
180
 
192
181
  handler = Domain.current.foobara_type_builder.handler_for_class(Handlers::ExtendAttributesTypeDeclaration)
@@ -101,6 +101,21 @@ module Foobara
101
101
  end
102
102
  end
103
103
 
104
+ def remove_processor_by_symbol(symbol)
105
+ [
106
+ casters,
107
+ element_processors,
108
+ processor_classes_requiring_type,
109
+ processors,
110
+ transformers,
111
+ validators
112
+ ].each do |processor_collection|
113
+ processor_collection&.delete_if { |p| p.symbol == symbol }
114
+ end
115
+ supported_processor_classes&.each { |processor_hash| processor_hash.delete(symbol) }
116
+ processor_classes_requiring_type&.delete_if { |p| p.symbol == symbol }
117
+ end
118
+
104
119
  def each_processor_class_requiring_type(&block)
105
120
  base_type&.each_processor_class_requiring_type(&block)
106
121
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.49
4
+ version: 0.0.51
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-21 00:00:00.000000000 Z
10
+ date: 2025-01-27 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bigdecimal