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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3bdf2caa154cb9aff4167f9f3c34da98bc81d40b
4
- data.tar.gz: 1ab25391bafc416d9bb155a180f5550bd9847ddf
3
+ metadata.gz: 3f32478a97e2546d624a27f40f448c0484a908df
4
+ data.tar.gz: 4a47b36b74abe48ac555cfc565f120b1937f3166
5
5
  SHA512:
6
- metadata.gz: f54726074561fdcdbfd5815dde4ea327c0bd478adc6830fa75b3b97ccbe9d2a9a6c572c97723e555e74abb6f584e96ee7c9cb1ac806161f3069e040743ea9830
7
- data.tar.gz: a697735fce73e3639fdc2a25d912268d27dce356e05a025f9716d5f4bb0205c2fb37ca3a7f0b2e7bdad6f0ec0bc553d5200c76bc6f4c348705b7594081ad827e
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) || instance_variable_set(
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
@@ -1,3 +1,3 @@
1
1
  module DataBroker
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -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
- it "returns nil if the delegated object is nil" do
162
- obj = TestValueObject.new
163
- allow(obj).to receive(:parent) { nil }
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
- expect(obj.parent_name).to be_nil
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.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-01-23 00:00:00.000000000 Z
11
+ date: 2014-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus