foobara 0.0.85 → 0.0.86

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: 3447ac0c4910cce965172cfdeaa22c16558bde49b0b0bcd533e2d5dba7b27188
4
- data.tar.gz: 67797d30549979ba6ef227d8c61bae996408d598b77edac19b4210a6e4e0edc6
3
+ metadata.gz: e400689de8a729a2ed91fc3fd0da0e447e4d773ece5a6efc42e4ee555eb665ef
4
+ data.tar.gz: 29f503d3d3263ad637add42716b757aba79688f98871a71cf9d011c72af28bd9
5
5
  SHA512:
6
- metadata.gz: 2c1b45ecd837fe9f66bb5dcd7d97d3f07dcbb8876a2c913386837378197b4ba0f33fac885283806adf9afea80cef65e3445ce13aff0e491005add424353e2475
7
- data.tar.gz: 4270856b98fb68dd813b3bde8e7284995f1293ec0f310122a4d136da4e2c02c094e5110c8e1363b80a8a6d699d0efec49148d4284302494f714e11edbbdd84b6
6
+ metadata.gz: 35490b924e4f50e2752936b26bbafd25e42b88c8be4a404e006befe58fb9b2b60be54eb54f039f4d5b2a455b409e256b5cbc8bc8496cc1a9e9bf94b52e17330f
7
+ data.tar.gz: 51745cf6ea9e92c93e6c2a944073232cb07126f35c6f0d10574b56f5b46ae2f91aef909008ab09b9d6d49711a9dc31c0b3ef2a74dc1b0cac4fbb1efe26ecf84b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # [0.0.86] - 2025-03-23
2
+
3
+ - Add an AttributesTransformer.only method to quickly get a TypedTransformer (helpful with inputs_transformers)
4
+
1
5
  # [0.0.85] - 2025-03-22
2
6
 
3
7
  - Add Manifest::TypeDeclaration#sensitive?
@@ -92,7 +92,6 @@ module Foobara
92
92
 
93
93
  def to_model
94
94
  raise "not an model" unless model?
95
- raise "model extension instead of an model" unless relevant_manifest.size == 1
96
95
 
97
96
  type = to_type
98
97
 
@@ -164,7 +164,20 @@ module Foobara
164
164
  def foobara_autoset_scoped_path(mod, make_top_level: false)
165
165
  return if mod.scoped_path_set?
166
166
 
167
- scoped_path = mod.name.split("::")
167
+ mod_name = mod.name
168
+
169
+ if mod_name.nil?
170
+ parent = mod.superclass
171
+ super_name = nil
172
+
173
+ begin
174
+ super_name = parent.scoped_path_set? ? parent.scoped_full_name : parent.name
175
+ end until super_name
176
+
177
+ mod_name = [super_name, mod.object_id.to_s(16)].join("::")
178
+ end
179
+
180
+ scoped_path = mod_name.split("::")
168
181
 
169
182
  adjusted_scoped_path = []
170
183
 
@@ -33,6 +33,22 @@ module Foobara
33
33
  )
34
34
  end
35
35
 
36
+ def only(declaration, *keys)
37
+ valid_keys = declaration[:element_type_declarations].keys
38
+ keys_to_keep = keys.map(&:to_sym)
39
+ invalid_keys = keys_to_keep - valid_keys
40
+
41
+ if invalid_keys.any?
42
+ # :nocov:
43
+ raise ArgumentError, "Invalid keys: #{invalid_keys} expected only #{valid_keys}"
44
+ # :nocov:
45
+ end
46
+
47
+ keys_to_reject = valid_keys - keys_to_keep
48
+
49
+ reject(declaration, keys_to_reject)
50
+ end
51
+
36
52
  def reject(declaration, *keys)
37
53
  # TODO: do we really need a deep dup?
38
54
  declaration = Util.deep_dup(declaration)
@@ -0,0 +1,33 @@
1
+ module Foobara
2
+ class AttributesTransformer < TypeDeclarations::TypedTransformer
3
+ class << self
4
+ attr_accessor :only_attributes
5
+
6
+ def type_declaration(from_type)
7
+ from_declaration = from_type.declaration_data
8
+ to_declaration = TypeDeclarations::Attributes.only(from_declaration, *only_attributes)
9
+
10
+ if TypeDeclarations.declarations_equal?(from_declaration, to_declaration)
11
+ from_type
12
+ else
13
+ from_type.foobara_domain.foobara_type_from_declaration(to_declaration)
14
+ end
15
+ end
16
+
17
+ def only(*attribute_names)
18
+ transformer_class = Class.new(self)
19
+ transformer_class.only_attributes = attribute_names
20
+
21
+ transformer_class
22
+ end
23
+ end
24
+
25
+ def transform(inputs)
26
+ inputs.slice(*allowed_keys)
27
+ end
28
+
29
+ def allowed_keys
30
+ type.element_types.keys
31
+ end
32
+ end
33
+ 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.85
4
+ version: 0.0.86
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
@@ -359,6 +359,7 @@ files:
359
359
  - projects/thread_parent/src/thread_parent.rb
360
360
  - projects/type_declarations/lib/foobara/type_declarations.rb
361
361
  - projects/type_declarations/src/attributes.rb
362
+ - projects/type_declarations/src/attributes_transformer.rb
362
363
  - projects/type_declarations/src/caster.rb
363
364
  - projects/type_declarations/src/desugarizer.rb
364
365
  - projects/type_declarations/src/dsl/attributes.rb