foobara 0.2.5 → 0.2.6

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: e05617e8bea9b7a9ce861246a1a5c664ad3b525630dd1cd7362b80b4d6d809ea
4
- data.tar.gz: 10bd954f202f83aef9a20f0dec859212766a81e9682f6526ece70e3cd457b6a7
3
+ metadata.gz: a3b6525afdbf01d8f0d56dce1f067430111781670ebac06dc4a90297e5fb1188
4
+ data.tar.gz: fc79448ff4613758061b9c6336855fed97b6328356d510b77eb438097d55c99d
5
5
  SHA512:
6
- metadata.gz: 26fa0c9be295542f963963ac892405a315d5b6f004fadcdf23336bab09ad973cdae843186134c20c1e173be816506c37f2ad34e825c6d84f2c2ef42845262011
7
- data.tar.gz: efefbce7b11751d240a09ca34bc5e20a182c60daa00cc79399aceee55c74e33b8b1135aca706abd2a8d3e80c39414477a19d3fee05cc28bdd0e13b063d6fda77
6
+ metadata.gz: 46d2df3884c269014f64a0b040d867e63bf65bd4c0822a4d810e07a506f296a2c6a967be2437542e7d6b56af8080094f1510da9d8143e94880428bd816bf32ad
7
+ data.tar.gz: 878e815dad1a261fa6bf9fc64525d06ea6cef4c499770fa6f621487a1fce011a2781750e53b75c40f8f8d1d3db57ef4cd17e4c542fba899c2474ca3576e239ab
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # [0.2.6] - 2025-10-30
2
+
3
+ - Add a set inputs transformer
4
+
1
5
  # [0.2.5] - 2025-10-27
2
6
 
3
7
  - Do not allow commands to be connected multiple times via symbol/string
@@ -17,6 +17,7 @@ module Foobara
17
17
  CommandConnector.add_desugarizer Desugarizers.rename :response, :response_mutators
18
18
  CommandConnector.add_desugarizer Desugarizers::Attributes::OnlyInputs
19
19
  CommandConnector.add_desugarizer Desugarizers::Attributes::RejectInputs
20
+ CommandConnector.add_desugarizer Desugarizers::SetInputs
20
21
  CommandConnector.add_desugarizer Desugarizers::Attributes::OnlyResult
21
22
  CommandConnector.add_desugarizer Desugarizers::Attributes::RejectResult
22
23
  CommandConnector.add_desugarizer Desugarizers::Attributes::InputsFromYaml
@@ -0,0 +1,48 @@
1
+ require_relative "../desugarizer"
2
+
3
+ module Foobara
4
+ module CommandConnectors
5
+ module Desugarizers
6
+ class SetInputs < Desugarizer
7
+ def applicable?(args_and_opts)
8
+ _args, opts = args_and_opts
9
+
10
+ return false unless opts.key?(:inputs_transformers)
11
+
12
+ transformers = opts[:inputs_transformers]
13
+ transformers = Util.array(transformers)
14
+
15
+ transformers.any? do |transformer|
16
+ transformer.is_a?(::Hash) && transformer.key?(:set)
17
+ end
18
+ end
19
+
20
+ def desugarize(args_and_opts)
21
+ args, opts = args_and_opts
22
+
23
+ transformers = opts[:inputs_transformers]
24
+ is_array = transformers.is_a?(::Array)
25
+
26
+ transformers = Util.array(transformers)
27
+
28
+ transformers = transformers.map do |transformer|
29
+ if transformer.is_a?(::Hash) && transformer.key?(:set)
30
+ AttributesTransformers.set(transformer[:set])
31
+ else
32
+ # TODO: add a test for this
33
+ # :nocov:
34
+ transformer
35
+ # :nocov:
36
+ end
37
+ end
38
+
39
+ transformers = transformers.first unless is_array
40
+
41
+ opts = opts.merge(inputs_transformers: transformers)
42
+
43
+ [args, opts]
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,6 +1,11 @@
1
1
  module Foobara
2
2
  module CommandConnectors
3
3
  module Serializers
4
+ # This seems to interpret "Atomic" as load the first entity you hit but not deeper entities.
5
+ # Other interpretations it could have been:
6
+ # 1) If top-level is an entity, load it and convert all nested entities to primary keys,
7
+ # otherwise, convert all entities to primary keys
8
+ # 2) Once past the first model, all entities are cast to primary keys
4
9
  class AtomicSerializer < SuccessSerializer
5
10
  def serialize(object)
6
11
  case object
@@ -8,6 +8,12 @@ module Foobara
8
8
  def register(scoped)
