zipit 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/VERSION +1 -1
  2. data/bin/zipit +0 -2
  3. data/lib/zipit.rb +48 -29
  4. data/spec/zipit_spec.rb +41 -0
  5. data/zipit.gemspec +17 -13
  6. metadata +28 -13
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.3.5
data/bin/zipit CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  require 'rubygems' unless RUBY_VERSION =~ /1.9.*/
4
4
 
5
- #!/usr/bin/env ruby
6
-
7
5
  $:.unshift(File::join(File::dirname(File::dirname(__FILE__)), "lib"))
8
6
 
9
7
  require 'zipit'
data/lib/zipit.rb CHANGED
@@ -1,32 +1,60 @@
1
1
  require 'zip/zip'
2
2
 
3
3
  class Zipit
4
- def create_zip_file params
5
- file_name = params[:file_name]
6
- dir = params[:dir]
4
+ attr_reader :global_excludes, :includes, :excludes
5
+
6
+ def zip_cmd_line params
7
+ archive = params[0].nil? ? "#{File.basename(Dir.pwd)}.zip" : params[0]
8
+ dir = params[1].nil? ? "." : params[1]
9
+
10
+ @includes = params[:includes].nil? ? [] : params[:includes]
11
+ @excludes = params[:excludes].nil? ? [] : params[:excludes]
7
12
  @global_excludes = params[:global_excludes].nil? ? [] : params[:global_excludes]
13
+
14
+ @excludes += [archive]
15
+ @global_excludes += ['.svn', '.git']
16
+
17
+ create_zip_file(:file_name => archive, :dir => dir)
18
+ end
19
+
20
+ def zip params
21
+ archive = params[:archive].nil? ? "#{File.basename(Dir.pwd)}.zip" : params[:archive]
22
+ dir = params[:dir].nil? ? "." : params[:dir]
23
+
8
24
  @includes = params[:includes].nil? ? [] : params[:includes]
9
25
  @excludes = params[:excludes].nil? ? [] : params[:excludes]
26
+ @global_excludes = params[:global_excludes].nil? ? [] : params[:global_excludes]
27
+
28
+ @excludes += [archive]
29
+ @global_excludes += ['.svn', '.git']
30
+
31
+ create_zip_file(:file_name => archive, :dir => dir)
32
+ end
33
+
34
+ private
35
+
36
+ def create_zip_file params
37
+ file_name = params[:file_name]
38
+ dir = params[:dir]
10
39
 
11
40
  Zip::ZipOutputStream.open(file_name) do |zos|
12
- zip(zos, dir, dir)
41
+ zip_stream(zos, dir, dir)
13
42
  end
14
43
  end
15
44
 
16
- def zip zos, name, basedir
45
+ def zip_stream zos, name, basedir
17
46
  Dir.new(name).each do |filename|
18
47
  if(filename != '.' and filename != '..')
19
48
  full_name = name + '/' + filename
20
49
 
21
50
  if File.directory? full_name
22
- zip(zos, full_name, basedir)
51
+ if not match?(full_name, global_excludes) and not match?(full_name, excludes) and not match?(full_name, includes)
52
+ zip_stream(zos, full_name, basedir)
53
+ end
23
54
  else
24
55
  new_name = full_name[basedir.length+1..full_name.length]
25
-
26
- if (match?(new_name, @global_excludes) or match?(new_name, @excludes)) and
27
- not match?(new_name, @includes)
28
- ;
29
- else
56
+
57
+ if not (match?(new_name, global_excludes) and not match?(new_name, excludes)) and not match?(new_name, includes)
30
58
  puts "Adding #{new_name} ..."
31
59
  # Create a new entry with some arbitrary name
32
60
  zos.put_next_entry(new_name)
@@ -37,34 +65,25 @@ class Zipit
37
65
  end
38
66
  end
39
67
  end
40
-
68
+
41
69
  def match? name, list
42
70
  list.each do |pattern|
43
- return true if File.fnmatch(pattern, name) or name =~ /^#{pattern}/
71
+ return true if File.fnmatch(pattern, name) or name =~ /#{pattern}/
44
72
  end
45
73
 
46
74
  false
47
- end
75
+ end
76
+
48
77
  end
49
78
 
50
- def zip_cmd_line params
79
+ def zip params
51
80
  zipit = Zipit.new
52
81
 
53
- archive = params[0].nil? ? "#{File.basename(Dir.pwd)}.zip" : params[0]
54
- dir = params[1].nil? ? "." : params[1]
55
-
56
- zipit.create_zip_file(
57
- :file_name => archive, :dir => dir,
58
- :global_excludes => ['.svn', '.git'], :excludes => [archive])
59
- end
82
+ zipit.zip params
83
+ end
60
84
 
61
- def zip params
85
+ def zip_cmd_line params
62
86
  zipit = Zipit.new
63
-
64
- archive = params[:archive].nil? ? "#{File.basename(Dir.pwd)}.zip" : params[:archive]
65
- dir = params[:dir].nil? ? "." : params[:dir]
66
87
 
67
- zipit.create_zip_file(
68
- :file_name => archive, :dir => dir,
69
- :global_excludes => ['.svn', '.git'], :excludes => [archive])
88
+ zipit.zip_cmd_line params
70
89
  end
