params-registry 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a042bd9fe8e18875fbe751867cf08830d8e23e965c0b4c9053e1948a474fe6da
4
- data.tar.gz: 37c92f7e5de26e422eda6441696c17319009edf0a57eeac813f118b8d7055c7b
3
+ metadata.gz: a176c219561e992201c81af4cfa87b348fd408a5d52121ae9483004fdf073af3
4
+ data.tar.gz: 3d532a4041860f3c09df1c5802e3e4dc27931cd98e13b1a5355f9251a7c73f83
5
5
  SHA512:
6
- metadata.gz: 3e0c5afa52cc9fde678195fdc48e52c470ca7061d70f478216937a8485b38c5f071904992b53370ce8fba63cbbe397041cbf1c852f476b99edd548f756cad25d
7
- data.tar.gz: 39e52f72ecf4f60f7834d9f406a5cb98f2d9e161ea5bfe01d34fb3ae821dbb454f4813286056e772457b4a9f1caae75d12681d98220db8c945ba858652c5996e
6
+ metadata.gz: 52eda8b9e02f1f82dd908a07d5c2f4f1179ec2a401dff5562b582f55bdc4989d11ae5956664784fc1dfcd58ccaa5d6899aa0d651794021f408e9c0e84c65c188
7
+ data.tar.gz: bf940c462597a0c43123e72f795e17f7778ff7ec2b73c7b9bcaea5c2e09b3a7472767342a12d4d155321c1033cf291571a0d91158745c6bae09af7f33f49ec4e
@@ -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
 
@@ -172,11 +176,24 @@ class Params::Registry::Instance
172
176
 
173
177
  # Taxidermy this object as an ordinary hash.
174
178
  #
179
+ # @param slugs [true, false] whether to use slugs versus canonical keys.
180
+ # @param extra [false, true] whether to include the "extra" parameters.
181
+ #
175
182
  # @return [Hash] basically the same thing, minus its metadata.
176
183
  #
177
- def to_h
184
+ def to_h slugs: true, extra: false
185
+ # we're gonna do damage, lol
186
+ out = @content.dup
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
192
+
178
193
  # XXX maybe enforce the ordering better??
179
- @content.merge @extra
194
+ out.merge! @extra if extra
195
+
196
+ out
180
197
  end
181
198
 
182
199
  # Retrieve an {Params::Registry::Instance} that isolates the
@@ -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.5"
6
+ VERSION = "0.1.7"
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.5
4
+ version: 0.1.7
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-04 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