params-registry 0.1.6 → 0.1.8

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: a2c64c0a41224198bdd02db7960b2051e74726bf690ddc66b222bc077bdeafd0
4
- data.tar.gz: 5bd14e8bb789ea29ebca723e13edd08a51174b37aaa15fdec7829041025d471f
3
+ metadata.gz: bcd8659d212d3467f58e09a552bc105d50e35bea4c695c40f9de744a978e4697
4
+ data.tar.gz: 03522f0aec72a7d4e3d329051ba18c60a6846cf96e1dfadc8efdea86c801f3d0
5
5
  SHA512:
6
- metadata.gz: 6f66092cfb1c2c047d6da054b295fa6dfd7796c9f01fe7543d9bfe680e5a57f0602fe48ae6f3733a8e65ea24fa29ad21ade20d18b90259a9784008f4e0876d7d
7
- data.tar.gz: e9a801b3893c7eb6a99eada97974750a1f78dd6a084202b0d7545b7464486770e062a4b138cf5466a242cf32f84a38990bc423261ea80ecf61e9e112b3858750
6
+ metadata.gz: 8e99fd842ae67daa05f39b60832f2ed03c1446b52b856ac6f661f7b3280cb567b0e7597d0d2f45c288542f14c188ab5be331a3989466c72378bbfdb213b2fca7
7
+ data.tar.gz: f5f0adaa738a61a7556c7e3e7f8eefccb498b0d835b6c774f56702ea938b8b02827f9c5d1f8289668b4d1719422febb8073b140737ce346c197fdeda34132d9c
@@ -64,8 +64,8 @@ class Params::Registry::Instance
64
64
  #
65
65
  def initialize registry, struct, defaults: false, force: false
66
66
  if registry.is_a? Params::Registry::Group
67
- @group = registry
68
- @registry = registry.registry
67
+ @group = registry.id
68
+ @registry = registry = registry.registry
69
69
  else
70
70
  @group = nil
71
71
  @registry = registry
@@ -74,13 +74,17 @@ class Params::Registry::Instance
74
74
  @content = {}
75
75
  @extra = {}
76
76
 
77
+ # warn "wtf lol #{@registry[@group].inspect}"
78
+
77
79
  # canonicalize the keys of the struct
78
80
  struct = Types::Input[struct].reduce({}) do |hash, pair|
79
81
  key, value = pair
80
- if t = registry[@group][key]
82
+ if t = @registry[@group][key]
83
+ # warn "yep #{key.inspect}"
81
84
  hash[t.id] = value
82
85
  else
83
- extra[key] = value
86
+ # warn "nope #{key.inspect}"
87
+ @extra[key] = value
84
88
  end
85
89
 
86
90
  hash
@@ -90,15 +94,15 @@ class Params::Registry::Instance
90
94
  del = Set[] # mark for deletion
91
95
 
92
96
  # grab the complements now
93
- complements = @content[registry.complement.id] =
94
- registry.complement.process(*struct.fetch(registry.complement.id, []))
97
+ complements = @content[@registry.complement.id] =
98
+ @registry.complement.process(*struct.fetch(@registry.complement.id, []))
95
99
 
96
100
  # warn registry.templates.ranked.inspect
97
101
 
98
102
  # warn complements.class
99
103
 
100
104
  # now we get the ranked templates and pass them through
101
- registry[@group].ranked.each do |templates|
105
+ @registry[@group].ranked.each do |templates|
102
106
  # give me the intersection of templates
103
107
  templates.values.each do |t|
104
108
 
@@ -178,13 +182,15 @@ class Params::Registry::Instance
178
182
  # @return [Hash] basically the same thing, minus its metadata.
179
183
  #
180
184
  def to_h slugs: true, extra: false
181
- # we're gonna do damage, lol
182
- out = @content.dup
185
+ g = registry[@group]
186
+
187
+ out = {}
183
188
 
184
- # this should work?
185
- out.transform_keys! do |k|
186
- registry[@group][k].slug || k.to_s.to_sym
187
- end if slugs
189
+ g.templates.each do |t|
190
+ next unless @content.key? t.id
191
+ key = slugs ? t.slug || t.id.to_s.to_sym : t.id
192
+ out[key] = @content[t.id]
193
+ end
188
194
 
189
195
  # XXX maybe enforce the ordering better??
190
196
  out.merge! @extra if extra
@@ -192,18 +198,18 @@ class Params::Registry::Instance
192
198
  out
193
199
  end
194
200
 
195
- # Retrieve an {Params::Registry::Instance} that isolates the
196
- # intersection of one or more groups
197
- #
198
- # @param group [Object] the group identifier.
199
- # @param extra [false, true] whether to include any "extra" unparsed
200
- # parameters.
201
- #
202
- # @return [Params::Registry::Instance] an instance containing just
203
- # the group(s) identified.
204
- #
205
- def group *group, extra: false
206
- end
201
+ # # Retrieve an {Params::Registry::Instance} that isolates the
202
+ # # intersection of one or more groups
203
+ # #
204
+ # # @param group [Object] the group identifier.
205
+ # # @param extra [false, true] whether to include any "extra" unparsed
206
+ # # parameters.
207
+ # #
208
+ # # @return [Params::Registry::Instance] an instance containing just
209
+ # # the group(s) identified.
210
+ # #
211
+ # def group *group, extra: false
212
+ # end
207
213
 
208
214
  # Serialize the instance back to a {::URI} query string.
209
215
  #
@@ -102,6 +102,15 @@ module Params::Registry::Types
102
102
  s.to_s.upcase.to_sym
103
103
  end
104
104
 
105
+ # This one is symbol-*ish*
106
+ Symbolish = self.Constructor(::Object) do |x|
107
+ if [::String, ::Symbol].any? { |c| x.is_a? c }
108
+ Symbol[x]
109
+ else
110
+ x
111
+ end
112
+ end
113
+
105
114
  # @!group Dates & Times
106
115
 
107
116
  # Ye olde {::Date}
@@ -151,15 +160,16 @@ module Params::Registry::Types
151
160
  input = ::URI.decode_www_form input if input.is_a? ::String
152
161
 
153
162
  case input
154
- when ::Hash then Hash.map(Symbol, Array.of(String))[input]
163
+ when ::Hash then Hash.map(Symbolish, Array.of(String))[input]
155
164
  when ::Array
156
165
  input.reduce({}) do |out, pair|
157
166
  k, *v = Strict::Array.constrained(min_size: 2)[pair]
158
- (out[k.to_sym] ||= []).push(*v)
167
+ (out[Symbolish[k]] ||= []).push(*v)
159
168
  out
160
169
  end
161
170
  else
162
- raise Dry::Types::CoercionError, "not sure what to do with #{input}"
171
+ raise Dry::Types::CoercionError,
172
+ "not sure what to do with #{input.inspect}"
163
173
  end
164
174
  end
165
175
 
@@ -3,6 +3,6 @@
3
3
  module Params
4
4
  class Registry
5
5
  # The module version
6
- VERSION = "0.1.6"
6
+ VERSION = "0.1.8"
7
7
  end
8
8
  end
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.6
4
+ version: 0.1.8
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-06 00:00:00.000000000 Z
11
+ date: 2024-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-types