shape_of 0.2.0 → 1.1.1
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 +4 -4
- data/lib/shape_of.rb +2 -43
- 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: 1b4935ae23d9b1478648c71bf1c2fa2f1ef02cd0ca8817ad5ba8b82e4a3e1af1
|
4
|
+
data.tar.gz: f67e5ef3f03f1ad27d55d10b2c2400cfed6d216de7d8e35d6b81f5f643d19289
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14cda0fb707a8a43269f9f19f52994920b2117449c0afcd3911c41706320cb0fb0b7565922ab627ad1be66908de9bf32d120f86db27b0bd2aa2fe086a80adcd9
|
7
|
+
data.tar.gz: ae65c4e28e748a9f3e361c51a66a4e84da83d07c7f579cb03758e1bf126b5d858a48a38949a10653704edc97fac6201d4ff1725773ca26e8dbc7da3fb89c76f4
|
data/lib/shape_of.rb
CHANGED
@@ -161,7 +161,7 @@ module ShapeOf
|
|
161
161
|
if @shape.respond_to? :shape_of?
|
162
162
|
@shape.shape_of? elem
|
163
163
|
elsif @shape.is_a? ::Array
|
164
|
-
Array[@shape].shape_of? elem
|
164
|
+
Array[@shape.first].shape_of? elem
|
165
165
|
elsif @shape.is_a? ::Hash
|
166
166
|
Hash[@shape].shape_of? elem
|
167
167
|
elsif @shape.is_a? Class
|
@@ -222,7 +222,7 @@ module ShapeOf
|
|
222
222
|
if @shape[key].respond_to? :shape_of?
|
223
223
|
@shape[key].shape_of? elem
|
224
224
|
elsif @shape[key].is_a? ::Array
|
225
|
-
Array[@shape[key]].shape_of? elem
|
225
|
+
Array[@shape[key].first].shape_of? elem
|
226
226
|
elsif @shape[key].is_a? ::Hash
|
227
227
|
Hash[@shape[key]].shape_of? elem
|
228
228
|
elsif @shape[key].is_a? Class
|
@@ -316,47 +316,6 @@ module ShapeOf
|
|
316
316
|
end
|
317
317
|
end
|
318
318
|
|
319
|
-
class Regexp < Shape
|
320
|
-
@internal_class = ::Regexp
|
321
|
-
|
322
|
-
def self.shape_of?(object)
|
323
|
-
object.instance_of? @internal_class
|
324
|
-
end
|
325
|
-
|
326
|
-
def self.[](shape)
|
327
|
-
raise TypeError, "Shape must be #{::Regexp.inspect}, was #{shape.inspect}" unless shape.instance_of? ::Regexp
|
328
|
-
|
329
|
-
Class.new(self) do
|
330
|
-
@class_name = "#{superclass.name}[#{shape.inspect}]"
|
331
|
-
@shape = shape
|
332
|
-
|
333
|
-
def self.name
|
334
|
-
@class_name
|
335
|
-
end
|
336
|
-
|
337
|
-
def self.to_s
|
338
|
-
@class_name
|
339
|
-
end
|
340
|
-
|
341
|
-
def self.inspect
|
342
|
-
@class_name
|
343
|
-
end
|
344
|
-
|
345
|
-
def self.shape_of?(object)
|
346
|
-
unless object.instance_of?(::Regexp) || object.instance_of?(String)
|
347
|
-
raise TypeError, "expected #{::Regexp.inspect} or #{String.inspect}, was instead #{object.inspect}"
|
348
|
-
end
|
349
|
-
|
350
|
-
if object.instance_of?(::Regexp)
|
351
|
-
@shape == object
|
352
|
-
else # string
|
353
|
-
@shape.match?(object)
|
354
|
-
end
|
355
|
-
end
|
356
|
-
end
|
357
|
-
end
|
358
|
-
end
|
359
|
-
|
360
319
|
Numeric = Union[Integer, Float, Rational, Complex].tap do |this|
|
361
320
|
this.instance_variable_set(:@class_name, this.name.sub(/Union.*/, 'Numeric'))
|
362
321
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shape_of
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Isom
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|