code-assertions 1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/code-assertions.rb +23 -2
- metadata +26 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b0b9be63fb9ea6439a11ca769e4a5f8469209c3c263ae5883a21398b2653fdb
|
4
|
+
data.tar.gz: 78d4a0d0ff834162b40f0cd7688aa86d4036eae032b7217b4757f67d319f6f3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3180d98fdc3c47cf30c29a1de6b95b8280273166ac33781ebc880229774035d8b9f54f6548a4f86fe7b30ff48714411bad92fc7b617778b4ee9a03b164aca2fb
|
7
|
+
data.tar.gz: 426a2aeb02e58a2a84198ca610e2ccd71a9853f8e7c67fe7bb885457349236f9bbcfa6073e685a91987b2302c29b0c7e6788dcc0711945a5385bc3b7e2a6a25a
|
data/lib/code-assertions.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "sourcify"
|
2
|
+
|
1
3
|
module CodeAssertions
|
2
4
|
class CodeAssertionFailed < StandardError; end
|
3
5
|
@@assertions_check = true
|
@@ -6,18 +8,37 @@ module CodeAssertions
|
|
6
8
|
@@assertions_check = false
|
7
9
|
end
|
8
10
|
|
9
|
-
|
11
|
+
alias :do_not_assert :assertions_off
|
12
|
+
|
13
|
+
def assert(message=nil, &block)
|
10
14
|
return unless @@assertions_check
|
11
|
-
|
15
|
+
unless block
|
16
|
+
warn "Empty assertion passed."
|
17
|
+
return
|
18
|
+
end
|
19
|
+
message = "Assertion failed: " + block.to_source[6...-1].strip unless message
|
12
20
|
raise CodeAssertionFailed, message unless block.call
|
13
21
|
end
|
14
22
|
|
15
23
|
def assert_not_nil(object)
|
16
24
|
assert("The result cannot be `nil` or `false`. #{object} given") { object }
|
17
25
|
end
|
26
|
+
alias :assert_nn :assert_not_nil
|
18
27
|
|
19
28
|
def assert_type(type, object)
|
20
29
|
assert("`type` should be an instance of `Class`") { type.is_a?(Class) }
|
21
30
|
assert("Wrong type: expected #{type.name}, given #{object.class.name}") { object.is_a?(type) }
|
22
31
|
end
|
32
|
+
|
33
|
+
def soft_assert(message=nil, &block)
|
34
|
+
return unless @@assertions_check
|
35
|
+
unless block
|
36
|
+
warn "Empty assertion passed."
|
37
|
+
return
|
38
|
+
end
|
39
|
+
message = "Assertion failed: " + block.to_source[6...-1].strip unless message
|
40
|
+
warn message unless block.call
|
41
|
+
end
|
23
42
|
end
|
43
|
+
|
44
|
+
include CodeAssertions
|
metadata
CHANGED
@@ -1,16 +1,37 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code-assertions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simone Scalabrino
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
11
|
+
date: 2019-08-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sourcify
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.5.0
|
20
|
+
- - "~>"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.5.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.5.0
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.5.0
|
33
|
+
description: Provides and includes a module that helps to make solid scripts for data
|
34
|
+
analysis
|
14
35
|
email: s.scalabrino9@gmail.com
|
15
36
|
executables: []
|
16
37
|
extensions: []
|
@@ -35,8 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
35
56
|
- !ruby/object:Gem::Version
|
36
57
|
version: '0'
|
37
58
|
requirements: []
|
38
|
-
|
39
|
-
rubygems_version: 2.7.7
|
59
|
+
rubygems_version: 3.0.4
|
40
60
|
signing_key:
|
41
61
|
specification_version: 4
|
42
62
|
summary: Simple code assertions toolkit for scripts
|