foobara 0.0.63 → 0.0.65

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: 51f412dd4ee9050badd64dfc8e1ec04e82f500ca4b11108ac87ec7303df68cdf
4
- data.tar.gz: 3c6a97a2c94639a964a728ffdf3a11cab2c1cd7bc3e966f2eb37b5b5de2a8af0
3
+ metadata.gz: 21197ef384605690acb82fc34c7e05508e876b9659ff7aeb3cb068b9f3d2e43f
4
+ data.tar.gz: 9fa7bb5281ce36f1b62b57860e29b618d58d1ae18b3a6e9212e370549d1b0f6f
5
5
  SHA512:
6
- metadata.gz: 62575b0f550c8dd9128f2d49d7b48fbda69af9f207533db1ca7a16c37981994506dcd4ba81b43efea51407bf14258bf7fa1f96e81a76aa006a0041641430a2d7
7
- data.tar.gz: 345c92a3db7720d4b8710296e15c8a1ead1a445f87820120f0874a8940ac48ea4fbac83fafdb8af6e4de7e0c60c40e352be1cdf7061e89fe8f35d52e5c584267
6
+ metadata.gz: 43f5d7f1caf9380fd20d3b68a277e43c1a2efbcf226096892c2cc9cfaed8dbfc7591a16024f01a4e57f6e3c0bb590f04e8bfb823007b353dbe15ca735e4a9d1b
7
+ data.tar.gz: 97bbe6d2d1c24827ca1210713b7e65e3f63dfb69bf7a312aab4f3631b4bf867b41dcdd2a9692cb626d563ad4166e433955dbf5bfd1d1154ac950b902bb0df0ce
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## [0.0.65] - 2025-02-26
2
+
3
+ - Fix a problem when looking up domain mappers with a symbol value that doesn't represent a type
4
+
5
+ ## [0.0.64] - 2025-02-25
6
+
7
+ - Fix bug where DomainMappers created after commands have ran wouldn't be detected
8
+ - Expose Enumerated::Values#value?
9
+ - Allow passing a hash to DomainMapper#new
10
+
1
11
  ## [0.0.63] - 2025-02-25
2
12
 
3
13
  - Allow creating an Enumerated from a list of value strings that contain colons
@@ -133,7 +133,25 @@ module Foobara
133
133
  super
134
134
  end
135
135
 
136
- def foobara_domain_map(value, to: nil, strict: false, criteria: nil, should_raise: false, **opts)
136
+ def foobara_domain_map(*args, to: nil, strict: false, criteria: nil, should_raise: false, **opts)
137
+ case args.size
138
+ when 1
139
+ value = args.first
140
+ when 0
141
+ if opts.empty?
142
+ # :nocov:
143
+ raise ArgumentError, "Expected at least one argument"
144
+ # :nocov:
145
+ else
146
+ value = opts
147
+ opts = {}
148
+ end
149
+ else
150
+ # :nocov:
151
+ raise ArgumentError, "Expected 1 argument but got #{args.size}"
152
+ # :nocov:
153
+ end
154
+
137
155
  invalid_keys = opts.keys - [:from]
138
156
 
139
157
  if invalid_keys.any?
@@ -145,17 +163,11 @@ module Foobara
145
163
  from = if opts.key?(:from)
146
164
  opts[:from]
147
165
  else
148
- try_nil = true
149
166
  value
150
167
  end
151
168
 
152
169
  mapper = lookup_matching_domain_mapper(from:, to:, criteria:, strict:)
153
170
 
154
- if try_nil
155
- from = nil
156
- mapper = lookup_matching_domain_mapper(from:, to:, criteria:, strict:)
157
- end
158
-
159
171
  if mapper
160
172
  mapper.map!(value)
161
173
  elsif should_raise
@@ -163,8 +175,8 @@ module Foobara
163
175
  end
164
176
  end
165
177
 
166
- def foobara_domain_map!(value, from: nil, to: nil, criteria: nil, strict: false)
167
- foobara_domain_map(value, from:, to:, criteria:, strict:, should_raise: true)
178
+ def foobara_domain_map!(*, **, &)
179
+ foobara_domain_map(*, should_raise: true, **, &)
168
180
  end
169
181
 
170
182
  def foobara_domain_name
@@ -6,6 +6,10 @@ module Foobara
6
6
  include CommandPatternImplementation
7
7
 
8
8
  class << self
9
+ def foobara_on_register
10
+ foobara_domain.new_mapper_registered!
11
+ end
12
+
9
13
  def map(value)
10
14
  new(from: value).run
11
15
  end
@@ -54,7 +58,7 @@ module Foobara
54
58
 
55
59
  type = object_to_type(type_indicator)
56
60
 
57
- return 1 if type.nil?
61
+ return 0 if type.nil?
58
62
  return 9 if type == value
59
63
 
60
64
  return 5 if type.applicable?(value) && type.process_value(value).success?
@@ -100,7 +104,7 @@ module Foobara
100
104
  when Types::Type
101
105
  object
102
106
  when ::Symbol
103
- domain.foobara_lookup_type!(object)
107
+ domain.foobara_lookup_type(object)
104
108
  end
105
109
  end
106
110
  end
@@ -40,6 +40,12 @@ module Foobara
40
40
  include Concern
41
41
 
42
42
  module ClassMethods
43
+ def new_mapper_registered!
44
+ if defined?(@mappers) && !@mappers.empty?
45
+ remove_instance_variable("@mappers")
46
+ end
47
+ end
48
+
43
49
  def lookup_matching_domain_mapper!(from: nil, to: nil, strict: false, criteria: nil)
44
50
  result = lookup_matching_domain_mapper(from:, to:, strict:, criteria:)
45
51
 
@@ -125,7 +125,7 @@ module Foobara
125
125
  mod = Module.new
126
126
  enumerated = self
127
127
 
128
- %i[all all_names all_values].each do |method_name|
128
+ %i[all all_names all_values value?].each do |method_name|
129
129
  mod.singleton_class.define_method method_name do |*args, **opts, &block|
130
130
  enumerated.send(method_name, *args, **opts, &block)
131
131
  end
@@ -78,6 +78,10 @@ module Foobara
78
78
  foobara_registry.register(scoped)
79
79
  # awkward??
80
80
  scoped.scoped_namespace = self
81
+
82
+ if scoped.respond_to?(:foobara_on_register)
83
+ scoped.foobara_on_register
84
+ end
81
85
  rescue PrefixlessRegistry::RegisteringScopedWithPrefixError,
82
86
  BaseRegistry::WouldMakeRegistryAmbiguousError => e
83
87
  _upgrade_registry(e)
@@ -154,6 +154,10 @@ module Foobara
154
154
  def target_class
155
155
  if target_classes.empty?
156
156
  # :nocov:
157
+ # TODO: We really need a better error message when we hit this point in the code path.
158
+ # One thing that can cause this is if you create a custom type called :model but it isn't loaded
159
+ # yet and we accidentally are referring to the builtin :model type. This error message doesn't reveal
160
+ # that you need to require the custom :model.
157
161
  raise "No target classes"
158
162
  # :nocov:
159
163
  elsif target_classes.size > 1
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.63
4
+ version: 0.0.65
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-25 00:00:00.000000000 Z
10
+ date: 2025-02-26 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bigdecimal