foobara 0.0.136 → 0.0.138

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.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/projects/builtin_types/lib/foobara/builtin_types.rb +1 -0
  4. data/projects/command/lib/foobara/command.rb +1 -0
  5. data/projects/command/src/command_pattern_implementation/concerns/reflection.rb +1 -0
  6. data/projects/command_connectors/lib/foobara/command_connectors.rb +1 -0
  7. data/projects/command_connectors/src/serializers/errors_serializer.rb +1 -2
  8. data/projects/command_connectors/src/transformers/entity_to_primary_key_inputs_transformer.rb +7 -1
  9. data/projects/common/src/error_collection.rb +24 -22
  10. data/projects/common/src/outcome.rb +13 -7
  11. data/projects/detached_entity/lib/foobara/detached_entity.rb +1 -0
  12. data/projects/domain/src/domain_module_extension.rb +2 -0
  13. data/projects/entity/lib/foobara/entity.rb +1 -0
  14. data/projects/entity/src/association_depth.rb +1 -1
  15. data/projects/entity/src/concerns/callbacks.rb +1 -0
  16. data/projects/foobara/src/project.rb +1 -0
  17. data/projects/model/lib/foobara/model.rb +1 -0
  18. data/projects/model/src/model.rb +1 -1
  19. data/projects/namespace/src/is_namespace.rb +16 -0
  20. data/projects/namespace/src/namespace_helpers.rb +4 -13
  21. data/projects/persistence/lib/foobara/persistence.rb +1 -0
  22. data/projects/persistence/src/entity_base/transaction/concerns/entity_callback_handling.rb +1 -0
  23. data/projects/persistence/src/entity_base/transaction/concerns/transaction_tracking.rb +1 -0
  24. data/projects/type_declarations/lib/foobara/type_declarations.rb +1 -0
  25. data/projects/type_declarations/src/attributes_transformers/from_yaml.rb +6 -0
  26. data/projects/type_declarations/src/attributes_transformers/only.rb +9 -1
  27. data/projects/type_declarations/src/attributes_transformers/reject.rb +11 -0
  28. data/projects/value/src/processor.rb +1 -1
  29. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f944c52f318016bd2742fb96208d11a2647d4802ee0a1ac4fbb5b353c5d6ad4
4
- data.tar.gz: 5c7560766afe430188cd41053ce9f470eae20605dba8dde824432b760e6aa336
3
+ metadata.gz: 6b67d70479dbaf49e1fb2c7fc255e96fefb41b1952c245baf75c3e677a451604
4
+ data.tar.gz: 618030d55da35eb987e63473a4cf50effa7aac62fed0d617a70758099dd40f50
5
5
  SHA512:
6
- metadata.gz: 3bf5da1d2282282a3d17eb44a0f8ca815c525800f71de56a05ed1c1b66babf5662293a0549df8a2ba6ee88da6cca7fe334f7a852d82b010afcf05f6d21ba1541
7
- data.tar.gz: 1444d194eaa3389270cdd23422ec294a59f523e1a71291a92551951987b54c7e316ce724465f7d0fa1151e5c7c2bad84879435eac2908c402f1c3ee888224c5f
6
+ metadata.gz: 9645d95fdcf186a9a1575af9d7d637e0703db3fc80cab9e58a293cc97a2bb37d21f655120057dba2dc533841d5a4836cec904da8f488a22ec182266ad8cc3137
7
+ data.tar.gz: d72777452ea575fcb2420e8edc41240eed16e46b603d3896be84c0a9568774a12aba385bef69a15f552f9540e1c3e54be5f37d98e3791cb6f990f85711b71a16
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ # [0.0.138] - 2025-07-23
2
+
3
+ - Allow #foobara_unregister by symbol, string, or array path
4
+
5
+ # [0.0.137] - 2025-07-22
6
+
7
+ - Fix bug where update_children_with_new_parent processes a scoped with itself
8
+ - Don't double-create Reject inputs transformers
9
+ - Fix description bug when transforming an entity to its primary key type
10
+ - Add .raise_if_production method to all uses of reset_all(s)
11
+ - Move the start_with? method another repository
12
+ - Prevent attributes transformers without attributes
13
+
1
14
  # [0.0.136] - 2025-07-06
