params-registry 0.1.7 → 0.1.11

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: a176c219561e992201c81af4cfa87b348fd408a5d52121ae9483004fdf073af3
4
- data.tar.gz: 3d532a4041860f3c09df1c5802e3e4dc27931cd98e13b1a5355f9251a7c73f83
3
+ metadata.gz: 9acf2f9ad9e56ea19a32e0803bf20559993a0d30ada1a11591e32de15297d339
4
+ data.tar.gz: 0cfcf9b1800162266314363889ea23577700c92c55853b54925bee4d2d204df6
5
5
  SHA512:
6
- metadata.gz: 52eda8b9e02f1f82dd908a07d5c2f4f1179ec2a401dff5562b582f55bdc4989d11ae5956664784fc1dfcd58ccaa5d6899aa0d651794021f408e9c0e84c65c188
7
- data.tar.gz: bf940c462597a0c43123e72f795e17f7778ff7ec2b73c7b9bcaea5c2e09b3a7472767342a12d4d155321c1033cf291571a0d91158745c6bae09af7f33f49ec4e
6
+ metadata.gz: be110642e2b2677745e58c146c1ac80f2f34171912daa2c9047785ab3490c89ad5f7ecaf970b4951606391983dc0bd52d44d0cd6fd1f62d95b862c77692f45a0
7
+ data.tar.gz: '0663797215b3d2b4162ccf72ed2f90aa1eaf47471a7e1cb85209eeb29d1dd5cb2284b6ea1b69b2f3fdb72a97325a4f018d8f47913c0f914af4e50a378d5be521'
@@ -74,16 +74,17 @@ class Params::Registry::Instance
74
74
  @content = {}
75
75
  @extra = {}
76
76
 
77
- warn "wtf lol #{@registry[@group].inspect}"
77
+ # warn "wtf lol #{@registry[@group].inspect}"
78
78
 
79
79
  # canonicalize the keys of the struct
80
80
  struct = Types::Input[struct].reduce({}) do |hash, pair|
81
81
  key, value = pair
82
+ # warn "kv: #{key.inspect} => #{value.inspect}"
82
83
  if t = @registry[@group][key]
83
- warn "yep #{key.inspect}"
84
+ # warn "yep #{key.inspect}"
84
85
  hash[t.id] = value
85
86
  else
86
- warn "nope #{key.inspect}"
87
+ # warn "nope #{key.inspect}"
87
88
  @extra[key] = value
88
89
  end
89
90
 
@@ -182,13 +183,15 @@ class Params::Registry::Instance
182
183
  # @return [Hash] basically the same thing, minus its metadata.
183
184
  #
184
185
  def to_h slugs: true, extra: false
185
- # we're gonna do damage, lol
186
- out = @content.dup
186
+ g = registry[@group]
187
187
 
188
- # this should work?
189
- out.transform_keys! do |k|
190
- registry[@group][k].slug || k.to_s.to_sym
191
- end if slugs
188
+ out = {}
189
+
190
+ g.templates.each do |t|
191
+ next unless @content.key? t.id
192
+ key = slugs ? t.slug || t.id.to_s.to_sym : t.id
193
+ out[key] = @content[t.id]
194
+ end
192
195
 
193
196
  # XXX maybe enforce the ordering better??
194
197
  out.merge! @extra if extra
@@ -196,19 +199,23 @@ class Params::Registry::Instance
196
199
  out
197
200
  end
198
201
 
199
- # Retrieve an {Params::Registry::Instance} that isolates the
200
- # intersection of one or more groups
201
- #
202
- # @param group [Object] the group identifier.
203
- # @param extra [false, true] whether to include any "extra" unparsed
204
- # parameters.
205
- #
206
- # @return [Params::Registry::Instance] an instance containing just
207
- # the group(s) identified.
208
- #
209
- def group *group, extra: false
202
+ def inspect
203
+ "<#{self.class} content: #{@content.inspect}, extra: #{@extra.inspect}>"
210
204
  end
211
205
 
206
+ # # Retrieve an {Params::Registry::Instance} that isolates the
207
+ # # intersection of one or more groups
208
+ # #
209
+ # # @param group [Object] the group identifier.
210
+ # # @param extra [false, true] whether to include any "extra" unparsed
211
+ # # parameters.
212
+ # #
213
+ # # @return [Params::Registry::Instance] an instance containing just
214
+ # # the group(s) identified.
215
+ # #
216
+ # def group *group, extra: false
217
+ # end
218
+
212
219
  # Serialize the instance back to a {::URI} query string.
213
220
  #
214
221
  # @return [String] the instance serialized as a URI query string.
@@ -189,7 +189,7 @@ class Params::Registry::Template
189
189
  # valid values are drawn.
190
190
  # @return [Object, nil]
191
191
  def universe
192
- refresh! unless @universe
192
+ refresh! if @unifunc and not @universe
193
193
  @universe
194
194
  end
195
195
 
@@ -403,7 +403,7 @@ class Params::Registry::Template
403
403
  @universe = univ
404
404
  end
405
405
 
406
- nil
406
+ self
407
407
  end
408
408
 
409
409
  # Return a suitable representation for debugging.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "version"
3
+ require_relative 'version'
4
4
 
5
5
  require 'dry-types' # let's try to use this and not hate it
6
6
  require 'set' # for some reason Set is not in the kernel but Range is
@@ -157,6 +157,7 @@ module Params::Registry::Types
157
157
 
158
158
  Input = self.Constructor(::Hash) do |input|
159
159
  input = input.query.to_s if input.is_a? ::URI
160
+ input = '' if input.nil?
160
161
  input = ::URI.decode_www_form input if input.is_a? ::String
161
162
 
162
163
  case input
@@ -3,6 +3,6 @@
3
3
  module Params
4
4
  class Registry
5
5
  # The module version
6
- VERSION = "0.1.7"
6
+ VERSION = '0.1.11'
7
7
  end
8
8
  end
@@ -135,6 +135,31 @@ class Params::Registry
135
135
  #
136
136
  def templates ; @templates.values; end
137
137
 
138
+ # Assign a new sequence of templates to the group.
139
+ #
140
+ # @param templates [Array, Hash]
141
+ #
142
+ # @return [Array, Hash] whatever was passed
143
+ # in because Ruby ignores the output
144
+ #
145
+ def templates= templates
146
+ templates = templates.to_a if templates.is_a? Hash
147
+
148
+ raise ArgumentError,
149
+ "Don't know what to do with #{templates.class}" unless
150
+ templates.respond_to? :to_a
151
+
152
+ # empty out the actual instance member
153
+ @templates.clear
154
+
155
+ # this should destructure appropriately (XXX MAYBE???) and also
156
+ # use the overloaded subscript assignment method
157
+ templates.to_a.each { |id, spec| self[id] = spec || id }
158
+
159
+ # now return the new members
160
+ @templates.values
161
+ end
162
+
138
163
  # Return the canonical identifier for the template.
139
164
  #
140
165
  # @param id [Object] the identifier, canonical or otherwise.
@@ -381,11 +406,12 @@ class Params::Registry
381
406
 
382
407
  # Refresh any stateful elements of the templates.
383
408
  #
384
- # @return [void]
409
+ # @return [self]
385
410
  #
386
411
  def refresh!
387
412
  templates.each { |t| t.refresh! }
388
- nil
413
+
414
+ self
389
415
  end
390
416
 
391
417
  # @!group Quasi-static methods to override in subclasses
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.1.7
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Taylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-13 00:00:00.000000000 Z
11
+ date: 2025-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-types
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  requirements: []
72
- rubygems_version: 3.3.15
72
+ rubygems_version: 3.4.20
73
73
  signing_key:
74
74
  specification_version: 4
75
75
  summary: 'Params::Registry: a registry for URI query parameters'