setsumei 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,10 +11,23 @@ module Setsumei
11
11
  attr_accessor :klass, :options
12
12
 
13
13
  def set_value_on(object, options = {})
14
- [options[:from_value_in][Build::Key.for((self.options[:within] || klass), given: options[:from_value_in].keys)]].flatten(1).each do |data|
14
+ return nil if options.empty?
15
+
16
+ Array( extract_from_hash options[:from_value_in] ).each do |data|
15
17
  object << Build.a(klass, from: data)
16
18
  end
17
19
  end
20
+
21
+ private
22
+ def extract_from_hash(hash)
23
+ hash[ extract_key_for hash ]
24
+ end
25
+ def extract_key_for(hash)
26
+ Build::Key.for configured_key, given: hash.keys
27
+ end
28
+ def configured_key
29
+ options[:within] || klass
30
+ end
18
31
  end
19
32
  end
20
33
  end
@@ -1,3 +1,3 @@
1
1
  module Setsumei
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -44,8 +44,12 @@ module Setsumei
44
44
  subject
45
45
  end
46
46
 
47
+ context "nil value" do
48
+ specify { collection.set_value_on(object).should be_nil }
49
+ end
50
+
47
51
  context "single value" do
48
- let(:single_value) { mock "single_value" }
52
+ let(:single_value) { mock "single_value", to_a: nil }
49
53
  let(:single_instance) { mock "single_instance" }
50
54
 
51
55
  before do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: setsumei
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jon Rowe
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-23 00:00:00 +01:00
13
+ date: 2011-05-24 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency