data_broker 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/data_broker/value_object.rb +4 -4
- data/lib/data_broker/version.rb +1 -1
- data/spec/value_object_spec.rb +16 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f32478a97e2546d624a27f40f448c0484a908df
|
4
|
+
data.tar.gz: 4a47b36b74abe48ac555cfc565f120b1937f3166
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69a70b5a00188fd407e070bd959f5548d0a0c0b9e8891ec9188138feb6ec16d472fa8a939891692a7f3ecdf2c7048922404daab262952f20d97b09e4a9b8fb7c
|
7
|
+
data.tar.gz: c2b549315d6190b4e2e5e28ff7a1e66988e1748e3fbcc8d5db736a5c9949cd7ce2feaaafc8e568c3c30ffbd807124e6f6f56466681567acaf57d6435cd1bf833
|
@@ -71,13 +71,13 @@ module DataBroker
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
def delegate(method, to: nil)
|
74
|
+
def delegate(method, to: nil, return_on_nil: nil)
|
75
75
|
delegated = "#{to}_#{method}"
|
76
76
|
define_method(delegated) do
|
77
77
|
ivar = "@#{delegated}"
|
78
|
-
instance_variable_get(ivar) ||
|
79
|
-
ivar, send(to).try(method)
|
80
|
-
|
78
|
+
instance_variable_get(ivar) ||
|
79
|
+
instance_variable_set(ivar, send(to).try(method)) ||
|
80
|
+
return_on_nil
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
data/lib/data_broker/version.rb
CHANGED
data/spec/value_object_spec.rb
CHANGED
@@ -14,6 +14,7 @@ class TestValueObject
|
|
14
14
|
has_many :friends
|
15
15
|
|
16
16
|
delegate :name, :to => :parent
|
17
|
+
delegate :recipes, :to => :parent, :return_on_nil => []
|
17
18
|
end
|
18
19
|
|
19
20
|
class TestValueObjectWithType
|
@@ -158,11 +159,22 @@ describe DataBroker::ValueObject do
|
|
158
159
|
expect(obj.parent_name).to eq("Bobby")
|
159
160
|
end
|
160
161
|
|
161
|
-
|
162
|
-
|
163
|
-
|
162
|
+
context "with no return_on_nil value specified" do
|
163
|
+
it "returns nil if the delegated object is nil" do
|
164
|
+
obj = TestValueObject.new
|
165
|
+
allow(obj).to receive(:parent) { nil }
|
166
|
+
|
167
|
+
expect(obj.parent_name).to be_nil
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context "with a return_on_nil value specified" do
|
172
|
+
it "returns the specified value if delegated object is nil" do
|
173
|
+
obj = TestValueObject.new
|
174
|
+
allow(obj).to receive(:parent) { nil }
|
164
175
|
|
165
|
-
|
176
|
+
expect(obj.parent_recipes).to be_empty
|
177
|
+
end
|
166
178
|
end
|
167
179
|
|
168
180
|
it "memoizes the results" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_broker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Emmons
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|