yesterday 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,6 +29,9 @@ module Yesterday
29
29
  if attribute == 'id'
30
30
  diff[attribute] = old_value
31
31
 
32
+ elsif old_value.is_a?(Hash)
33
+ diff[attribute] = diff_attributes(old_value, to[attribute] || {})
34
+
32
35
  elsif !old_value.is_a?(Array) && !ignored_attributes.include?(attribute)
33
36
  new_value = to[attribute]
34
37
  diff[attribute] = [old_value, new_value]
@@ -1,3 +1,3 @@
1
1
  module Yesterday
2
- VERSION = "0.5"
2
+ VERSION = "0.6"
3
3
  end
@@ -11,12 +11,15 @@ module Yesterday
11
11
  attributes = {}
12
12
 
13
13
  hash.each do |attribute, value|
14
- if nested_value? value
14
+ if nested_objects? value
15
15
  value.each do |item|
16
16
  attributes[attribute] ||= []
17
- attributes[attribute] << deserialize(item)
17
+ attributes[attribute] << deserialize(item) if item
18
18
  end
19
19
 
20
+ elsif nested_object? value
21
+ attributes[attribute] = deserialize(value)
22
+
20
23
  elsif attribute != 'id'
21
24
  attributes[attribute] = value.is_a?(Array) ? Yesterday::VersionedAttribute.new(value) : value
22
25
  end
@@ -25,9 +28,13 @@ module Yesterday
25
28
  Yesterday::VersionedObject.new(attributes.merge({ 'id' => hash['id']}))
26
29
  end
27
30
 
28
- def nested_value?(value)
31
+ def nested_objects?(value)
29
32
  value.is_a?(Array) && value.first.is_a?(Hash)
30
33
  end
31
34
 
35
+ def nested_object?(value)
36
+ value.is_a?(Hash)
37
+ end
38
+
32
39
  end
33
40
  end
data/spec/differ_spec.rb CHANGED
@@ -16,7 +16,12 @@ describe Yesterday::Differ do
16
16
  'address' => 'Sesamstreet 2' }
17
17
  ]
18
18
  }
19
- ]
19
+ ],
20
+ 'state' => {
21
+ 'id' => 1,
22
+ 'code' => 'C00',
23
+ 'description' => 'Critical'
24
+ }
20
25
  }
21
26
 
22
27
  to = {
@@ -33,7 +38,12 @@ describe Yesterday::Differ do
33
38
  'address' => 'Foobar 2' }
34
39
  ]
35
40
  }
36
- ]
41
+ ],
42
+ 'state' => {
43
+ 'id' => 1,
44
+ 'code' => 'C12',
45
+ 'description' => 'Non critical'
46
+ }
37
47
  }
38
48
 
39
49
  Yesterday::Differ.new(from, to).diff.should == {
@@ -54,6 +64,12 @@ describe Yesterday::Differ do
54
64
  '_event' => 'modified'
55
65
  }
56
66
  ],
67
+ 'state' => {
68
+ 'id' => 1,
69
+ 'code' => ['C00', 'C12'],
70
+ 'description' => ['Critical', 'Non critical'],
71
+ '_event' => 'modified'
72
+ },
57
73
  '_event' => 'modified'
58
74
  }
59
75
  end
@@ -16,7 +16,12 @@ describe Yesterday::VersionedObjectCreator do
16
16
  'address' => ['Sesamstreet 2', 'Sesamstreet 2'] }
17
17
  ]
18
18
  }
19
- ]
19
+ ],
20
+ 'state' => {
21
+ 'id' => 1,
22
+ 'code' => ['C00', 'C12'],
23
+ 'description' => ['Critical', 'Non critical']
24
+ }
20
25
  }
21
26
 
22
27
  object = Yesterday::VersionedObjectCreator.new(from).to_object
@@ -37,5 +42,11 @@ describe Yesterday::VersionedObjectCreator do
37
42
  object.contacts.first.addresses.first.address.current.should == 'Sesamstreet 1'
38
43
  object.contacts.first.addresses.last.address.previous.should == 'Sesamstreet 2'
39
44
  object.contacts.first.addresses.last.address.current.should == 'Sesamstreet 2'
45
+
46
+ object.state.id.should == 1
47
+ object.state.code.current.should == 'C12'
48
+ object.state.code.previous.should == 'C00'
49
+ object.state.description.current.should == 'Non critical'
50
+ object.state.description.previous.should == 'Critical'
40
51
  end
41
52
  end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yesterday
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 5
9
- version: "0.5"
8
+ - 6
9
+ version: "0.6"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Diederick Lawson
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-04-01 00:00:00 +02:00
17
+ date: 2011-04-04 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency