zipit 0.1.0
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/CHANGES +6 -0
- data/README +14 -0
- data/Rakefile +13 -0
- data/lib/zip_it.rb +69 -0
- data/zipit.gemspec +29 -0
- metadata +59 -0
data/CHANGES
ADDED
data/README
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
= Zipit Gem -- rake helper for zipping/unzipping project files
|
2
|
+
|
3
|
+
= Installing Zipit
|
4
|
+
|
5
|
+
== Installing the Gem
|
6
|
+
$ sudo gem sources -a http://gemcutter.org
|
7
|
+
$ sudo gem install zipit
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
task :zip do
|
12
|
+
zip :archive => "my_project.zip", :dir => "."
|
13
|
+
end
|
14
|
+
|
data/Rakefile
ADDED
data/lib/zip_it.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'zip/zip'
|
2
|
+
|
3
|
+
class ZipIt
|
4
|
+
def create_zip_file params
|
5
|
+
file_name = params[:file_name]
|
6
|
+
dir = params[:dir]
|
7
|
+
@global_excludes = params[:global_excludes].nil? ? [] : params[:global_excludes]
|
8
|
+
@includes = params[:includes].nil? ? [] : params[:includes]
|
9
|
+
@excludes = params[:excludes].nil? ? [] : params[:excludes]
|
10
|
+
|
11
|
+
Zip::ZipOutputStream.open(file_name) do |zos|
|
12
|
+
zip(zos, dir, dir)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def zip zos, name, basedir
|
17
|
+
Dir.new(name).each do |filename|
|
18
|
+
if(filename != '.' and filename != '..')
|
19
|
+
full_name = name + '/' + filename
|
20
|
+
|
21
|
+
if File.directory? full_name
|
22
|
+
zip(zos, full_name, basedir)
|
23
|
+
else
|
24
|
+
new_name = full_name[basedir.length+1..full_name.length]
|
25
|
+
#puts new_name
|
26
|
+
|
27
|
+
#unless contains?(@excludes, full_name) and not contains?(@includes, full_name)
|
28
|
+
if (match?(new_name, @global_excludes) or match?(new_name, @excludes)) and
|
29
|
+
not match?(new_name, @includes)
|
30
|
+
;
|
31
|
+
else
|
32
|
+
puts "Adding #{new_name} ..."
|
33
|
+
# Create a new entry with some arbitrary name
|
34
|
+
zos.put_next_entry(new_name)
|
35
|
+
# Add the contents of the file, don't read the stuff linewise if its binary, instead use direct IO
|
36
|
+
zos.print IO.read(name + '/' + filename)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# def contains? name, list
|
44
|
+
# list.each do |element|
|
45
|
+
# pos = name =~ /#{element}/
|
46
|
+
# pos = pos.nil? ? -1 : pos
|
47
|
+
#
|
48
|
+
# return true if pos >=0
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# false
|
52
|
+
# end
|
53
|
+
|
54
|
+
def match? name, list
|
55
|
+
list.each do |pattern|
|
56
|
+
return true if File.fnmatch(pattern, name)
|
57
|
+
end
|
58
|
+
|
59
|
+
false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def zip params
|
64
|
+
zipit = ZipIt.new
|
65
|
+
|
66
|
+
zipit.create_zip_file(
|
67
|
+
:file_name => params[:archive], :dir => params[:dir],
|
68
|
+
:global_excludes => ['.svn'], :excludes => ["*.zip"])
|
69
|
+
end
|
data/zipit.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{zipit}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
|
9
|
+
s.authors = ["Alexander Shvets"]
|
10
|
+
s.date = %q{2010-02-02}
|
11
|
+
s.description = %q{Rake helper for zipping/unzipping project files.}
|
12
|
+
s.email = %q{alexander.shvets@gmail.com}
|
13
|
+
|
14
|
+
s.files = ["CHANGES", "zipit.gemspec", "Rakefile", "README", "lib/zip_it.rb"]
|
15
|
+
|
16
|
+
s.has_rdoc = true
|
17
|
+
s.homepage = %q{http://github.com/shvets/zipit}
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.rubyforge_project = %q{zipit}
|
20
|
+
s.rubygems_version = %q{1.3.2}
|
21
|
+
s.summary = %q{Rake helper for zipping/unzipping project files.}
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
s.specification_version = 2
|
25
|
+
end
|
26
|
+
|
27
|
+
s.platform = Gem::Platform::RUBY
|
28
|
+
s.requirements = ["none"]
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zipit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Shvets
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-02-02 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Rake helper for zipping/unzipping project files.
|
17
|
+
email: alexander.shvets@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- CHANGES
|
26
|
+
- zipit.gemspec
|
27
|
+
- Rakefile
|
28
|
+
- README
|
29
|
+
- lib/zip_it.rb
|
30
|
+
has_rdoc: true
|
31
|
+
homepage: http://github.com/shvets/zipit
|
32
|
+
licenses: []
|
33
|
+
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
requirements:
|
52
|
+
- none
|
53
|
+
rubyforge_project: zipit
|
54
|
+
rubygems_version: 1.3.5
|
55
|
+
signing_key:
|
56
|
+
specification_version: 2
|
57
|
+
summary: Rake helper for zipping/unzipping project files.
|
58
|
+
test_files: []
|
59
|
+
|