shape_of 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/shape_of.rb +14 -6
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64fc24c8d36d335c6052f39457aac2f62dd4155538e57dda11c78e080748bac7
4
- data.tar.gz: ff28778300c41c9352a83da9d6ae2b95c75150dd5429abfd5e3a90c0dd1397e5
3
+ metadata.gz: f227bdcd2eb6f6161a565d653a11510cdbaeb9f7dca33d7e99ed704f574412b1
4
+ data.tar.gz: 177e743c8a22d03f56d7609ae478bd4ba5febd9b4da66e63b91ecab6a5119d11
5
5
  SHA512:
6
- metadata.gz: 0725a89f09c62099a96287fdc2c14080d004de6f1682e9cf09cefc6ed7300e535cfb7d375f7e913d8ccd22b5f2b23b52da8072aa85dbfe2cca3dc7d6480672b5
7
- data.tar.gz: e285973c38a51f6fcbb662e82322ea9bcb291388617849e0b86bdfd0e44cf2c4007ae456f5259fffef63f80d178c3f94016b49fa4ef2096c4d39a2e7992ae84d
6
+ metadata.gz: a06688a7273bc87e05a96c4d3efedffc4281dd29fdb005c07477be380e17f655c9c17e7d2947900d87989fb45ee2171e226194531f51d2487dd47df082e3e69b
7
+ data.tar.gz: 5b633d82d85b04fd41463d5a43dbda8da587a458bb77a50e02c8694202e26bc0a2eefb395924bd9d5ac50bdeca821ac66924aa0793f57f34afb1c50b358d705e
data/lib/shape_of.rb CHANGED
@@ -127,9 +127,9 @@ module ShapeOf
127
127
  end
128
128
  end
129
129
 
130
- # Array[Shape] denotes that it is an array of shapes.
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 Array, are the core components of this module.
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: Shape, ...] denotes it is a hash of shapes with a very specific structure. Hash (without square brackets) is just a hash with any shape.
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[Shape1, Shape2, ...] denotes that it can be of one the provided shapes
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[Shape] denotes that the usual type is a Shape, but is optional (meaning if it is nil or the key is not present in the Hash, it's still true)
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
- # Nothing only passes when the key does not exist in the Hash.
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,6 +319,9 @@ module ShapeOf
316
319
  end
317
320
  end
318
321
 
322
+ # Matches a Regexp against a String using Regexp#match?.
323
+ # Pretty much a wrapper around Regexp because a Regexp instance will be tested for equality
324
+ # in the ShapeOf::Hash and ShapeOf::Array since it's not a class.
319
325
  class Pattern < Shape
320
326
  def self.[](shape)
321
327
  raise TypeError, "Shape must be #{Regexp.inspect}, was #{shape.inspect}" unless shape.instance_of? Regexp
@@ -345,10 +351,12 @@ module ShapeOf
345
351
  end
346
352
  end
347
353
 
354
+ # Union[Integer, Float, Rational, Complex]
348
355
  Numeric = Union[Integer, Float, Rational, Complex].tap do |this|
349
356
  this.instance_variable_set(:@class_name, this.name.sub(/Union.*/, 'Numeric'))
350
357
  end
351
358
 
359
+ # Union[TrueClass, FalseClass]
352
360
  Boolean = Union[TrueClass, FalseClass].tap do |this|
353
361
  this.instance_variable_set(:@class_name, this.name.sub(/Union.*/, 'Boolean'))
354
362
  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: 2.0.1
4
+ version: 2.0.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-20 00:00:00.000000000 Z
11
+ date: 2021-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest