arguard 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/lib/arguard/guards/collections_guard.rb +25 -0
- data/lib/arguard/guards/numbers_guard.rb +18 -0
- data/lib/arguard/guards/objects_guard.rb +34 -0
- data/lib/arguard/guards/strings_guard.rb +11 -0
- data/lib/arguard/version.rb +1 -1
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b339c5c4e7efe5e57314c5d5e3a8f4523931c803
|
4
|
+
data.tar.gz: 42b67d7e8e33bab16c9b55c3cf9c18016f9e6ab9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '076796418a5c1fd89e72b0cf15e0076d92cb8b1e6b22c362295ab738379b235f83ef204fe49a7eff3e84bef6a0dd6c1c744363582725c541d12d6ddf41b8798c'
|
7
|
+
data.tar.gz: 9ab109d37b797c02226ab4698929e993b98c318e7cd1f7b817c3f910e72a27b082dcf45319c0b3d2958e12fa9a41c569fac7f8f5ed3e01e118ace9630c964bc9
|
data/.gitignore
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
# This file is subject to the terms and conditions defined in
|
2
|
+
# file 'LICENSE.txt', which is part of this source code package.
|
3
|
+
module Arguard
|
4
|
+
module Guards
|
5
|
+
module CollectionsGuard
|
6
|
+
def not_nil!
|
7
|
+
self.each do |item|
|
8
|
+
item.not_nil!
|
9
|
+
end
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
def not_empty!
|
14
|
+
if self.size == 0
|
15
|
+
raise ArgumentError.new('Collection must not be empty.')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def not_nil_not_empty!
|
20
|
+
self.not_nil!.not_empty!
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# This file is subject to the terms and conditions defined in
|
2
|
+
# file 'LICENSE.txt', which is part of this source code package.
|
3
|
+
module Arguard
|
4
|
+
module Guards
|
5
|
+
module NumbersGuard
|
6
|
+
|
7
|
+
def odd!(message = nil)
|
8
|
+
unless odd?
|
9
|
+
exc_message = message.nil? ? 'Number must be odd.' : "Number must be odd. Message: '#{message}'"
|
10
|
+
|
11
|
+
raise ArgumentError.new(exc_message)
|
12
|
+
end
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# This file is subject to the terms and conditions defined in
|
2
|
+
# file 'LICENSE.txt', which is part of this source code package.
|
3
|
+
module Arguard
|
4
|
+
module Guards
|
5
|
+
module ObjectsGuard
|
6
|
+
def not_nil!(object_name = nil)
|
7
|
+
if self.nil?
|
8
|
+
exc_message = object_name.nil? ? "Object must not be nil. Class: '#{self.class.name}'" : "Object must not be nil. Class: '#{self.class.name}', Name: '#{object_name}'"
|
9
|
+
|
10
|
+
raise ArgumentError.new(exc_message)
|
11
|
+
end
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def true!(message = nil)
|
16
|
+
unless self.class == TrueClass
|
17
|
+
exc_message = message.nil? ? 'Condition must be true.' : "Condition must be true. Message: '#{message}'"
|
18
|
+
|
19
|
+
raise ArgumentError.new(exc_message)
|
20
|
+
end
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def false!(message = nil)
|
25
|
+
unless self.class == FalseClass
|
26
|
+
exc_message = message.nil? ? 'Condition must be false.' : "Condition must be false. Message: '#{message}'"
|
27
|
+
|
28
|
+
raise ArgumentError.new(exc_message)
|
29
|
+
end
|
30
|
+
self
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/arguard/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arguard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Helmut Juskewycz - hemju
|
@@ -88,6 +88,10 @@ files:
|
|
88
88
|
- bin/console
|
89
89
|
- bin/setup
|
90
90
|
- lib/arguard.rb
|
91
|
+
- lib/arguard/guards/collections_guard.rb
|
92
|
+
- lib/arguard/guards/numbers_guard.rb
|
93
|
+
- lib/arguard/guards/objects_guard.rb
|
94
|
+
- lib/arguard/guards/strings_guard.rb
|
91
95
|
- lib/arguard/version.rb
|
92
96
|
homepage: http://hemju.com
|
93
97
|
licenses:
|