@@ -0,0 +1,41 @@
1
+ # zipit_spec.rb
2
+
3
+ require 'zipit'
4
+
5
+ describe Zipit do
6
+ context "create zip archive from the dir" do
7
+ subject { Zipit.new }
8
+
9
+ before do
10
+ `mkdir -pv test/.svn`
11
+ `mkdir -pv test/test1/.svn`
12
+ `cp zipit_spec.rb test/test1/.svn`
13
+
14
+ `mkdir -pv test/test1/test2/test3`
15
+ `mkdir -pv test/test4/test5/test6/test7`
16
+ `cp zipit_spec.rb test/test1/test2/test3`
17
+ `cp zipit_spec.rb test/test4/test5/test6/test7`
18
+ end
19
+
20
+ after do
21
+ `rm -r test`
22
+ end
23
+
24
+ it "should create new archive" do
25
+ subject.zip :archive => "../test1.zip", :dir => "test"
26
+
27
+ Zip::ZipFile.open("../test1.zip") do |zipfile|
28
+ zipfile.find_entry('test1/test2/test3/zipit_spec.rb').should_not be_nil
29
+ end
30
+ end
31
+
32
+ it "should not include test2" do
33
+ subject.zip :archive => "../test2.zip", :dir => "test", :excludes => ["test2"]
34
+
35
+ Zip::ZipFile.open("../test2.zip") do |zipfile|
36
+ zipfile.find_entry('test1/test2/test3/zipit_spec.rb').should be_nil
37
+ end
38
+ end
39
+ end
40
+ end
41
+
data/zipit.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{zipit}
8
- s.version = "0.3.4"
8
+ s.version = "0.3.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alexander Shvets"]
12
- s.date = %q{2010-08-19}
12
+ s.date = %q{2011-08-26}
13
13
  s.default_executable = %q{zipit}
14
14
  s.description = %q{Rake helper for zipping/unzipping project files.}
15
15
  s.email = %q{alexander.shvets@gmail.com}
@@ -19,31 +19,35 @@ Gem::Specification.new do |s|
19
19
  ]
20
20
  s.files = [
21
21
  "CHANGES",
22
- "README",
23
- "Rakefile",
24
- "VERSION",
25
- "bin/zipit",
26
- "bin/zipit.bat",
27
- "lib/zipit.rb",
28
- "zipit.gemspec"
22
+ "README",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "bin/zipit",
26
+ "bin/zipit.bat",
27
+ "lib/zipit.rb",
28
+ "zipit.gemspec"
29
29
  ]
30
30
  s.homepage = %q{http://github.com/shvets/zipit}
31
- s.rdoc_options = ["--charset=UTF-8"]
32
31
  s.require_paths = ["lib"]
33
32
  s.requirements = ["none"]
34
- s.rubygems_version = %q{1.3.7}
33
+ s.rubygems_version = %q{1.6.2}
35
34
  s.summary = %q{Rake helper for zipping/unzipping project files. (Summary).}
35
+ s.test_files = [
36
+ "spec/zipit_spec.rb"
37
+ ]
36
38
 
37
39
  if s.respond_to? :specification_version then
38
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
39
40
  s.specification_version = 3
40
41
 
41
42
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_runtime_dependency(%q<zip>, [">= 0"])
42
44
  s.add_runtime_dependency(%q<rubyzip>, [">= 0.9.4"])
43
45
  else
46
+ s.add_dependency(%q<zip>, [">= 0"])
44
47
  s.add_dependency(%q<rubyzip>, [">= 0.9.4"])
45
48
  end
46
49
  else
50
+ s.add_dependency(%q<zip>, [">= 0"])
47
51
  s.add_dependency(%q<rubyzip>, [">= 0.9.4"])
48
52
  end
49
53
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zipit
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
4
+ hash: 25
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 4
10
- version: 0.3.4
9
+ - 5
10
+ version: 0.3.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alexander Shvets
@@ -15,13 +15,27 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-19 00:00:00 -04:00
18
+ date: 2011-08-26 00:00:00 -04:00
19
19
  default_executable: zipit
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: rubyzip
23
22
  prerelease: false
23
+ type: :runtime
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ name: zip
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ prerelease: false
37
+ type: :runtime
38
+ requirement: &id002 !ruby/object:Gem::Requirement
25
39
  none: false
26
40
  requirements:
27
41
  - - ">="
@@ -32,8 +46,8 @@ dependencies:
32
46
  - 9
33
47
  - 4
34
48
  version: 0.9.4
35
- type: :runtime
36
- version_requirements: *id001
49
+ name: rubyzip
50
+ version_requirements: *id002
37
51
  description: Rake helper for zipping/unzipping project files.
38
52
  email: alexander.shvets@gmail.com
39
53
  executables:
@@ -51,13 +65,14 @@ files:
51
65
  - bin/zipit.bat
52
66
  - lib/zipit.rb
53
67
  - zipit.gemspec
68
+ - spec/zipit_spec.rb
54
69
  has_rdoc: true
55
70
  homepage: http://github.com/shvets/zipit
56
71
  licenses: []
57
72
 
58
73
  post_install_message:
59
- rdoc_options:
60
- - --charset=UTF-8
74
+ rdoc_options: []
75
+
61
76
  require_paths:
62
77
  - lib
63
78
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -81,9 +96,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
96
  requirements:
82
97
  - none
83
98
  rubyforge_project:
84
- rubygems_version: 1.3.7
99
+ rubygems_version: 1.6.2
85
100
  signing_key:
86
101
  specification_version: 3
87
102
  summary: Rake helper for zipping/unzipping project files. (Summary).
88
- test_files: []
89
-
103
+ test_files:
104
+ - spec/zipit_spec.rb