nullz 0.5.0 → 0.6.0
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/Gemfile.lock +1 -1
- data/lib/null_object.rb +78 -77
- data/lib/nullz/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0e3503834934297d10f1b0631230645fbad2c96c5461a27f85b37bc1093462e
|
4
|
+
data.tar.gz: 144e0d1fdf69dcc32874be9e892ff1def5bae5cebe7826fde87201eb5de9c7f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c12d55139debb4c3d702cb3f3d241e2798fc4f550d8d9dcfa4e7318bca2f65c749a6786376bcaacde846c60e7764b1babe0dbbb0b865049ed709aa5af572c3a
|
7
|
+
data.tar.gz: 89b40bd49c475a9d195598bf42e30a0fe64867d1d563e6bcb6572c427ec72469e11bf12aff5917133ab8126168405ebaae2734d7ced7a94388106d8c28600900
|
data/Gemfile.lock
CHANGED
data/lib/null_object.rb
CHANGED
@@ -1,93 +1,94 @@
|
|
1
1
|
require 'nullz/version'
|
2
2
|
|
3
|
-
ON_NULL_OBJECT_CREATED = Proc.new { }
|
4
|
-
USE_NULL_OBJECT = false
|
5
|
-
|
6
3
|
def _(obj)
|
7
|
-
obj || NullObject.new
|
4
|
+
obj || Nullz::NullObject.new
|
8
5
|
end
|
9
6
|
|
10
|
-
def __(obj, on_null_object_created_proc = ON_NULL_OBJECT_CREATED)
|
7
|
+
def __(obj, on_null_object_created_proc = Nullz::ON_NULL_OBJECT_CREATED)
|
11
8
|
return obj if obj
|
12
9
|
|
13
10
|
on_null_object_created_proc.call
|
14
11
|
|
15
|
-
NullObject.new
|
12
|
+
Nullz::NullObject.new
|
16
13
|
end
|
17
14
|
|
18
|
-
def safe(obj, on_null_object_created_proc = ON_NULL_OBJECT_CREATED)
|
19
|
-
USE_NULL_OBJECT ? __(obj, on_null_object_created_proc) : obj
|
15
|
+
def safe(obj, on_null_object_created_proc = Nullz::ON_NULL_OBJECT_CREATED)
|
16
|
+
Nullz::USE_NULL_OBJECT ? __(obj, on_null_object_created_proc) : obj
|
20
17
|
end
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
19
|
+
module Nullz
|
20
|
+
ON_NULL_OBJECT_CREATED = Proc.new { }
|
21
|
+
USE_NULL_OBJECT = false
|
22
|
+
|
23
|
+
class NullObject
|
24
|
+
def method_missing(method, *_args, &_block)
|
25
|
+
return false if method.to_s.index('?')
|
26
|
+
NullObject.new unless method == :to_ary
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_s
|
30
|
+
''
|
31
|
+
end
|
32
|
+
|
33
|
+
alias_method :to_str, :to_s
|
34
|
+
|
35
|
+
def coerce(value)
|
36
|
+
[NullObject.new, value]
|
37
|
+
end
|
38
|
+
|
39
|
+
def return_null_object(_value)
|
40
|
+
NullObject.new
|
41
|
+
end
|
42
|
+
|
43
|
+
alias_method :+, :return_null_object
|
44
|
+
alias_method :-, :return_null_object
|
45
|
+
alias_method :*, :return_null_object
|
46
|
+
alias_method :/, :return_null_object
|
47
|
+
alias_method :|, :return_null_object
|
48
|
+
alias_method :^, :return_null_object
|
49
|
+
alias_method :~, :return_null_object
|
50
|
+
alias_method :&, :return_null_object
|
51
|
+
alias_method :[], :return_null_object
|
52
|
+
alias_method :<<, :return_null_object
|
53
|
+
alias_method :>>, :return_null_object
|
54
|
+
|
55
|
+
def ==(value)
|
56
|
+
value.nil?
|
57
|
+
end
|
58
|
+
|
59
|
+
def !=(value)
|
60
|
+
!value.nil?
|
61
|
+
end
|
62
|
+
|
63
|
+
def to_int
|
64
|
+
0
|
65
|
+
end
|
66
|
+
|
67
|
+
def to_bool
|
68
|
+
false
|
69
|
+
end
|
70
|
+
|
71
|
+
alias_method :to_b, :to_bool
|
72
|
+
|
73
|
+
def >(_value)
|
74
|
+
return false
|
75
|
+
end
|
76
|
+
|
77
|
+
def <(_value)
|
78
|
+
return false
|
79
|
+
end
|
80
|
+
|
81
|
+
def empty?
|
82
|
+
true
|
83
|
+
end
|
84
|
+
|
85
|
+
def nil?
|
86
|
+
true
|
87
|
+
end
|
88
|
+
|
89
|
+
def null?
|
90
|
+
true
|
91
|
+
end
|
90
92
|
end
|
91
93
|
end
|
92
94
|
|
93
|
-
|
data/lib/nullz/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nullz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Jacobs
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|