2
15
 
3
16
  - Do not allow calling Foobara.reset_alls in production
@@ -64,6 +64,7 @@ module Foobara
64
64
  end
65
65
 
66
66
  def reset_all
67
+ Foobara.raise_if_production!("reset_all")
67
68
  builtin_types.each do |builtin_type|
68
69
  builtin_type.foobara_each do |scoped|
69
70
  if scoped.scoped_namespace == builtin_type
@@ -9,6 +9,7 @@ module Foobara
9
9
  end
10
10
 
11
11
  def reset_all
12
+ Foobara.raise_if_production!("reset_all")
12
13
  to_delete = []
13
14
 
14
15
  all.each do |command_class|
@@ -16,6 +16,7 @@ module Foobara
16
16
  end
17
17
 
18
18
  def reset_all
19
+ Foobara.raise_if_production!("reset_all")
19
20
  remove_instance_variable("@all") if instance_variable_defined?("@all")
20
21
  end
21
22
 
@@ -24,6 +24,7 @@ module Foobara
24
24
  end
25
25
 
26
26
  def reset_all
27
+ Foobara.raise_if_production!("reset_all")
27
28
  remove_instance_variable("@desugarizer") if defined?(@desugarizer)
28
29
  remove_instance_variable("@desugarizers") if defined?(@desugarizers)
29
30
  end
@@ -11,8 +11,7 @@ module Foobara
11
11
  end
12
12
 
13
13
  def serialize(error_collection)
14
- errors = error_collection.errors
15
- errors.map(&:to_h)
14
+ error_collection.map(&:to_h)
16
15
  end
17
16
  end
18
17
  end
@@ -52,13 +52,19 @@ module Foobara
52
52
 
53
53
  unless to_type.extends_directly?(Foobara::BuiltinTypes[:detached_entity]) ||
54
54
  to_type.extends_directly?(Foobara::BuiltinTypes[:entity])
55
+
55
56
  description = [
56
57
  description,
57
- to_type.description
58
+ *to_type.description
58
59
  ].join(" : ")
59
60
  end
61
+
60
62
  declaration[:description] = description
61
63
 
64
+ if to_type.declaration_data.key?(:allow_nil)
65
+ declaration[:allow_nil] = to_type.declaration_data[:allow_nil]
66
+ end
67
+
62
68
  declaration
63
69
  elsif to_type.extends?(Foobara::BuiltinTypes[:model])
64
70
  attributes_type = to_type.target_class.attributes_type
@@ -1,22 +1,15 @@
1
1
  module Foobara
2
- # TODO: inherit array instead of delegating
3
- class ErrorCollection
2
+ class ErrorCollection < Array
4
3
  class ErrorAlreadySetError < StandardError; end
5
4
 
6
5
  class << self
7
6
  def to_h(errors)
8
7
  new.tap do |collection|
9
8
  collection.add_errors(errors)
10
- end.to_h
9
+ end.errors_hash
11
10
  end
12
11
  end
13
12
 
14
- attr_reader :error_array
15
-
16
- def initialize
17
- @error_array = []
18
- end
19
-
20
13
  def success?
21
14
  empty?
22
15
  end
@@ -25,14 +18,18 @@ module Foobara
25
18
  !empty?
26
19
  end
27
20
 
28
- foobara_delegate :empty?, :partition, :size, :clear, to: :error_array
29
-
30
21
  def errors
31
- error_array
22
+ # :nocov:
23
+ warn "DEPRECATED: Do not call ErrorCollection#errors instead just use the collection directly."
24
+ self
25
+ # :nocov:
32
26
  end
33
27
 
34
28
  def each_error(&)
35
- error_array.each(&)
29
+ # :nocov:
30
+ warn "DEPRECATED: This method will be deprecated in the coming version"
31
+ each(&)
32
+ # :nocov:
36
33
  end
