easy_diff 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/easy_diff/core.rb +15 -7
- data/spec/easy_diff_spec.rb +22 -0
- metadata +39 -14
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/easy_diff/core.rb
CHANGED
@@ -5,9 +5,9 @@ module EasyDiff
|
|
5
5
|
added = nil
|
6
6
|
|
7
7
|
if original.nil?
|
8
|
-
added = modified.safe_dup
|
8
|
+
added = modified.safe_dup
|
9
9
|
elsif modified.nil?
|
10
|
-
removed = original.safe_dup
|
10
|
+
removed = original.safe_dup
|
11
11
|
elsif original.is_a?(Hash) && modified.is_a?(Hash)
|
12
12
|
removed = {}
|
13
13
|
added = {}
|
@@ -20,8 +20,8 @@ module EasyDiff
|
|
20
20
|
keys_added.each{ |key| added[key] = modified[key].safe_dup }
|
21
21
|
keys_in_common.each do |key|
|
22
22
|
r, a = easy_diff original[key], modified[key]
|
23
|
-
removed[key] = r unless r
|
24
|
-
added[key] = a unless a
|
23
|
+
removed[key] = r unless _blank?(r)
|
24
|
+
added[key] = a unless _blank?(a)
|
25
25
|
end
|
26
26
|
elsif original.is_a?(Array) && modified.is_a?(Array)
|
27
27
|
removed = original - modified
|
@@ -32,7 +32,7 @@ module EasyDiff
|
|
32
32
|
end
|
33
33
|
return removed, added
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def self.easy_unmerge!(original, removed)
|
37
37
|
if original.is_a?(Hash) && removed.is_a?(Hash)
|
38
38
|
original_keys = original.keys
|
@@ -47,7 +47,7 @@ module EasyDiff
|
|
47
47
|
end
|
48
48
|
original
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
def self.easy_merge!(original, added)
|
52
52
|
if added.nil?
|
53
53
|
return original
|
@@ -62,9 +62,17 @@ module EasyDiff
|
|
62
62
|
end
|
63
63
|
original
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
def self.easy_clone(original)
|
67
67
|
Marshal::load(Marshal.dump(original))
|
68
68
|
end
|
69
|
+
|
70
|
+
def self._blank?(obj)
|
71
|
+
if obj.respond_to?(:empty?)
|
72
|
+
obj.empty?
|
73
|
+
else
|
74
|
+
obj.nil?
|
75
|
+
end
|
76
|
+
end
|
69
77
|
end
|
70
78
|
end
|
data/spec/easy_diff_spec.rb
CHANGED
@@ -101,4 +101,26 @@ describe EasyDiff do
|
|
101
101
|
:extra_removed => "bye"
|
102
102
|
}
|
103
103
|
end
|
104
|
+
|
105
|
+
it "should not show empty hashes or arrays as diffs" do
|
106
|
+
@modified[:tags] = @original[:tags]
|
107
|
+
@modified[:pos] = @original[:pos]
|
108
|
+
@removed.delete :pos
|
109
|
+
@removed.delete :tags
|
110
|
+
@added.delete :pos
|
111
|
+
@added.delete :tags
|
112
|
+
removed, added = @original.easy_diff @modified
|
113
|
+
removed.should == @removed
|
114
|
+
added.should == @added
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should show added empty hashes as a diff" do
|
118
|
+
@original[:empty_array] = []
|
119
|
+
@modified[:empty_hash] = {}
|
120
|
+
@removed[:empty_array] = []
|
121
|
+
@added[:empty_hash] = {}
|
122
|
+
removed, added = @original.easy_diff @modified
|
123
|
+
removed.should == @removed
|
124
|
+
added.should == @added
|
125
|
+
end
|
104
126
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_diff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-07-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 2.4.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.4.0
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: yard
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: 0.6.0
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.6.0
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: bundler
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ~>
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: 1.0.0
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.0
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: jeweler
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ~>
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: 1.5.2
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.5.2
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: rcov
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ! '>='
|
@@ -65,7 +85,12 @@ dependencies:
|
|
65
85
|
version: '0'
|
66
86
|
type: :development
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
69
94
|
description: ! "Easy Diff enhances the functionality of Hash, allowing recursive diff,
|
70
95
|
merge, and unmerge of arbitrarily constructed hashes.\n This is perfect for people
|
71
96
|
who need to do diffs on not only plain text files but also data as Hash or JSON
|
@@ -108,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
133
|
version: '0'
|
109
134
|
segments:
|
110
135
|
- 0
|
111
|
-
hash: -
|
136
|
+
hash: -682295806044477025
|
112
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
138
|
none: false
|
114
139
|
requirements:
|
@@ -117,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
142
|
version: '0'
|
118
143
|
requirements: []
|
119
144
|
rubyforge_project:
|
120
|
-
rubygems_version: 1.8.
|
145
|
+
rubygems_version: 1.8.29
|
121
146
|
signing_key:
|
122
147
|
specification_version: 3
|
123
148
|
summary: Recursive diff, merge, and unmerge for hashes and arrays.
|