easy_diff 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -7,7 +7,7 @@ is included with diff and merge to more easily allow versioning of arbitrary dat
7
7
  == Install
8
8
 
9
9
  gem install easy_diff
10
-
10
+
11
11
  == Examples
12
12
 
13
13
  === Hash#easy_diff
@@ -23,7 +23,7 @@ The first contains what has to be removed from self to create the second hash. T
23
23
  :some_bool => false,
24
24
  :extra_removed => "bye"
25
25
  }
26
-
26
+
27
27
  modified = {
28
28
  :tags => ['b', 'c', 'd'],
29
29
  :pos => {:x => '3', :y => '2'},
@@ -32,9 +32,9 @@ The first contains what has to be removed from self to create the second hash. T
32
32
  :some_bool => true,
33
33
  :extra_added => "hi"
34
34
  }
35
-
35
+
36
36
  removed, added = original.easy_diff modified
37
-
37
+
38
38
  # The removed and added hashes should contain the following:
39
39
  # removed = {
40
40
  # :tags => ['a'],
@@ -43,7 +43,7 @@ The first contains what has to be removed from self to create the second hash. T
43
43
  # :some_bool => false,
44
44
  # :extra_removed => "bye"
45
45
  # }
46
- #
46
+ #
47
47
  # added = {
48
48
  # :tags => ['d'],
49
49
  # :pos => {:x => '3'},
@@ -51,7 +51,7 @@ The first contains what has to be removed from self to create the second hash. T
51
51
  # :some_bool => true,
52
52
  # :extra_added => "hi"
53
53
  # }
54
-
54
+
55
55
  === Hash#easy_merge
56
56
 
57
57
  Takes a hash and recursively merges it with self. Arrays are merged by the union operation and then sorted.
@@ -65,7 +65,7 @@ Using Hash#easy_merge! will modify self instead of returning a new hash.
65
65
  :some_bool => false,
66
66
  :extra_removed => "bye"
67
67
  }
68
-
68
+
69
69
  extra = {
70
70
  :tags => ['d'],
71
71
  :pos => {:x => '3'},
@@ -73,7 +73,7 @@ Using Hash#easy_merge! will modify self instead of returning a new hash.
73
73
  :some_bool => true,
74
74
  :extra_added => "hi"
75
75
  }
76
-
76
+
77
77
  merged = original.easy_merge extra
78
78
 
79
79
  # The merged hash should look like this:
@@ -86,7 +86,7 @@ Using Hash#easy_merge! will modify self instead of returning a new hash.
86
86
  # :extra_removed => "bye",
87
87
  # :extra_added => "hi"
88
88
  # }
89
-
89
+
90
90
  === Hash#easy_unmerge
91
91
 
92
92
  Takes a hash and recursively unmerges it with self. By unmerging, I mean it will remove all matching values from
@@ -101,7 +101,7 @@ Using Hash#easy_unmerge! will modify self instead of returning a new hash.
101
101
  :some_bool => true,
102
102
  :extra_added => "hi"
103
103
  }
104
-
104
+
105
105
  extra = {
106
106
  :tags => ['d'],
107
107
  :pos => {:x => '3'},
@@ -109,7 +109,7 @@ Using Hash#easy_unmerge! will modify self instead of returning a new hash.
109
109
  :some_bool => true,
110
110
  :extra_added => "hi"
111
111
  }
112
-
112
+
113
113
  unmerged = original.easy_unmerge extra
114
114
 
115
115
  # The unmerged hash should look like this:
@@ -118,7 +118,7 @@ Using Hash#easy_unmerge! will modify self instead of returning a new hash.
118
118
  # :pos => {:y => '2'},
119
119
  # :some_str => "bla"
120
120
  # }
121
-
121
+
122
122
  === Hash#easy_clone
123
123
 
124
124
  Performs a deep clone on a hash
@@ -127,12 +127,12 @@ Performs a deep clone on a hash
127
127
  :tags => ['b', 'c', 'd'],
128
128
  :pos => {:x => '3', :y => '2'}
129
129
  }
130
-
130
+
131
131
  new = original.easy_clone
132
-
132
+
133
133
  new[:tags] << 'e'
134
134
  new[:pos][:y] = '1'
135
-
135
+
136
136
  # The original hash will still look like this:
137
137
  # original = {
138
138
  # :tags => ['b', 'c', 'd'],
@@ -140,7 +140,7 @@ Performs a deep clone on a hash
140
140
  # }
141
141
 
142
142
  == Contributing to easy_diff