37
34
 
38
35
  def has_error?(error)
@@ -42,15 +39,13 @@ module Foobara
42
39
  # :nocov:
43
40
  end
44
41
 
45
- error_array.include?(error)
42
+ include?(error)
46
43
  end
47
44
 
48
45
  def add_error(error_or_collection_or_error_hash)
49
46
  error = case error_or_collection_or_error_hash
50
47
  when Error
51
48
  error_or_collection_or_error_hash
52
- when ErrorCollection
53
- return add_errors(error_or_collection_or_error_hash.errors)
54
49
  when Hash
55
50
  if error_or_collection_or_error_hash.key?(:symbol) &&
56
51
  error_or_collection_or_error_hash.key?(:message)
@@ -73,25 +68,32 @@ module Foobara
73
68
  raise ErrorAlreadySetError, "cannot set #{error} more than once"
74
69
  end
75
70
 
76
- error_array << error
71
+ self << error
77
72
  end
78
73
 
79
74
  def add_errors(errors)
80
75
  Util.array(errors).each { |error| add_error(error) }
81
76
  end
82
77
 
83
- def to_h
84
- error_array.to_h do |error|
85
- [error.key, error.to_h]
78
+ def errors_hash
79
+ each_with_object({}) do |error, hash|
80
+ hash[error.key] = error.to_h
86
81
  end
87
82
  end
88
83
 
89
84
  def to_sentence
90
- Util.to_sentence(error_array.map(&:message))
85
+ Util.to_sentence(map(&:message))
91
86
  end
92
87
 
93
88
  def keys
94
- error_array.map(&:key)
89
+ map(&:key)
90
+ end
91
+
92
+ def to_h
93
+ # :nocov:
94
+ warn "DEPRECATED: Use #errors_hash instead"
95
+ errors_hash
96
+ # :nocov:
95
97
  end
96
98
  end
97
99
  end
@@ -56,29 +56,35 @@ module Foobara
56
56
  end
57
57
 
58
58
  foobara_delegate :has_errors?,
59
- :errors,
60
- :each_error,
61
59
  :has_error?,
62
60
  :add_error,
63
61
  :add_errors,
64
62
  to: :error_collection
65
63
 
64
+ def errors
65
+ error_collection
66
+ end
67
+
68
+ def each_error(&)
69
+ error_collection.each(&)
70
+ end
71
+
66
72
  def success?
67
73
  !has_errors?
68
74
  end
69
75
 
70
76
  def fatal?
71
- errors.any?(&:fatal?)
77
+ error_collection.any?(&:fatal?)
72
78
  end
73
79
 
74
80
  def raise!
75
81
  return if success?
76
82
 
77
- error = errors.first
83
+ error = error_collection.first
78
84
  original_backtrace = error.backtrace_when_initialized
79
85
 
80
- if errors.size > 1
81
- error = UnsuccessfulOutcomeError.new(errors)
86
+ if error_collection.size > 1
87
+ error = UnsuccessfulOutcomeError.new(error_collection)
82
88
  end
83
89
 
84
90
  error.set_backtrace(original_backtrace)
@@ -93,7 +99,7 @@ module Foobara
93
99
  end
94
100
 
95
101
  def errors_hash
96
- error_collection.to_h
102
+ error_collection.errors_hash
97
103
  end
98
104
 
99
105
  def errors_sentence
@@ -16,6 +16,7 @@ module Foobara
16
16
  end
17
17
 
18
18
  def reset_all
19
+ Foobara.raise_if_production!("reset_all")
19
20
  install!
20
21
  end
21
22
  end
@@ -63,6 +63,8 @@ module Foobara
63
63
  attr_writer :foobara_domain_name, :foobara_full_domain_name
64
64
 
65
65
  def foobara_unregister(scoped)
66
+ scoped = to_scoped(scoped)
67
+
66
68
  foobara_type_builder.clear_cache
67
69
 
68
70
  if scoped.is_a?(Foobara::Types::Type)
