params-registry 0.2.1 → 0.2.2

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: ac097d76612371d0ccf0cd787b7aa3fa39b1b0392dd65ee09fb9188488785c67
4
- data.tar.gz: 78d0cfe84914872dbc96852600af044b13dff6883cdf475810a411ce8c1d4b31
3
+ metadata.gz: b55a15071c752544d76d3256a835eb927507ff8685a90cc94cc00a9bf6fed373
4
+ data.tar.gz: c4e5cc3a55c98e39405fa5d61e88ccecdc279e5149d38a04469a6ab5db664e33
5
5
  SHA512:
6
- metadata.gz: 54afd98474e0c2570a3aa40b6149395dae855a9c99e4b7da0791739760aaa96f0bf1c11694290c5a0f975e396deb218174f2926d7af5ac4ea78028b0ad5da162
7
- data.tar.gz: 2c245cbd712bf4bad769ef3b9f5e11f4926597d8ca9d557540cf57b9e441868c6d5130f37c974235660fb1ecb12bf82ac0c58fbb564e29fd5f464c8b38e35d20
6
+ metadata.gz: 356602be7b8437695e5439bafcb74c62d85a1e5205a436c2ab90e8ec19d1cdc0692fdd0b25dd16ac18f86861c96d7a501b4114a357469b301e17f6396becd834
7
+ data.tar.gz: b7f9c511c11070da981d7d85d4354c4f46c7d72a780aee8b2e4eace3ce34c5d52eef6866dce51add8bd32947924614c853f677cf602d7e34d7ec7f6f17df2d19
data/README.md CHANGED
@@ -18,9 +18,9 @@ _symbols_, which you have to _manage_, and this is a _problem_.
18
18
  table: named parameters that are exposed to the wild through
19
19
  mechanisms like URLs and APIs.
20
20
 
21
- ## So, query parameters, isn't that like, _super_ anal?
21
+ ## So, query parameters, isn't that like, _super_ uptight?
22
22
 