143
-
143
+
144
144
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
145
145
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
146
146
  * Fork the project
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
data/lib/easy_diff.rb CHANGED
@@ -3,4 +3,4 @@ require File.expand_path(File.dirname(__FILE__) + '/easy_diff/core')
3
3
  require File.expand_path(File.dirname(__FILE__) + '/easy_diff/hash_ext')
4
4
 
5
5
  Object.send :include, EasyDiff::SafeDup
6
- Hash.send :include, EasyDiff::HashExt
6
+ Hash.send :include, EasyDiff::HashExt
@@ -68,11 +68,11 @@ module EasyDiff
68
68
  end
69
69
 
70
70
  def self._blank?(obj)
71
- if obj.respond_to?(:empty?)
71
+ if obj.is_a?(Hash) || obj.is_a?(Array)
72
72
  obj.empty?
73
73
  else
74
74
  obj.nil?
75
75
  end
76
76
  end
77
77
  end
78
- end
78
+ end
@@ -11,17 +11,17 @@ module EasyDiff
11
11
  def easy_unmerge!(other)
12
12
  EasyDiff::Core.easy_unmerge! self, other
13
13
  end
14
-
14
+
15
15
  def easy_merge(other)
16
16
  self.easy_clone.easy_merge!(other)
17
17
  end
18
-
18
+
19
19
  def easy_unmerge(other)
20
20
  self.easy_clone.easy_unmerge!(other)
21
21
  end
22
-
22
+
23
23
  def easy_clone
24
24
  EasyDiff::Core.easy_clone self
25
25
  end
26
26
  end
27
- end
27
+ end
@@ -8,4 +8,4 @@ module EasyDiff
8
8
  end
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -10,7 +10,7 @@ describe EasyDiff do
10
10
  :some_bool => false,
11
11
  :extra_removed => "bye"
12
12
  }
13
-
13
+
14
14
  @modified = {
15
15
  :tags => ['b', 'c', 'd'],
16
16
  :pos => {:x => '3', :y => '2'},
@@ -19,7 +19,7 @@ describe EasyDiff do
19
19
  :some_bool => true,
20
20
  :extra_added => "hi"
21
21
  }
22
-
22
+
23
23
  @removed = {
24
24
  :tags => ['a'],
25
25
  :pos => {:x => '1'},
@@ -27,7 +27,7 @@ describe EasyDiff do
27
27
  :some_bool => false,
28
28
  :extra_removed => "bye"
29
29
  }
30
-
30
+
31
31
  @added = {
32
32
  :tags => ['d'],
33
33
  :pos => {:x => '3'},
@@ -41,7 +41,7 @@ describe EasyDiff do
41
41
  removed.should == @removed
42
42
  added.should == @added
43
43
  end
44
-
44
+
45
45
  it "should compute easy_unmerge" do
46
46
  unmerged = @modified.easy_unmerge @added
47
47
  unmerged.should == {
@@ -50,7 +50,7 @@ describe EasyDiff do
50
50
  :some_str => "bla"
51
51
  }
52
52
  end
53
-
53
+
54
54
  it "should compute easy_merge" do
55
55
  merged = @original.easy_merge @added
56
56
  merged.should == {
@@ -71,14 +71,14 @@ describe EasyDiff do
71
71
  :extra_removed => "bye"
72
72
  }
73
73
  end
74
-
74
+
75
75
  it "should stay the same" do
76
76
  removed, added = @original.easy_diff @modified
77
77
  unmerged = @modified.easy_unmerge added
78
78
  original = unmerged.easy_merge removed
79
79
  original.should == @original
80
80
  end
81
-
81
+
82
82
  it "should do a deep clone" do
83
83
  cloned = @original.easy_clone
84
84
  cloned.should == @original
@@ -123,4 +123,12 @@ describe EasyDiff do
123
123
  removed.should == @removed
124
124
  added.should == @added
125
125
  end
126
+
127
+ it "should only check empty? on Hashes and Arrays" do
128
+ original = {:possibly_empty_string => ""}
129
+ modified = {:possibly_empty_string => "not empty"}
130
+ removed, added = original.easy_diff modified
131
+ removed.should == {:possibly_empty_string => ""}
132
+ added.should == {:possibly_empty_string => "not empty"}
133
+ end
126
134
  end
data/spec/spec_helper.rb CHANGED
@@ -8,5 +8,5 @@ require 'easy_diff'
8
8
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
9
 
10
10
  RSpec.configure do |config|
11
-
11
+
12
12
  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.3
4
+ version: 0.0.4
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: 2014-07-05 00:00:00.000000000 Z
12
+ date: 2014-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -133,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  segments:
135
135
  - 0
136
- hash: -682295806044477025
136
+ hash: -1698235666282817780
137
137
  required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements: