ssdiff 0.0.1
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.
- data/.gitignore +7 -0
- data/.rvmrc_sample +1 -0
- data/Gemfile +5 -0
- data/Guardfile +10 -0
- data/README.rdoc +65 -0
- data/Rakefile +15 -0
- data/lib/ssdiff/version.rb +8 -0
- data/lib/ssdiff.rb +42 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/ssdiff_spec.rb +62 -0
- data/ssdiff.gemspec +25 -0
- metadata +89 -0
data/.gitignore
ADDED
data/.rvmrc_sample
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.2@sdiff
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :version => 2 do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
watch("sdiff.gemspec") { "spec" }
|
9
|
+
end
|
10
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
= ssdiff
|
2
|
+
|
3
|
+
The Super Stupid Diff gem
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
gem install ssdiff
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
Do you really know how to use this gem? WTF??
|
12
|
+
|
13
|
+
So...
|
14
|
+
|
15
|
+
require 'ssdiff'
|
16
|
+
>> "a".ssdiff "b"
|
17
|
+
=> ["a", "b"]
|
18
|
+
>> "b".ssdiff "b"
|
19
|
+
=> []
|
20
|
+
>> ["b"].ssdiff "b"
|
21
|
+
=> [["b"], "b"]
|
22
|
+
>> ["b"].ssdiff ["b"]
|
23
|
+
=> []
|
24
|
+
>> ["b"].ssdiff ["a","b"]
|
25
|
+
=> ["a"]
|
26
|
+
>> {:a => 1}.ssdiff({:a => 2})
|
27
|
+
=> [[:a, 1], [:a, 2]]
|
28
|
+
>> {:a => 1}.ssdiff({:b => 2})
|
29
|
+
=> [[:a, 1], [:b, 2]]
|
30
|
+
>> Object.ssdiff "a", "ab"
|
31
|
+
=> ["a", "ab"]
|
32
|
+
>> Object.ssdiff "ba", "ab"
|
33
|
+
=> ["ba", "ab"]
|
34
|
+
>> Object.ssdiff %w"b a", %w"a b"
|
35
|
+
=> []
|
36
|
+
|
37
|
+
Easy and, probably, Stupid!
|
38
|
+
|
39
|
+
== Crazy Maintainer
|
40
|
+
|
41
|
+
* Tino Gomes (http://blog.tinogomes.com/)
|
42
|
+
|
43
|
+
== License
|
44
|
+
|
45
|
+
(The MIT License)
|
46
|
+
|
47
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
48
|
+
a copy of this software and associated documentation files (the
|
49
|
+
'Software'), to deal in the Software without restriction, including
|
50
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
51
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
52
|
+
permit persons to whom the Software is furnished to do so, subject to
|
53
|
+
the following conditions:
|
54
|
+
|
55
|
+
The above copyright notice and this permission notice shall be
|
56
|
+
included in all copies or substantial portions of the Software.
|
57
|
+
|
58
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
59
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
60
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
61
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
62
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
63
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
64
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
65
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "bundler"
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
RSpec::Core::RakeTask.new
|
6
|
+
|
7
|
+
require "rake/rdoctask"
|
8
|
+
Rake::RDocTask.new do |t|
|
9
|
+
t.rdoc_dir = "docs"
|
10
|
+
t.main = "README.rdoc"
|
11
|
+
t.rdoc_files.include "README.rdoc", *Dir["lib/**/*.rb"]
|
12
|
+
end
|
13
|
+
|
14
|
+
task :default => [:spec]
|
15
|
+
|
data/lib/ssdiff.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "ssdiff/version"
|
2
|
+
|
3
|
+
module Super
|
4
|
+
module Stupid
|
5
|
+
module Diff
|
6
|
+
module ClassMethods
|
7
|
+
def ssdiff(a, b)
|
8
|
+
return [] if a == b
|
9
|
+
return [a, b] unless a.instance_of?(b.class)
|
10
|
+
|
11
|
+
convert_to_hash = false
|
12
|
+
|
13
|
+
if a.instance_of?(String)
|
14
|
+
a = a.split
|
15
|
+
b = b.split
|
16
|
+
end
|
17
|
+
|
18
|
+
if a.instance_of?(Hash)
|
19
|
+
a = a.to_a
|
20
|
+
b = b.to_a
|
21
|
+
convert_to_hash = true
|
22
|
+
end
|
23
|
+
|
24
|
+
((a - b) + (b -a))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module InstanceMethods
|
29
|
+
def ssdiff(a)
|
30
|
+
self.class.ssdiff(self, a)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.included(receiver)
|
35
|
+
receiver.extend ClassMethods
|
36
|
+
receiver.send :include, InstanceMethods
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Object.__send__(:include, Super::Stupid::Diff)
|
data/spec/spec_helper.rb
ADDED
data/spec/ssdiff_spec.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Super::Stupid::Diff do
|
4
|
+
it "should result diff for different objects" do
|
5
|
+
Object.ssdiff([1], "1").should == [[1], "1"]
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should raise when compare objects without - method" do
|
9
|
+
expect {
|
10
|
+
Object.ssdiff(Object.new, Object.new)
|
11
|
+
}.to raise_error(NoMethodError)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should result diff for arrays ['a'] and ['b']" do
|
15
|
+
Object.ssdiff(%w(a), %w(b)).should == ["a" ,"b"]
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should result diff for arrays ['a', 'b'] and ['b']" do
|
19
|
+
Object.ssdiff(%w(a b), %w(b)).should == ["a"]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should result diff for arrays ['a'] and ['b', 'a']" do
|
23
|
+
Object.ssdiff(%w(a), %w(b a)).should == ["b"]
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should result not diff for same arrays" do
|
27
|
+
Object.ssdiff(%w(a b c def), %w(a b c def)).should == []
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should result diff for strings 'a' and 'b'" do
|
31
|
+
Object.ssdiff(%(a), %(b)).should == ["a", "b"]
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should result diff for strings 'ab' and 'a'" do
|
35
|
+
Object.ssdiff(%(ab), %(a)).should == ["ab", "a"]
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should result not diff for same strings" do
|
39
|
+
Object.ssdiff("same", "same").should == []
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should result diff for hashes with difference on keys" do
|
43
|
+
Object.ssdiff({:a => 1}, {:b => 1}).should == [[:a, 1], [:b, 1]]
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should result diff for hashes with difference on values" do
|
47
|
+
Object.ssdiff({:a => 1}, {:a => 2}).should == [[:a, 1], [:a, 2]]
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should result diff for hashes" do
|
51
|
+
Object.ssdiff({:a => 1, :b => 2}, {:a => 1}).should == [[:b, 2]]
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should result not diff for same hases" do
|
55
|
+
Object.ssdiff({:a => 1, :b => 2}, {:b => 2, :a => 1}).should == []
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should result diff self with other" do
|
59
|
+
"a".ssdiff("b").should == ["a", "b"]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
data/ssdiff.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "ssdiff/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "ssdiff"
|
7
|
+
s.version = Super::Stupid::Diff::VERSION
|
8
|
+
s.authors = ["tinogomes"]
|
9
|
+
s.email = ["tinorj@gmail.com"]
|
10
|
+
s.homepage = "http://github.com/tinogomes/ssdiff"
|
11
|
+
s.summary = %q{A Super Stupic Diff implementation}
|
12
|
+
s.description = %q{A Super Stupic Diff implementation}
|
13
|
+
|
14
|
+
s.rubyforge_project = "ssdiff"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_development_dependency "ruby-debug19" if RUBY_VERSION >= "1.9"
|
21
|
+
|
22
|
+
s.add_development_dependency "rspec", "~> 2.6"
|
23
|
+
s.add_development_dependency "guard-rspec"
|
24
|
+
end
|
25
|
+
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ssdiff
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- tinogomes
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-06-09 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ruby-debug19
|
16
|
+
requirement: &23133360 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *23133360
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &23132860 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.6'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *23132860
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: guard-rspec
|
38
|
+
requirement: &23132440 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *23132440
|
47
|
+
description: A Super Stupic Diff implementation
|
48
|
+
email:
|
49
|
+
- tinorj@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- .rvmrc_sample
|
56
|
+
- Gemfile
|
57
|
+
- Guardfile
|
58
|
+
- README.rdoc
|
59
|
+
- Rakefile
|
60
|
+
- lib/ssdiff.rb
|
61
|
+
- lib/ssdiff/version.rb
|
62
|
+
- spec/spec_helper.rb
|
63
|
+
- spec/ssdiff_spec.rb
|
64
|
+
- ssdiff.gemspec
|
65
|
+
homepage: http://github.com/tinogomes/ssdiff
|
66
|
+
licenses: []
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project: ssdiff
|
85
|
+
rubygems_version: 1.8.1
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: A Super Stupic Diff implementation
|
89
|
+
test_files: []
|