params-registry 0.1.6 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/params/registry/instance.rb +31 -25
- data/lib/params/registry/types.rb +13 -3
- data/lib/params/registry/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcd8659d212d3467f58e09a552bc105d50e35bea4c695c40f9de744a978e4697
|
4
|
+
data.tar.gz: 03522f0aec72a7d4e3d329051ba18c60a6846cf96e1dfadc8efdea86c801f3d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
182
|
-
|
185
|
+
g = registry[@group]
|
186
|
+
|
187
|
+
out = {}
|
183
188
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
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(
|
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
|
167
|
+
(out[Symbolish[k]] ||= []).push(*v)
|
159
168
|
out
|
160
169
|
end
|
161
170
|
else
|
162
|
-
raise Dry::Types::CoercionError,
|
171
|
+
raise Dry::Types::CoercionError,
|
172
|
+
"not sure what to do with #{input.inspect}"
|
163
173
|
end
|
164
174
|
end
|
165
175
|
|
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
|
+
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-
|
11
|
+
date: 2024-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-types
|