isy 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.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/isy/methods.rb +11 -16
- data/lib/isy/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d069d9988e704be2859166c1a1f070b6f319761e
|
4
|
+
data.tar.gz: 844eb46166ab5e3f90e8eb2be820b26e960789b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37c2bc3fa5c1f7803c7df1361ef0dc51d813fed5d4f41cea149d13ef4d3978f3b76c76062c88374f48f61ba05d3d75b9f412e8206c2cff58d9d56acb16ca1f31
|
7
|
+
data.tar.gz: cffc758e1b3b9033585dcd2fcd2ab2ea1ad3990818783d2dcffdba96f40f3bda5e04edc633b99f906fd7eefad72c1088483be34637f602fb999c42b1a38e5192
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Isy
|
2
|
+
*(pronounced like 'izzy')*
|
2
3
|
|
3
4
|
[](https://travis-ci.org/acuppy/isy)
|
4
5
|
[](https://codeclimate.com/github/acuppy/isy)
|
@@ -33,7 +34,7 @@ end
|
|
33
34
|
```
|
34
35
|
|
35
36
|
The first argument is the subject of the test (i.e. what should match the proceeding assertion)
|
36
|
-
The second argument is the type
|
37
|
+
The second argument is the class, `Range`, `Regexp` or any object (type) which responds to `===`.
|
37
38
|
|
38
39
|
If the subject doesn't match the provided type, then it raises a formatted exception describing
|
39
40
|
what argument *value* was a type mismatch (as an `Isy::ArgumentTypeMismatch` exception).
|
data/lib/isy/methods.rb
CHANGED
@@ -34,23 +34,13 @@ module Isy
|
|
34
34
|
# As illustrated above, `isy` yields to the operation the first argument (segments). The expectation
|
35
35
|
# is that the value returned by the operation (block) is a boolen (true => passes, false => failed).
|
36
36
|
#
|
37
|
-
def isy subject,
|
38
|
-
|
39
|
-
raise ArgumentError,
|
40
|
-
'Object#isy requires either a type or evaluation block'
|
41
|
-
end
|
42
|
-
|
43
|
-
evaluation ||= ->(s) { s.is_a? args[0] }
|
44
|
-
is_valid = !!(evaluation.call subject)
|
45
|
-
|
46
|
-
unless is_valid
|
37
|
+
def isy subject, evaluation=nil, &block
|
38
|
+
unless isy? subject, evaluation, &block
|
47
39
|
raise Isy::ArgumentTypeMismatch.new(
|
48
40
|
subject: subject,
|
49
41
|
caller_method: caller_locations(1,1)[0].label
|
50
42
|
)
|
51
43
|
end
|
52
|
-
|
53
|
-
is_valid
|
54
44
|
end
|
55
45
|
|
56
46
|
# Isy::Methods#isy?
|
@@ -79,10 +69,15 @@ module Isy
|
|
79
69
|
# As illustrated above, `isy?` yields to the operation the first argument (segments). The expectation
|
80
70
|
# is that the value returned by the operation (block) is a boolen (true => passes, false => failed).
|
81
71
|
#
|
82
|
-
def isy? subject,
|
83
|
-
|
84
|
-
|
85
|
-
|
72
|
+
def isy? subject, evaluation=nil, &block
|
73
|
+
tester = block || evaluation
|
74
|
+
|
75
|
+
unless tester
|
76
|
+
raise ArgumentError,
|
77
|
+
'Object#isy requires either a type or evaluation block'
|
78
|
+
end
|
79
|
+
|
80
|
+
tester === subject
|
86
81
|
end
|
87
82
|
end
|
88
83
|
end
|
data/lib/isy/version.rb
CHANGED