mediator 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -54,12 +54,14 @@ class Mediator
54
54
  def many name, options = {}, &block
55
55
  options = {construct: true}.merge options
56
56
 
57
+ data = get(name, options)
58
+ return if data.nil? and !options[:empty] # Can't use main empty? call here as [] does not count as empty..
59
+
57
60
  mediator.set name, [] unless options[:merge]
58
61
 
59
- data = get(name, options) || []
60
62
  subj = (options && options[:subject]) || mediator.get(name, options)
61
63
 
62
- data.each do |d|
64
+ (data || []).each do |d|
63
65
  name = name[0..-2] if name[-1] == "s"
64
66
  s = mediator.construct name
65
67
  sub s, d, options, &block
data/mediator.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
9
9
  gem.test_files = `git ls-files -- test/*`.split "\n"
10
10
  gem.name = "mediator"
11
11
  gem.require_paths = ["lib"]
12
- gem.version = "0.4.0"
12
+ gem.version = "0.4.1"
13
13
 
14
14
  gem.required_ruby_version = ">= 1.9.2"
15
15
  end
@@ -255,6 +255,32 @@ describe Mediator::Parser do
255
255
  assert_equal ["blup?"], s.foos.map(&:baz)
256
256
  end
257
257
 
258
+ it "does nothing with nil values by default" do
259
+ s = Bar.new foos: [ Foo.new(baz: "bar") ]
260
+
261
+ assert_equal ["bar"], s.foos.map(&:baz)
262
+
263
+ m = Mediator[s]
264
+ d = { foos: nil }
265
+
266
+ m.parse d
267
+
268
+ assert_equal ["bar"], s.foos.map(&:baz)
269
+ end
270
+
271
+ it "does something with []" do
272
+ s = Bar.new foos: [ Foo.new(baz: "bar") ]
273
+
274
+ assert_equal ["bar"], s.foos.map(&:baz)
275
+
276
+ m = Mediator[s]
277
+ d = { foos: [] }
278
+
279
+ m.parse d
280
+
281
+ assert_equal [], s.foos.map(&:baz)
282
+ end
283
+
258
284
  it "adds new models if told to" do
259
285
  s = Bar.new merge_foos: [ Foo.new(baz: "bar") ]
260
286
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mediator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
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: 2013-03-05 00:00:00.000000000 Z
12
+ date: 2013-03-07 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A go-between for models.
15
15
  email: