foobara 0.0.55 → 0.0.57

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: 78bd1547b990baf3ef2d1210747e7c9ea2943a3136fd39d38f399f0a90f73aa6
4
- data.tar.gz: b75e8291b79c05de501de15ed64c62df2ce26de2f7e13fcde95dd6c9cd445430
3
+ metadata.gz: 63e9a6f8fe233be5b149ccd3f7d0fec23f4525f833ab887470251f041bbe63d8
4
+ data.tar.gz: 43b48d0b6b364b60db43aa9123b0929cd59c95871e83af894f8a35d2eadaac4d
5
5
  SHA512:
6
- metadata.gz: 3d49b8eef5f2823c475b2227e1f05c844327837ff8eb0545ca62b46aa2f122413d4d283d3e6fc7a8618e8469c98ab7bfb6b77f5a4fa7131743cffa0d398309a3
7
- data.tar.gz: ca9194b01789d6ac289322a919b56ac9e9074a838524509d0759251d4c62839942b56aac0d6c59f3018d89a67fa68aa9421b5c28922b1c4c978e3060432aeb32
6
+ metadata.gz: 39607e1c26837a96c621c20af465e37e1190f715edf5b2d21d029519794cdc396d9376fc91babf4869e577f01895e6bcb3fab5a744497d296f816a75d4053f82
7
+ data.tar.gz: d6c28e37b91842740c465e35d3c974066f7e2b0e25b30e11573d52e90faddfe52c1edfd4fb7c17eba4eb18a657a3f33bf6b958c71ae6ce1c824068e21802baeb
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.4.1
1
+ 3.4.2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.0.57] - 2025-02-18
2
+
3
+ - Add Enumerated.make_module helper
4
+
5
+ ## [0.0.56] - 2025-02-16
6
+
7
+ - Bump Ruby to 3.4.2
8
+ - Add an ignore_unexpected_attributes option to Model#initialize
9
+
1
10
  ## [0.0.55] - 2025-02-01
2
11
 
3
12
  - Mark types as builtin directly and add builtin flag to manifest
@@ -0,0 +1,27 @@
1
+ module Foobara
2
+ module BuiltinTypes
3
+ module Attributes
4
+ module Transformers
5
+ class RemoveUnexpectedAttributes < Value::Transformer
6
+ class << self
7
+ def requires_parent_declaration_data?
8
+ true
9
+ end
10
+ end
11
+
12
+ def applicable?(hash)
13
+ Thread.foobara_var_get(:foobara_ignore_unexpected_attributes) && unexpected_attributes(hash).any?
14
+ end
15
+
16
+ def transform(hash)
17
+ hash.except(*unexpected_attributes(hash))
18
+ end
19
+
20
+ def unexpected_attributes(hash)
21
+ hash.keys - parent_declaration_data[:element_type_declarations].keys
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -15,11 +15,11 @@ module Foobara
15
15
  parse(string)
16
16
  end
17
17
 
18
- private
19
-
20
18
  NOT_DELIMITED_REGEX = /\A(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})\z/
21
19
  DELIMITED_REGEX = /\A(?<year>\d{4,})(?<delimiter>[\/\\.|_:;-])(?<month>\d{1,2})\k<delimiter>(?<day>\d{1,2})\z/
22
20
 
21
+ private
22
+
23
23
  def parse(string)
24
24
  match = NOT_DELIMITED_REGEX.match(string) || DELIMITED_REGEX.match(string)
25
25
 
@@ -0,0 +1,9 @@
1
+ module Foobara
2
+ module Enumerated
3
+ class << self
4
+ def make_module(...)
5
+ Values.new(...).make_module
6
+ end
7
+ end
8
+ end
9
+ end
@@ -116,6 +116,23 @@ module Foobara
116
116
  def respond_to_missing?(name, _include_private = false)
117
117
  @symbol_map.key?(name)
118
118
  end
119
+
120
+ def make_module
121
+ mod = Module.new
122
+ enumerated = self
123
+
124
+ %i[all all_names all_values].each do |method_name|
125
+ mod.singleton_class.define_method method_name do |*args, **opts, &block|
126
+ enumerated.send(method_name, *args, **opts, &block)
127
+ end
128
+ end
129
+
130
+ @symbol_map.each_pair do |name, value|
131
+ mod.const_set(name, value)
132
+ end
133
+
134
+ mod
135
+ end
119
136
  end
120
137
  end
121
138
  end
@@ -171,7 +171,7 @@ module Foobara
171
171
  attr_accessor :mutable
172
172
 
173
173
  def initialize(attributes = nil, options = {})
174
- allowed_options = %i[validate mutable]
174
+ allowed_options = %i[validate mutable ignore_unexpected_attributes]
175
175
  invalid_options = options.keys - allowed_options
176
176
 
177
177
  unless invalid_options.empty?
@@ -180,6 +180,12 @@ module Foobara
180
180
  # :nocov:
181
181
  end
182
182
 
183
+ if options[:ignore_unexpected_attributes]
184
+ Thread.foobara_with_var(:foobara_ignore_unexpected_attributes, true) do
185
+ return initialize(attributes, options.except(:ignore_unexpected_attributes))
186
+ end
187
+ end
188
+
183
189
  validate = options[:validate]
184
190
 
185
191
  if attributes.nil?
@@ -189,6 +195,14 @@ module Foobara
189
195
  # :nocov:
190
196
  end
191
197
  else
198
+ if Thread.foobara_var_get(:foobara_ignore_unexpected_attributes)
199
+ outcome = attributes_type.process_value(attributes)
200
+
201
+ if outcome.success?
202
+ attributes = outcome.result
203
+ end
204
+ end
205
+
192
206
  self.mutable = true
193
207
  attributes.each_pair do |attribute_name, value|
194
208
  write_attribute(attribute_name, value)
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.55
4
+ version: 0.0.57
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-02 00:00:00.000000000 Z
10
+ date: 2025-02-18 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bigdecimal
@@ -71,6 +71,7 @@ files:
71
71
  - projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/desugarizers/move_required_from_element_types_to_root.rb
72
72
  - projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_of_symbols.rb
73
73
  - projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb
74
+ - projects/builtin_types/src/attributes/transformers/remove_unexpected_attributes.rb
74
75
  - projects/builtin_types/src/big_decimal/casters/integer.rb
75
76
  - projects/builtin_types/src/big_decimal/casters/string.rb
76
77
  - projects/builtin_types/src/boolean/casters/numeric.rb
@@ -248,6 +249,7 @@ files:
248
249
  - projects/entity/src/not_found_error.rb
249
250
  - projects/enumerated/lib/foobara/enumerated.rb
250
251
  - projects/enumerated/src/accessors.rb
252
+ - projects/enumerated/src/enumerated.rb
251
253
  - projects/enumerated/src/values.rb
252
254
  - projects/foobara/lib/foobara.rb
253
255
  - projects/foobara/lib/foobara/all.rb