23
- So, I vacillated for _years_ before making [the _first_ version of
23
+ I vacillated for _years_ before making [the _first_ version of
24
24
  this module](https://metacpan.org/dist/Params-Registry) back in 2013.
25
25
  _Query_ parameters? I mean, who cares? Well, it turns out that if you
26
26
  want certain outcomes, this is the kind of software you need. _What_
@@ -220,7 +220,12 @@ class Params::Registry::Instance
220
220
  return @extras[param] = value
221
221
  end
222
222
 
223
- @content[template.id] = template.process value
223
+ # XXX THIS MIGHT FUCK SHIT UP
224
+ if value.nil?
225
+ @content.delete template.id
226
+ else
227
+ @content[template.id] = template.process value
228
+ end
224
229
  end
225
230
 
226
231
  # Bulk-assign instance content.
@@ -239,9 +244,9 @@ class Params::Registry::Instance
239
244
  #
240
245
  # @return [URI, #query=] the URI with the new query string
241
246
  #
242
- def make_uri uri, defaults: false
247
+ def make_uri uri, defaults: false, extra: false
243
248
  uri = uri.dup
244
- uri.query = to_s defaults: defaults
249
+ uri.query = to_s defaults: defaults, extra: extra
245
250
  uri
246
251
  end
247
252
 
@@ -281,14 +286,39 @@ class Params::Registry::Instance
281
286
 
282
287
  # Serialize the instance back to a {::URI} query string.
283
288
  #
289
+ # @params defaults [false, true, Object, Array] whether to serialize
290
+ # default values, or specific keys/slugs to include
291
+ # @params extra [false, true] whether to include parameters that
292
+ # were passed in that aren't in the registry
293
+ #
284
294
  # @return [String] the instance serialized as a URI query string.
285
295
  #
286
296
  def to_s defaults: false, extra: false
287
297
  ts = registry.templates
298
+
299
+ # warn ts.inspect
300
+
301
+ # this should give us a list of keys that have defaults that we
302
+ # want to show up
303
+ defaults = case defaults
304
+ when nil, false then []
305
+ when true then ts.select { |k| ts[k].default? }.values.map(&:id)
306
+ when -> d { d.respond_to? :to_a } then defaults.to_a
307
+ else [defaults]
308
+ end.map { |d| ts[d]&.id }.compact
309
+
310
+ # the template keys should have the original order so we want to intersee
288
311
  sequence = ts.keys & @content.keys
289
312
  complements = Set[]
290
- sequence.map do |k|
313
+ out = sequence.map do |k|
291
314
  template = ts[k]
315
+
316
+ # we want to skip the parameter if it's the same as
317
+ next if template.default? and @content[k] == template.default and
318
+ not defaults.include? k
319
+
320
+ # get the dependencies, convert to an array of strings, harvest
321
+ # complement flag (if present)
292
322
  deps = @content.slice(*(template.depends - template.consumes))
293
323
  v, c = template.unprocess @content[k], deps, try_complement: true
294
324
  complements << k if c
@@ -300,7 +330,12 @@ class Params::Registry::Instance
300
330
  v.map do |v|
301
331
  "#{template.slug || encode_value(k)}=#{encode_value v}"
302
332
  end.join ?&
303
- end.compact.join ?&
333
+ end.compact
334
+
335
+ # XXX TODO complement and extras i just don't feel like looking up how
336
+ # that's supposed to work rn but they would go here
337
+
338
+ out.join ?&
304
339
  end
305
340
 
306
341
  # Return a string representation of the object suitable for debugging.
@@ -289,6 +289,13 @@ class Params::Registry::Template
289
289
  #
290
290
  def composite? ; !!@composite; end
291
291
 
292
+ # @!attribute [r] default?
293
+ # Whether this parameter has a default value.
294
+ #
295
+ # @return [Boolean]
296
+ #
297
+ def default? ; !@default.nil?; end
298
+
292
299
  # @!attribute [r] preproc?
293
300
  # Whether there is a preprocessor function.
294
301
  #
@@ -40,6 +40,8 @@ module Params::Registry::Types
40
40
  end
41
41
  end
42
42
 
43
+ Boolean = Bool
44
+
43
45
  # For some reason there isn't a stock `Proc` type.
44
46
  Proc = self.Instance(::Proc)
45
47
 
@@ -3,6 +3,6 @@
3
3
  module Params
4
4
  class Registry
5
5
  # The module version
6
- VERSION = '0.2.1'
6
+ VERSION = '0.2.2'
7
7
  end
8
8
  end
@@ -244,10 +244,14 @@ class Params::Registry
244
244
  # @param params
245
245
  # [String, URI, Hash{#to_sym => Array}, Array<Array<(#to_sym, Object)>>]
246
246
  # the parameter set, in a dizzying variety of inputs.
247
+ # @param defaults [true, false] whether to include default values
248
+ # in the instance
249
+ # @param force [false, true] whether to force something i don't
250
+ # remember what though lol
247
251
  #
248
252
  # @return [Params::Registry::Instance] the instance.
249
253
  #
250
- def process params, defaults: false, force: false
254
+ def process params, defaults: true, force: false
251
255
  registry.instance_class.new self,
252
256
  params: params, defaults: defaults, force: force
253
257
  end
@@ -404,10 +408,14 @@ class Params::Registry
404
408
  # @param params
405
409
  # [String, URI, Hash{#to_sym => Array}, Array<Array<(#to_sym, Object)>>]
406
410
  # the parameter set, in a dizzying variety of inputs.
411
+ # @param defaults [true, false] whether to include default values
412
+ # in the instance
413
+ # @param force [false, true] whether to force something i don't
414
+ # remember what though lol
407
415
  #
408
416
  # @return [Params::Registry::Instance] the instance.
409
417
  #
410
- def process params, defaults: false, force: false
418
+ def process params, defaults: true, force: false
411
419
  instance_class.new self, params: params, defaults: defaults, force: force
412
420
  end
413
421
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: params-registry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Taylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-18 00:00:00.000000000 Z
11
+ date: 2025-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-types