foobara 0.0.38 → 0.0.39

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.
@@ -20,29 +20,50 @@ module Foobara
20
20
 
21
21
  builtin_type_module = const_get(module_symbol, false)
22
22
 
23
+ processor_classes_requiring_type = []
24
+
23
25
  casters_module = Util.constant_value(builtin_type_module, :Casters)
24
26
  caster_classes = if casters_module
25
27
  Util.constant_values(casters_module, extends: Value::Processor)
26
28
  end
27
- casters = caster_classes&.map do |caster_class|
28
- caster_class.new_with_agnostic_args(parent_declaration_data: declaration_data)
29
+ casters = []
30
+ caster_classes&.each do |caster_class|
31
+ if caster_class.respond_to?(:requires_type?) && caster_class.requires_type?
32
+ processor_classes_requiring_type << caster_class
33
+ else
34
+ casters << caster_class.new_with_agnostic_args(parent_declaration_data: declaration_data)
35
+ end
29
36
  end
30
37
 
31
38
  transformers_module = Util.constant_value(builtin_type_module, :Transformers)
32
39
  transformer_classes = if transformers_module
33
40
  Util.constant_values(transformers_module, extends: Value::Processor)
34
41
  end
35
- transformers = transformer_classes&.map do |transformer_class|
36
- transformer_class.new_with_agnostic_args(parent_declaration_data: declaration_data)
37
- end || []
42
+ transformers = []
43
+ transformer_classes&.each do |transformer_class|
44
+ if transformer_class.respond_to?(:requires_type?) && transformer_class.requires_type?
45
+ # :nocov:
46
+ processor_classes_requiring_type << transformer_class
47
+ # :nocov:
48
+ else
49
+ transformers << transformer_class.new_with_agnostic_args(parent_declaration_data: declaration_data)
50
+ end
51
+ end
38
52
 
39
53
  validators_module = Util.constant_value(builtin_type_module, :Validators)
40
54
  validator_classes = if validators_module
41
55
  Util.constant_values(validators_module, extends: Value::Processor)
42
56
  end
43
- validators = validator_classes&.map do |validator_class|
44
- validator_class.new_with_agnostic_args(parent_declaration_data: declaration_data)
45
- end || []
57
+ validators = []
58
+ validator_classes&.each do |validator_class|
59
+ if validator_class.respond_to?(:requires_type?) && validator_class.requires_type?
60
+ # :nocov:
61
+ processor_classes_requiring_type << validator_class
62
+ # :nocov:
63
+ else
64
+ validators << validator_class.new_with_agnostic_args(parent_declaration_data: declaration_data)
65
+ end
66
+ end
46
67
 
47
68
  type = Foobara::Types::Type.new(
48
69
  declaration_data,
@@ -54,7 +75,8 @@ module Foobara
54
75
  # TODO: this is for controlling casting or not casting but could give the wrong information from a
55
76
  # reflection point of view...
56
77
  target_classes:,
57
- description:
78
+ description:,
79
+ processor_classes_requiring_type:
58
80
  )
59
81
 
60
82
  add_builtin_type(type)
@@ -13,6 +13,7 @@ module Foobara
13
13
  type = outcome.result
14
14
  entity_class = type.target_class
15
15
 
16
+ # TODO: is this duplicated??
16
17
  unless entity_class.primary_key_attribute
17
18
  entity_class.primary_key(strict_declaration_type[:primary_key])
18
19
  end
@@ -0,0 +1,39 @@
1
+ module Foobara
2
+ module BuiltinTypes
3
+ module Entity
4
+ module Casters
5
+ class PrimaryKey < Value::Caster
6
+ class << self
7
+ def requires_declaration_data?
8
+ true
9
+ end
10
+
11
+ def requires_type?
12
+ true
13
+ end
14
+ end
15
+
16
+ def entity_class
17
+ declaration_data.target_class
18
+ end
19
+
20
+ def primary_key_type
21
+ entity_class.primary_key_type
22
+ end
23
+
24
+ def applicable?(value)
25
+ primary_key_type.applicable?(value)
26
+ end
27
+
28
+ def transform(primary_key)
29
+ entity_class.thunk(primary_key)
30
+ end
31
+
32
+ def applies_message
33
+ primary_key_type.value_caster.applies_message
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -3,35 +3,6 @@ module Foobara
3
3
  module Handlers
4
4
  class ExtendEntityTypeDeclaration < ExtendDetachedEntityTypeDeclaration
5
5
  class ToTypeTransformer < ExtendDetachedEntityTypeDeclaration::ToTypeTransformer
6
- # TODO: move this to a more appropriate place
7
- class EntityPrimaryKeyCaster < Value::Caster
8
- class << self
9
- def requires_declaration_data?
10
- true
11
- end
12
- end
13
-
14
- def entity_class
15
- declaration_data
16
- end
17
-
18
- def primary_key_type
19
- entity_class.primary_key_type
20
- end
21
-
22
- def applicable?(value)
23
- primary_key_type.applicable?(value)
24
- end
25
-
26
- def transform(primary_key)
27
- entity_class.thunk(primary_key)
28
- end
29
-
30
- def applies_message
31
- primary_key_type.value_caster.applies_message
32
- end
33
- end
34
-
35
6
  def process_value(strict_declaration_type)
36
7
  super.tap do |outcome|
37
8
  if outcome.success?
@@ -43,8 +14,6 @@ module Foobara
43
14
  caster.is_a?(Foobara::BuiltinTypes::Entity::Casters::Hash)
44
15
  end
45
16
  end
46
-
47
- type.casters << EntityPrimaryKeyCaster.new(entity_class)
48
17
  end
49
18
  end
50
19
  end
@@ -2,9 +2,13 @@ module Foobara
2
2
  module BuiltinTypes
3
3
  module Model
4
4
  # TODO: Create Mutations/SupportedMutations concept
5
- class Transformers
5
+ class SupportedTransformers
6
6
  class Mutable < TypeDeclarations::Transformer
7
7
  class << self
8
+ def requires_declaration_data?
9
+ true
10
+ end
11
+
8
12
  def requires_parent_declaration_data?
9
13
  true
10
14
  end
@@ -7,6 +7,10 @@ module Foobara
7
7
  def requires_parent_declaration_data?
8
8
  true
9
9
  end
10
+
11
+ def requires_declaration_data?
12
+ false
13
+ end
10
14
  end
11
15
 
12
16
  def always_applicable?
@@ -16,7 +16,7 @@ module Foobara
16
16
  # TODO: create declaration validator for name and the others
17
17
  # TODO: seems like a smell that we don't have processors for these?
18
18
  def non_processor_keys
19
- [:name, :model_class, :model_base_class, :model_module, :attributes_declaration, :mutable, *super]
19
+ [:name, :model_class, :model_base_class, :model_module, :attributes_declaration, *super]
20
20
  end
21
21
 
22
22
  def process_value(...)
@@ -16,10 +16,6 @@ module Foobara
16
16
  def declaration_to_type(strict_type_declaration)
17
17
  type_for_declaration(strict_type_declaration[:type])
18
18
  end
19
-
20
- def non_processor_keys
21
- [:mutable, *super]
22
- end
23
19
  end
24
20
  end
25
21
  end
@@ -25,7 +25,8 @@ module Foobara
25
25
  :raw_declaration_data,
26
26
  :name,
27
27
  :target_classes,
28
- :description
28
+ :description,
29
+ :processor_classes_requiring_type
29
30
  attr_reader :type_symbol
30
31
 
31
32
  def initialize(
@@ -41,6 +42,7 @@ module Foobara
41
42
  element_type: nil,
42
43
  element_types: nil,
43
44
  structure_count: nil,
45
+ processor_classes_requiring_type: nil,
44
46
  **opts
45
47
  )
46
48
  self.base_type = base_type
@@ -56,12 +58,57 @@ module Foobara
56
58
  self.element_type = element_type
57
59
  self.name = name
58
60
  self.target_classes = Util.array(target_classes)
61
+ self.processor_classes_requiring_type = processor_classes_requiring_type
59
62
 
60
63
  super(*, **opts.merge(processors:, prioritize: false))
61
64
 
65
+ apply_all_processors_needing_type!
66
+
62
67
  validate_processors!
63
68
  end
64
69
 
70
+ def apply_all_processors_needing_type!
71
+ each_processor_class_requiring_type do |processor_class|
72
+ # TODO: is this a smell?
73
+ processor = processor_class.new(self)
74
+
75
+ category = case processor
76
+ when Value::Caster
77
+ casters
78
+ when Value::Validator
79
+ # :nocov:
80
+ validators
81
+ # :nocov:
82
+ when Value::Transformer
83
+ # :nocov:
84
+ transformers
85
+ # :nocov:
86
+ when Types::ElementProcessor
87
+ # :nocov:
88
+ element_processors
89
+ # :nocov:
90
+ else
91
+ # TODO: add validator that these are all fine so we don't have to bother here...
92
+ # :nocov:
93
+ raise "Not sure where to put #{processor}"
94
+ # :nocov:
95
+ end
96
+
97
+ symbol = processor.symbol
98
+ category.delete_if { |p| p.symbol == symbol }
99
+
100
+ category << processor
101
+ end
102
+ end
103
+
104
+ def each_processor_class_requiring_type(&block)
105
+ base_type&.each_processor_class_requiring_type(&block)
106
+
107
+ processor_classes_requiring_type&.each do |processor_class|
108
+ block.call(processor_class)
109
+ end
110
+ end
111
+
65
112
  def validate_processors!
66
113
  all = [casters, transformers, validators, element_processors]
67
114
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.38
4
+ version: 0.0.39
5
5
  platform: ruby
6
+ original_platform: ''
6
7
  authors:
7
8
  - Miles Georgi
8
- autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-11 00:00:00.000000000 Z
11
+ date: 2024-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: foobara-util
@@ -218,6 +218,7 @@ files:
218
218
  - projects/entity/src/entity.rb
219
219
  - projects/entity/src/extensions/builtin_types/entity.rb
220
220
  - projects/entity/src/extensions/builtin_types/entity/casters/hash.rb
221
+ - projects/entity/src/extensions/builtin_types/entity/casters/primary_key.rb
221
222
  - projects/entity/src/extensions/builtin_types/entity/validators/attributes_declaration.rb
222
223
  - projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration.rb
223
224
  - projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/attributes_handler_desugarizer.rb
@@ -260,7 +261,7 @@ files:
260
261
  - projects/model/src/concerns/reflection.rb
261
262
  - projects/model/src/concerns/types.rb
262
263
  - projects/model/src/extensions/builtin_types/model/casters/hash.rb
263
- - projects/model/src/extensions/builtin_types/model/transformers/mutable.rb
264
+ - projects/model/src/extensions/builtin_types/model/supported_transformers/mutable.rb
264
265
  - projects/model/src/extensions/builtin_types/model/validators/attributes_declaration.rb
265
266
  - projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration.rb
266
267
  - projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/attributes_handler_desugarizer.rb
@@ -382,7 +383,6 @@ metadata:
382
383
  source_code_uri: https://foobara.com
383
384
  changelog_uri: https://foobara.com/blob/main/CHANGELOG.md
384
385
  rubygems_mfa_required: 'true'
385
- post_install_message:
386
386
  rdoc_options: []
387
387
  require_paths:
388
388
  - "./projects/builtin_types/lib"
@@ -422,8 +422,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
422
422
  - !ruby/object:Gem::Version
423
423
  version: '0'
424
424
  requirements: []
425
- rubygems_version: 3.5.23
426
- signing_key:
425
+ rubygems_version: 3.6.0
427
426
  specification_version: 4
428
427
  summary: A command-centric and discoverable software framework with a focus on domain
429
428
  concepts and abstracting away integration code