foobara 0.0.63 → 0.0.64

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: 57076f6987a22c895a9ce9b024b2a7e05ffcaa5d96719dedc168cb029404a185
4
+ data.tar.gz: b1616575b7778d1ff2597a4c208fda89e544dbe77f3bf0a1ee724c6d5e753aae
5
5
  SHA512:
6
- metadata.gz: 62575b0f550c8dd9128f2d49d7b48fbda69af9f207533db1ca7a16c37981994506dcd4ba81b43efea51407bf14258bf7fa1f96e81a76aa006a0041641430a2d7
7
- data.tar.gz: 345c92a3db7720d4b8710296e15c8a1ead1a445f87820120f0874a8940ac48ea4fbac83fafdb8af6e4de7e0c60c40e352be1cdf7061e89fe8f35d52e5c584267
6
+ metadata.gz: bfb5adcce767f972f766372d23a473ca5598eb281809b5ee64a62e4a08265326e8aae3c6a6698be9cb3a1dedf87f8e32e33bd75a416181fcca7c2cdce2c0d05a
7
+ data.tar.gz: b2654dadfc19dda6fa4019715ede5b7ad0bc06e17232dff595cdeeff6ddfdd0da2bbf5e7df42b2f63d66a5ba56eed4d38d6c4e6dffcf2823ca001ac7ddd8a0dc
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [0.0.64] - 2025-02-25
2
+
3
+ - Fix bug where DomainMappers created after commands have ran wouldn't be detected
4
+ - Expose Enumerated::Values#value?
5
+ - Allow passing a hash to DomainMapper#new
6
+
1
7
  ## [0.0.63] - 2025-02-25
2
8
 
3
9
  - 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
@@ -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)
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.63
4
+ version: 0.0.64
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi