cmer-diff_dirs 0.1.1 → 0.1.2

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/README.rdoc CHANGED
@@ -3,7 +3,8 @@
3
3
  Helper to diff two directories
4
4
 
5
5
  = Example
6
-
6
+ require 'rubygems'
7
+ require 'diff_dirs'
7
8
  diff_dirs "~/dir1", "~/dir2"
8
9
 
9
10
  == Dependencies (for tests only)
data/Rakefile CHANGED
@@ -19,7 +19,34 @@ begin
19
19
  gemspec.description = "Ruby helper to diff two directories"
20
20
  gemspec.authors = ["Carl Mercier"]
21
21
  gemspec.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*"]
22
+ gemspec.rubyforge_project = 'diffdirs'
22
23
  end
23
24
  rescue LoadError
24
25
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
25
26
  end
27
+
28
+ begin
29
+ require 'rake/contrib/sshpublisher'
30
+ namespace :rubyforge do
31
+
32
+ desc "Release gem and RDoc documentation to RubyForge"
33
+ task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
34
+
35
+ namespace :release do
36
+ desc "Publish RDoc to RubyForge."
37
+ task :docs => [:rdoc] do
38
+ config = YAML.load(
39
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
40
+ )
41
+
42
+ host = "#{config['username']}@rubyforge.org"
43
+ remote_dir = "/var/www/cmercier/diff_dirs/"
44
+ local_dir = 'rdoc'
45
+
46
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
47
+ end
48
+ end
49
+ end
50
+ rescue LoadError
51
+ puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
52
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/lib/diff_dirs.rb CHANGED
@@ -20,10 +20,10 @@ class DiffDirs
20
20
  # New/Deleted files
21
21
  match = line.match(/^Only in ([^:]*): ([^$]*)$/)
22
22
  if match
23
- if match[1] == dir1
24
- return [:deleted, match[2]] # deleted from second dir
25
- elsif match[1] == dir2
26
- return [:new, match[2]] # new in second dir
23
+ if match[1].starts_with?(dir1)
24
+ return [:deleted, remove_dir_from_path("#{match[1]}/#{match[2]}", dir1)] # deleted from second dir
25
+ elsif match[1].starts_with?(dir2)
26
+ return [:new, remove_dir_from_path("#{match[1]}/#{match[2]}", dir2)] # new in second dir
27
27
  else
28
28
  raise "#{dir1} or #{dir2} didn't match #{match[1]}"
29
29
  end
@@ -43,7 +43,7 @@ class DiffDirs
43
43
  end
44
44
 
45
45
  def self.remove_dir_from_path(path, dir)
46
- dir += "/" unless dir[-1..-1] == "/"
46
+ dir = add_slash(dir)
47
47
  path.sub(Regexp.new("^#{dir}"), "")
48
48
  end
49
49
 
@@ -54,6 +54,18 @@ class DiffDirs
54
54
  dir
55
55
  end
56
56
  end
57
+
58
+ def self.add_slash(path)
59
+ path += "/" unless path[-1..-1] == "/"
60
+ path
61
+ end
62
+ end
63
+
64
+ class String
65
+ def starts_with?(prefix)
66
+ prefix = prefix.to_s
67
+ self[0, prefix.length] == prefix
68
+ end
57
69
  end
58
70
 
59
71
  public
@@ -1,5 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
- require File.dirname(__FILE__) + '/../diff_dirs'
2
+ require File.dirname(__FILE__) + '/../lib/diff_dirs'
3
3
 
4
4
  class DiffDirsTest < Test::Unit::TestCase
5
5
  context "diff executable" do
@@ -67,4 +67,43 @@ class DiffDirsTest < Test::Unit::TestCase
67
67
  assert_not_equal "~/", DiffDirs.send(:expand_path, "~/")
68
68
  end
69
69
  end
70
+
71
+ context "complex real life directory structure" do
72
+ setup do
73
+ @path = "/tmp/diff-dirs-test-#{rand(10000)}"
74
+ exec "mkdir -p #{@path}/1/dir1/dir2"
75
+ exec "touch #{@path}/1/dir1/file1"
76
+ exec "touch #{@path}/1/dir1/dir2/file2"
77
+ exec "mkdir -p #{@path}/1/foo/bar"
78
+ exec "touch #{@path}/1/foo/file_in_foo"
79
+ exec "touch #{@path}/1/file_in_root"
80
+ exec "touch #{@path}/1/another_file_in_root"
81
+ exec "echo hello > #{@path}/1/foo/file_with_content"
82
+
83
+ exec "mkdir -p #{@path}/2/foo/bar"
84
+ exec "touch #{@path}/2/foo/file_in_foo"
85
+ exec "touch #{@path}/2/foo/bar/file_in_bar"
86
+ exec "touch #{@path}/2/file_in_root"
87
+ exec "touch #{@path}/2/yet_another_file_in_root"
88
+ exec "echo world > #{@path}/2/foo/file_with_content"
89
+ end
90
+
91
+ teardown do
92
+ `rm -fr #{@path}`
93
+ end
94
+
95
+ should "run the full stack properly and return the correct diff result" do
96
+
97
+ assert_equal [[:deleted, "another_file_in_root"],
98
+ [:deleted, "dir1"],
99
+ [:new, "foo/bar/file_in_bar"],
100
+ [:modified, "foo/file_with_content"],
101
+ [:new, "yet_another_file_in_root"]], DiffDirs.diff_dirs("#{@path}/1", "#{@path}/2")
102
+ end
103
+ end
104
+
105
+ def exec(cmd)
106
+ # puts cmd
107
+ `#{cmd}`
108
+ end
70
109
  end
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ require 'yaml'
3
+
4
+ if ARGV.size < 1
5
+ puts "Usage: github-test.rb my-project.gemspec"
6
+ exit
7
+ end
8
+
9
+ require 'rubygems/specification'
10
+ data = File.read(ARGV[0])
11
+ spec = nil
12
+
13
+ if data !~ %r{!ruby/object:Gem::Specification}
14
+ Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
15
+ else
16
+ spec = YAML.load(data)
17
+ end
18
+
19
+ spec.validate
20
+
21
+ puts spec
22
+ puts "OK"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmer-diff_dirs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Mercier
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-12 00:00:00 -07:00
12
+ date: 2009-05-20 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -29,6 +29,7 @@ files:
29
29
  - VERSION
30
30
  - lib/diff_dirs.rb
31
31
  - test/diff_dirs_test.rb
32
+ - test/github-test.rb
32
33
  - test/test_helper.rb
33
34
  has_rdoc: true
34
35
  homepage: http://github.com/cmer/diff_dirs
@@ -51,11 +52,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
52
  version:
52
53
  requirements: []
53
54
 
54
- rubyforge_project:
55
+ rubyforge_project: diffdirs
55
56
  rubygems_version: 1.2.0
56
57
  signing_key:
57
58
  specification_version: 3
58
59
  summary: Ruby helper to diff two directories
59
60
  test_files:
60
61
  - test/diff_dirs_test.rb
62
+ - test/github-test.rb
61
63
  - test/test_helper.rb