params-registry 0.1.4 → 0.1.6

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: 2b59f44588d91a5931a029450ff4087f634a8e4c4f92d5fc07ed593b616ddda1
4
- data.tar.gz: 524ee99633bd8f266acca27eb9f712bbdb3d64b02291e09848e2efb4b694db29
3
+ metadata.gz: a2c64c0a41224198bdd02db7960b2051e74726bf690ddc66b222bc077bdeafd0
4
+ data.tar.gz: 5bd14e8bb789ea29ebca723e13edd08a51174b37aaa15fdec7829041025d471f
5
5
  SHA512:
6
- metadata.gz: 6929a5621c8a7fc76f64104fceaca556d00013a06465077fc47e328bc48dedda7668cd19b28f9a70bd63d3ae27fb19884ae4f327f74253b3a66bfd5e202975b3
7
- data.tar.gz: a309df26a0e9f3050f7c234b65a98cee13e32b038a1369479c5ad3c7c7e9ab2836542be35f9948716b74febbb5f48cfe896a6c5b2d47e4bcdf1c4d470cca3204
6
+ metadata.gz: 6f66092cfb1c2c047d6da054b295fa6dfd7796c9f01fe7543d9bfe680e5a57f0602fe48ae6f3733a8e65ea24fa29ad21ade20d18b90259a9784008f4e0876d7d
7
+ data.tar.gz: e9a801b3893c7eb6a99eada97974750a1f78dd6a084202b0d7545b7464486770e062a4b138cf5466a242cf32f84a38990bc423261ea80ecf61e9e112b3858750
@@ -63,15 +63,21 @@ class Params::Registry::Instance
63
63
  # resembles the output of `URI.decode_www_form`.
64
64
  #
65
65
  def initialize registry, struct, defaults: false, force: false
66
- struct = Types::Input[struct]
67
- @registry = registry
66
+ if registry.is_a? Params::Registry::Group
67
+ @group = registry
68
+ @registry = registry.registry
69
+ else
70
+ @group = nil
71
+ @registry = registry
72
+ end
73
+
68
74
  @content = {}
69
75
  @extra = {}
70
76
 
71
77
  # canonicalize the keys of the struct
72
- struct = struct.reduce({}) do |hash, pair|
78
+ struct = Types::Input[struct].reduce({}) do |hash, pair|
73
79
  key, value = pair
74
- if t = registry.templates[key]
80
+ if t = registry[@group][key]
75
81
  hash[t.id] = value
76
82
  else
77
83
  extra[key] = value
@@ -92,7 +98,7 @@ class Params::Registry::Instance
92
98
  # warn complements.class
93
99
 
94
100
  # now we get the ranked templates and pass them through
95
- registry.templates.ranked.each do |templates|
101
+ registry[@group].ranked.each do |templates|
96
102
  # give me the intersection of templates
97
103
  templates.values.each do |t|
98
104
 
@@ -166,11 +172,24 @@ class Params::Registry::Instance
166
172
 
167
173
  # Taxidermy this object as an ordinary hash.
168
174
  #
175
+ # @param slugs [true, false] whether to use slugs versus canonical keys.
176
+ # @param extra [false, true] whether to include the "extra" parameters.
177
+ #
169
178
  # @return [Hash] basically the same thing, minus its metadata.
170
179
  #
171
- def to_h
180
+ def to_h slugs: true, extra: false
181
+ # we're gonna do damage, lol
182
+ out = @content.dup
183
+
184
+ # this should work?
185
+ out.transform_keys! do |k|
186
+ registry[@group][k].slug || k.to_s.to_sym
187
+ end if slugs
188
+
172
189
  # XXX maybe enforce the ordering better??
173
- @content.merge @extra
190
+ out.merge! @extra if extra
191
+
192
+ out
174
193
  end
175
194
 
176
195
  # Retrieve an {Params::Registry::Instance} that isolates the
@@ -3,6 +3,6 @@
3
3
  module Params
4
4
  class Registry
5
5
  # The module version
6
- VERSION = "0.1.4"
6
+ VERSION = "0.1.6"
7
7
  end
8
8
  end
@@ -89,7 +89,7 @@ class Params::Registry
89
89
  template = registry.template_class.new registry, id, **spec
90
90
  end
91
91
 
92
- # amke sure we aren't calling ourselves
92
+ # make sure we aren't calling ourselves
93
93
  registry.templates[id] = template unless registry.templates.equal? self
94
94
 
95
95
  # okay now actually assign
@@ -209,6 +209,18 @@ class Params::Registry
209
209
  "#<#{self.class}: #{id} {#{keys.join ', '}}>"
210
210
  end
211
211
 
212
+ # Process the parameters and return a {Params::Registry::Instance}.
213
+ #
214
+ # @param params
215
+ # [String, URI, Hash{#to_sym => Array}, Array<Array<(#to_sym, Object)>>]
216
+ # the parameter set, in a dizzying variety of inputs.
217
+ #
218
+ # @return [Params::Registry::Instance] the instance.
219
+ #
220
+ def process params
221
+ registry.instance_class.new self, Types::Input[params]
222
+ end
223
+
212
224
  end
213
225
 
214
226
  private
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.4
4
+ version: 0.1.6
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-03 00:00:00.000000000 Z
11
+ date: 2024-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-types