shape_of 0.2.0 → 0.2.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/shape_of.rb +6 -18
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9663853638d239d448381e9ab748aeb7813a76b42ed9bd97c423f6d142c95d80
4
- data.tar.gz: b1bdfeb51c08760c7c83519ce640c48d1202d23f3878adb93a2824761525219e
3
+ metadata.gz: cf335e236284c12e251182de9ed6d299a732e9a9c08802702da1982e74c07a05
4
+ data.tar.gz: 417d9223a3a039c70205dcff26d23844a5067e2ffe2dad1b38f3d84644399123
5
5
  SHA512:
6
- metadata.gz: 49cc6be2be276d554b25affe85bd97aca4ff3a134ee2a6334a0d37f35982f34ff28c39d3ce090418d2843b15dbc9d4b5b3bcbe568be69acbed90e31bcfab1ec6
7
- data.tar.gz: cbaa2ed60315ffc111228a0f2093e950ad930a5ecbbba25c471f2d55044d1f14829e040e04d6e6705fcb767519994b1df46b67d0e61ea1046d90a54b87ff3057
6
+ metadata.gz: bb681e7c250d0ef0f81c66ebbf126cc1f7f13fef4dce314364686fa6301181009a0e8e961a6ea23e724aea6737bcde9643a096e168379a43825e953050fe97b1
7
+ data.tar.gz: a46c0b1712c6003c75edf9a5641fc03f1a64672b0b6e2882cfaa996a8b3a0609306b53a0184d6cb2924132cc4ca94f55b0adf2fc4413822224568518c1eeca30
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,15 +316,9 @@ 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
-
319
+ class Pattern < Shape
326
320
  def self.[](shape)
327
- raise TypeError, "Shape must be #{::Regexp.inspect}, was #{shape.inspect}" unless shape.instance_of? ::Regexp
321
+ raise TypeError, "Shape must be #{Regexp.inspect}, was #{shape.inspect}" unless shape.instance_of? Regexp
328
322
 
329
323
  Class.new(self) do
330
324
  @class_name = "#{superclass.name}[#{shape.inspect}]"
@@ -343,15 +337,9 @@ module ShapeOf
343
337
  end
344
338
 
345
339
  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
340
+ raise TypeError, "expected #{String.inspect}, was instead #{object.inspect}" unless object.instance_of?(String)
349
341
 
350
- if object.instance_of?(::Regexp)
351
- @shape == object
352
- else # string
353
- @shape.match?(object)
354
- end
342
+ @shape.match?(object)
355
343
  end
356
344
  end
357
345
  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: 0.2.0
4
+ version: 0.2.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-17 00:00:00.000000000 Z
11
+ date: 2021-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest