setsumei 0.0.3 → 0.0.4
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.
@@ -11,23 +11,30 @@ module Setsumei
|
|
11
11
|
attr_accessor :klass, :options
|
12
12
|
|
13
13
|
def set_value_on(object, options = {})
|
14
|
-
return nil if options.empty?
|
14
|
+
return nil if options.empty? || options[:from_value_in].empty?
|
15
15
|
|
16
|
-
|
16
|
+
array( extract_from_hash options[:from_value_in] ).each do |data|
|
17
17
|
object << Build.a(klass, from: data)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
22
|
+
def array(thing)
|
23
|
+
[thing].flatten(1).compact
|
24
|
+
end
|
22
25
|
def extract_from_hash(hash)
|
23
26
|
hash[ extract_key_for hash ]
|
24
27
|
end
|
25
28
|
def extract_key_for(hash)
|
26
|
-
Build::Key.for configured_key, given: hash
|
29
|
+
Build::Key.for configured_key, given: hash_keys(hash)
|
27
30
|
end
|
28
31
|
def configured_key
|
29
32
|
options[:within] || klass
|
30
33
|
end
|
34
|
+
def hash_keys(hash)
|
35
|
+
( hash && hash.keys ) || []
|
36
|
+
end
|
37
|
+
|
31
38
|
end
|
32
39
|
end
|
33
40
|
end
|
data/lib/setsumei/version.rb
CHANGED
@@ -46,6 +46,11 @@ module Setsumei
|
|
46
46
|
|
47
47
|
context "nil value" do
|
48
48
|
specify { collection.set_value_on(object).should be_nil }
|
49
|
+
it "should protect against instances where there are attributes, but not for our defined element keys" do
|
50
|
+
hash = { from_value_in: {"@size"=>"0"} }
|
51
|
+
object.should_not_receive(:<<)
|
52
|
+
collection.set_value_on(object,hash)
|
53
|
+
end
|
49
54
|
end
|
50
55
|
|
51
56
|
context "single value" do
|