9
9
  short_name = scoped.scoped_short_name
10
10
  registry[short_name] ||= []
11
+ # This kind of error should only happen in test suites that need to unregister/reregister things
12
+ # with different object_ids but the same scoped full name. So will check it in commented out.
13
+ # if registry[short_name].map(&:scoped_full_name).include?(scoped.scoped_full_name)
14
+ # raise "Already registered: #{scoped.scoped_full_name}"
15
+ # end
16
+
11
17
  registry[short_name] |= [scoped]
12
18
  end
13
19
 
@@ -0,0 +1,77 @@
1
+ module Foobara
2
+ class AttributesTransformers < TypeDeclarations::TypedTransformer
3
+ class << self
4
+ def next_index
5
+ @index ||= 0
6
+ @index += 1
7
+ end
8
+
9
+ def set(attribute_names_to_values)
10
+ if attribute_names_to_values.empty?
11
+ # :nocov:
12
+ raise ArgumentError, "You must specify at least one attribute name/value pair"
13
+ # :nocov:
14
+ end
15
+
16
+ symbol = symbol_for_attribute_names([*attribute_names_to_values.keys, next_index.to_s.to_sym])
17
+ existing = Set.foobara_lookup(symbol, mode: Namespace::LookupMode::DIRECT)
18
+
19
+ return existing if existing
20
+
21
+ transformer_class = Class.new(Set)
22
+ transformer_class.attribute_names_to_values = attribute_names_to_values
23
+
24
+ Namespace::NamespaceHelpers.foobara_autoset_scoped_path(transformer_class, set_namespace: true)
25
+ transformer_class.scoped_namespace.foobara_register(transformer_class)
26
+
27
+ transformer_class
28
+ end
29
+ end
30
+
31
+ class Set < AttributesTransformers
32
+ class << self
33
+ attr_accessor :attribute_names_to_values
34
+
35
+ def symbol
36
+ if attribute_names_to_values
37
+ symbol_for_attribute_names(attribute_names_to_values.keys)
38
+ end
39
+ end
40
+
41
+ def will_set_scoped_path?
42
+ true
43
+ end
44
+ end
45
+
46
+ def to_type_declaration
47
+ # TODO: test this
48
+ # :nocov:
49
+ if from_type
50
+ from_declaration = from_type.declaration_data
51
+ TypeDeclarations::Attributes.reject(from_declaration, *self.class.attribute_names_to_values.keys)
52
+ end
53
+ # :nocov:
54
+ end
55
+
56
+ def from_type_declaration
57
+ if to_type
58
+ to_declaration = to_type.declaration_data
59
+ TypeDeclarations::Attributes.reject(to_declaration, *self.class.attribute_names_to_values.keys)
60
+ end
61
+ end
62
+
63
+ def transform(inputs)
64
+ to_merge = {}
65
+
66
+ self.class.attribute_names_to_values.each_pair do |input_name, value|
67
+ if value.is_a?(::Proc)
68
+ value = value.call
69
+ end
70
+ to_merge[input_name] = value
71
+ end
72
+
73
+ inputs.merge(to_merge)
74
+ end
75
+ end
76
+ end
77
+ end
data/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Foobara
2
2
  module Version
3
- VERSION = "0.2.5".freeze
3
+ VERSION = "0.2.6".freeze
4
4
  MINIMUM_RUBY_VERSION = ">= 3.4.0".freeze
5
5
  end
6
6
  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.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
@@ -214,6 +214,7 @@ files:
214
214
  - projects/command_connectors/src/desugarizers/attributes/reject_result.rb
215
215
  - projects/command_connectors/src/desugarizers/auth.rb
216
216
  - projects/command_connectors/src/desugarizers/rename_key.rb
217
+ - projects/command_connectors/src/desugarizers/set_inputs.rb
217
218
  - projects/command_connectors/src/desugarizers/symbols_to_true.rb
218
219
  - projects/command_connectors/src/request_mutator.rb
219
220
  - projects/command_connectors/src/response_mutator.rb
@@ -422,6 +423,7 @@ files:
422
423
  - projects/type_declarations/src/attributes_transformers/from_yaml.rb
423
424
  - projects/type_declarations/src/attributes_transformers/only.rb
424
425
  - projects/type_declarations/src/attributes_transformers/reject.rb
426
+ - projects/type_declarations/src/attributes_transformers/set.rb
425
427
  - projects/type_declarations/src/caster.rb
426
428
  - projects/type_declarations/src/desugarizer.rb
427
429
  - projects/type_declarations/src/desugarizer_pipeline.rb