@@ -21,6 +21,7 @@ module Foobara
21
21
  end
22
22
 
23
23
  def reset_all
24
+ Foobara.raise_if_production!("reset_all")
24
25
  Entity::Concerns::Callbacks.reset_all
25
26
 
26
27
  install!
@@ -2,6 +2,6 @@ module Foobara
2
2
  module AssociationDepth
3
3
  ATOM = :atom
4
4
  AGGREGATE = :aggregate
5
- PRIMARY_KEY_ONLY = :primary_key
5
+ PRIMARY_KEY_ONLY = :primary_key_only
6
6
  end
7
7
  end
@@ -6,6 +6,7 @@ module Foobara
6
6
 
7
7
  class << self
8
8
  def reset_all
9
+ Foobara.raise_if_production!("reset_all")
9
10
  Entity.instance_variable_set("@class_callback_registry", nil)
10
11
  end
11
12
  end
@@ -34,6 +34,7 @@ module Foobara
34
34
  end
35
35
 
36
36
  def reset_all
37
+ Foobara.raise_if_production!("reset_all")
37
38
  if self.module.respond_to?(:reset_all)
38
39
  self.module.reset_all
39
40
  end
@@ -28,6 +28,7 @@ module Foobara
28
28
  end
29
29
 
30
30
  def reset_all
31
+ Foobara.raise_if_production!("reset_all")
31
32
  install!
32
33
  end
33
34
  end
@@ -309,7 +309,7 @@ module Foobara
309
309
  end
310
310
 
311
311
  def validation_errors
312
- attributes_type.process_value(attributes).errors
312
+ attributes_type.process_value(attributes).error_collection
313
313
  end
314
314
 
315
315
  def validate!
@@ -74,6 +74,20 @@ module Foobara
74
74
  foobara_parent_namespace.nil?
75
75
  end
76
76
 
77
+ def to_scoped(scopedish)
78
+ if scopedish.is_a?(::String) || scopedish.is_a?(::Symbol) || scopedish.is_a?(::Array)
79
+ scopedish = foobara_lookup(scopedish)
80
+
81
+ unless scopedish
82
+ # :nocov:
83
+ raise ArgumentError, "Cannot unregister non-existent #{scopedish}"
84
+ # :nocov:
85
+ end
86
+ end
87
+
88
+ scopedish
89
+ end
90
+
77
91
  def foobara_register(scoped)
78
92
  foobara_registry.register(scoped)
79
93
  # awkward??
@@ -89,6 +103,8 @@ module Foobara
89
103
  end
90
104
 
91
105
  def foobara_unregister(scoped)
106
+ scoped = to_scoped(scoped)
107
+
92
108
  foobara_registry.unregister(scoped)
93
109
  foobara_children.delete(scoped)
94
110
  scoped.scoped_namespace = nil
@@ -248,10 +248,12 @@ module Foobara
248
248
  next if parent == mod
249
249
 
250
250
  if parent && !parent.scoped_full_path.empty?
251
- next if _start_with?(parent.scoped_full_path, mod.scoped_full_path)
251
+ next if Foobara::Util.start_with?(parent.scoped_full_path, mod.scoped_full_path)
252
252
  end
253
253
 
254
- if _start_with?(scoped.scoped_full_path, mod.scoped_full_path)
254
+ next if scoped.scoped_full_path == mod.scoped_full_path
255
+
256
+ if Foobara::Util.start_with?(scoped.scoped_full_path, mod.scoped_full_path)
255
257
  scoped.scoped_path = scoped.scoped_full_path[mod.scoped_full_path.size..]
256
258
 
257
259
  if parent
@@ -268,17 +270,6 @@ module Foobara
268
270
  end
269
271
  end
270
272
  end
271
-
272
- # TODO: move to util
273
- def _start_with?(large_array, small_array)
274
- return false unless large_array.size > small_array.size
275
-
276
- small_array.each.with_index do |item, index|
277
- return false unless large_array[index] == item
278
- end
279
-
280
- true
281
- end
282
273
  end
283
274
 
284
275
  def foobara_namespace!(scoped_path: nil, ignore_modules: nil)
@@ -2,6 +2,7 @@ module Foobara
2
2
  module Persistence
3
3
  class << self
4
4
  def reset_all
5
+ Foobara.raise_if_production!("reset_all")
5
6
  @tables_for_entity_class_name = @bases = @default_crud_driver = @default_base = nil
6
7
  EntityBase::Transaction::Concerns::EntityCallbackHandling.reset_all
7
8
  EntityBase::Transaction.reset_all
@@ -10,6 +10,7 @@ module Foobara
10
10
  module EntityCallbackHandling
11
11
  class << self
12
12
  def reset_all
13
+ Foobara.raise_if_production!("reset_all")
13
14
  install!
14
15
  end
15
16
 
@@ -21,6 +21,7 @@ module Foobara
21
21
  end
22
22
 
23
23
  def reset_all
24
+ Foobara.raise_if_production!("reset_all")
24
25
  @open_transactions = nil
25
26
  end
26
27
 
@@ -2,6 +2,7 @@ module Foobara
2
2
  module TypeDeclarations
3
3
  class << self
4
4
  def reset_all
5
+ Foobara.raise_if_production!("reset_all")
5
6
  # TODO: this doesn't really belong here. I think we need to maybe call reset in reverse order?
6
7
  Foobara::Domain::DomainModuleExtension.all.each do |domain|
7
8
  var = "@foobara_type_builder"
@@ -3,6 +3,12 @@ module Foobara
3
3
  class << self
4
4
  # TODO: dry this up with a .subclass method in AttributesTransformers?
5
5
  def from_yaml(*attribute_names)
6
+ if attribute_names.empty?
7
+ # :nocov:
8
+ raise ArgumentError, "You must specify at least one attribute name"
9
+ # :nocov:
10
+ end
11
+
6
12
  symbol = symbol_for_attribute_names(attribute_names)
7
13
  existing = FromYaml.foobara_lookup(symbol, mode: Namespace::LookupMode::DIRECT)
8
14
 
@@ -2,10 +2,18 @@ module Foobara
2
2
  class AttributesTransformers < TypeDeclarations::TypedTransformer
3
3
  class << self
4
4
  def only(*attribute_names)
5
+ if attribute_names.empty?
6
+ # :nocov:
7
+ raise ArgumentError, "You must specify at least one attribute name"
8
+ # :nocov:
9
+ end
10
+
5
11
  symbol = symbol_for_attribute_names(attribute_names)
6
12
  existing = Only.foobara_lookup(symbol, mode: Namespace::LookupMode::DIRECT)
7
13
 
8
- return existing if existing
14
+ if existing
15
+ return existing
16
+ end
9
17
 
10
18
  transformer_class = Class.new(Only)
11
19
  transformer_class.only_attributes = attribute_names
@@ -2,6 +2,17 @@ module Foobara
2
2
  class AttributesTransformers < TypeDeclarations::TypedTransformer
3
3
  class << self
4
4
  def reject(*attribute_names)
5
+ if attribute_names.empty?
6
+ # :nocov:
7
+ raise ArgumentError, "You must specify at least one attribute name"
8
+ # :nocov:
9
+ end
10
+
11
+ symbol = symbol_for_attribute_names(attribute_names)
12
+ existing = Reject.foobara_lookup(symbol, mode: Namespace::LookupMode::DIRECT)
13
+
14
+ return existing if existing
15
+
5
16
  transformer_class = Class.new(Reject)
6
17
  transformer_class.reject_attributes = attribute_names
7
18
 
@@ -235,7 +235,7 @@ module Foobara
235
235
  return old_outcome unless applicable?(value)
236
236
 
237
237
  process_value(value).tap do |outcome|
238
- outcome.add_errors(old_outcome.errors)
238
+ outcome.add_errors(old_outcome.error_collection)
239
239
  end
240
240
  end
241
241
 
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.136
4
+ version: 0.0.138
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi