shape_of 1.1.1 → 1.1.2
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 +11 -6
- 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: a15e41f23fb7b198036f33f6099ff66a25d2ed5ca9bcc65c12f5ae78417f260a
|
4
|
+
data.tar.gz: df2f851769ee13aac6c5845de131af0c2ade259e96d4c22876ac61091eed0c89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 955b6f608e4cb0a3be5a8590c7cc260a6cb65b50c84736b129a61729889d1e08c15ff125a2f5cf6509bab558a9c016781363c3874a95230d6f193a5e97c8505b
|
7
|
+
data.tar.gz: d3d8f89ddc5c9d9e54513bfc69529f4262e6036a5dc02db0cf304b777ac16f82a96da50c132a79188faf5ef165381c9e2db8c5c45ec9a935bfc9647d2ee93282
|
data/lib/shape_of.rb
CHANGED
@@ -127,9 +127,9 @@ module ShapeOf
|
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
130
|
-
# Array[
|
130
|
+
# Array[shape] denotes that it is an array of shapes.
|
131
131
|
# It checks every element in the array and verifies that the element is in the correct shape.
|
132
|
-
# This, along with
|
132
|
+
# This, along with Hash, are the core components of this module.
|
133
133
|
# Note that a ShapeOf::Array[Integer].shape_of?([]) will pass because it is vacuously true for an empty array.
|
134
134
|
class Array < Shape
|
135
135
|
@internal_class = ::Array
|
@@ -175,7 +175,8 @@ module ShapeOf
|
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
178
|
-
# Hash[key:
|
178
|
+
# Hash[key: shape, ...] denotes it is a hash of shapes with a very specific structure.
|
179
|
+
# Hash (without square brackets) is just a hash with any shape.
|
179
180
|
# This, along with Array, are the core components of this module.
|
180
181
|
# Note that the keys are converted to strings for comparison for both the shape and object provided.
|
181
182
|
class Hash < Shape
|
@@ -242,7 +243,7 @@ module ShapeOf
|
|
242
243
|
end
|
243
244
|
end
|
244
245
|
|
245
|
-
# Union[
|
246
|
+
# Union[shape1, shape2, ...] denotes that it can be of one the provided shapes.
|
246
247
|
class Union < Shape
|
247
248
|
def self.[](*shapes)
|
248
249
|
Class.new(self) do
|
@@ -280,7 +281,8 @@ module ShapeOf
|
|
280
281
|
end
|
281
282
|
end
|
282
283
|
|
283
|
-
# Optional[
|
284
|
+
# Optional[shape] denotes that the usual type is a shape, but is optional
|
285
|
+
# (meaning if it is nil or the key is not present in the Hash, it's still true)
|
284
286
|
class Optional < Shape
|
285
287
|
def self.[](shape)
|
286
288
|
raise TypeError, "Shape cannot be nil" if shape.nil? || shape == NilClass
|
@@ -299,13 +301,14 @@ module ShapeOf
|
|
299
301
|
end
|
300
302
|
end
|
301
303
|
|
304
|
+
# Anything matches unless key does not exist in the Hash.
|
302
305
|
class Any < Shape
|
303
306
|
def self.shape_of?(object)
|
304
307
|
true
|
305
308
|
end
|
306
309
|
end
|
307
310
|
|
308
|
-
#
|
311
|
+
# Only passes when the key does not exist in the Hash.
|
309
312
|
class Nothing < Shape
|
310
313
|
def self.shape_of?(object)
|
311
314
|
false
|
@@ -316,10 +319,12 @@ module ShapeOf
|
|
316
319
|
end
|
317
320
|
end
|
318
321
|
|
322
|
+
# Union[Integer, Float, Rational, Complex]
|
319
323
|
Numeric = Union[Integer, Float, Rational, Complex].tap do |this|
|
320
324
|
this.instance_variable_set(:@class_name, this.name.sub(/Union.*/, 'Numeric'))
|
321
325
|
end
|
322
326
|
|
327
|
+
# Union[TrueClass, FalseClass]
|
323
328
|
Boolean = Union[TrueClass, FalseClass].tap do |this|
|
324
329
|
this.instance_variable_set(:@class_name, this.name.sub(/Union.*/, 'Boolean'))
|
325
330
|
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: 1.1.
|
4
|
+
version: 1.1.2
|
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-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|