code-assertions 1.0 → 1.1.1

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/code-assertions.rb +23 -2
  3. metadata +26 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2804bd98e0251fcb8cc571796413909921b4f06eb89c4ff91eca395b127ca49a
4
- data.tar.gz: b25bfce9824a17c3b5c0def39e5bd6005d60a386127014ac97bc5124bac873d0
3
+ metadata.gz: 8b0b9be63fb9ea6439a11ca769e4a5f8469209c3c263ae5883a21398b2653fdb
4
+ data.tar.gz: 78d4a0d0ff834162b40f0cd7688aa86d4036eae032b7217b4757f67d319f6f3a
5
5
  SHA512:
6
- metadata.gz: 91a7f9f4fddb841b39e9b5e8eebba763442b510b8a339aca494e9a54654f9519d247b118453ade12b387f43eb0baf372f426a48b6e7fd9b88009b82996d7b25f
7
- data.tar.gz: 9514483542a6b69fbd11a0caea40ddc4561247b8c6ce2b7c3997a4f275e5c68cdbcaf4aea9302b324f5c65a3a4d4316bd5c8f7de1eee6d4d2f2ed034cafce77b
6
+ metadata.gz: 3180d98fdc3c47cf30c29a1de6b95b8280273166ac33781ebc880229774035d8b9f54f6548a4f86fe7b30ff48714411bad92fc7b617778b4ee9a03b164aca2fb
7
+ data.tar.gz: 426a2aeb02e58a2a84198ca610e2ccd71a9853f8e7c67fe7bb885457349236f9bbcfa6073e685a91987b2302c29b0c7e6788dcc0711945a5385bc3b7e2a6a25a
@@ -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
- def assert(message="Assertion failed", &block)
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: '1.0'
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: 2018-10-18 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Provides a module that helps to make solid scripts for data analysis
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
- rubyforge_project:
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