nullobject_chain 0.0.1 → 1.0.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.
- data/lib/nullobject_chain.rb +13 -4
- metadata +3 -2
data/lib/nullobject_chain.rb
CHANGED
@@ -1,18 +1,27 @@
|
|
1
1
|
class NullChainer < BasicObject
|
2
|
+
class << self
|
3
|
+
attr_accessor :use_nullobject
|
4
|
+
end
|
5
|
+
@use_nullobject = false
|
6
|
+
|
2
7
|
def initialize(obj)
|
3
8
|
@obj = obj
|
4
9
|
end
|
5
10
|
|
6
11
|
def get
|
7
|
-
@obj
|
12
|
+
if @obj.is_a?(::NilClass) && ::NullChainer.use_nullobject
|
13
|
+
::Null::Object.instance
|
14
|
+
else
|
15
|
+
@obj
|
16
|
+
end
|
8
17
|
end
|
9
18
|
|
10
19
|
def method_missing(name, *args, &block)
|
11
20
|
begin
|
12
|
-
::NullChainer.new(@obj.send(name, *args, &block))
|
21
|
+
::NullChainer.new(@obj.send(name, *args, &block))
|
13
22
|
rescue ::NoMethodError
|
14
23
|
if @obj.nil?
|
15
|
-
::NullChainer.new(
|
24
|
+
::NullChainer.new(nil)
|
16
25
|
else
|
17
26
|
super
|
18
27
|
end
|
@@ -22,4 +31,4 @@ end
|
|
22
31
|
|
23
32
|
def NullChain(obj)
|
24
33
|
NullChainer.new(obj)
|
25
|
-
end
|
34
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nullobject_chain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nullobject
|
@@ -59,3 +59,4 @@ signing_key:
|
|
59
59
|
specification_version: 3
|
60
60
|
summary: Chain methods on nil without getting exceptions.
|
61
61
|
test_files: []
|
62
|
+
has_rdoc:
|