zip_dsl 1.4.4 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,106 +0,0 @@
1
- require 'zip/zip'
2
-
3
- class ZipUpdater
4
- attr_reader :from_dir
5
-
6
- def initialize name, from_dir
7
- @from_dir = from_dir
8
- @zipfile = Zip::ZipFile.open(name)
9
- end
10
-
11
- def close
12
- @zipfile.close
13
- end
14
-
15
- def file params
16
- to_dir = params[:to_dir].nil? ? File.dirname(params[:name]) : strip_dot(params[:to_dir])
17
-
18
- add_or_replace_file full_name(params[:name]), "#{to_dir}/#{params[:name]}"
19
- end
20
-
21
- def content params
22
- to_dir = params[:to_dir].nil? ? File.dirname(params[:name]) : params[:to_dir]
23
-
24
- add_or_replace_file params[:name], to_dir, params[:source]
25
- end
26
-
27
- def directory params
28
- if params[:from_dir].nil?
29
- add_empty_directory params[:to_dir]
30
- else
31
- if params[:to_dir].nil?
32
- to_dir = params[:from_dir]
33
- else
34
- to_dir = params[:to_dir]
35
- end
36
-
37
- filter = params[:filter].nil? ? "**/*" : params[:filter]
38
-
39
- add_directory params[:from_dir], to_dir, filter
40
- end
41
-
42
- #Dir["spec/stubs/**/*.*"].each do |name|
43
- # if File.file? name
44
- # add_or_replace(zipfile, "WEB-INF/spec/stubs/#{name['spec/stubs'.size+1..-1]}", name)
45
- # end
46
- #end
47
- end
48
-
49
- private
50
-
51
- def add_or_replace_file from_name, to_name
52
- begin
53
- @zipfile.add to_name, from_name
54
- rescue Zip::ZipEntryExistsError
55
- @zipfile.replace to_name, from_name
56
- end
57
- end
58
-
59
- def add_directory from_dir, to_dir, filter="**/*"
60
- patterns = filter.kind_of?(String) ? [filter] : filter
61
-
62
- patterns.each do |pattern|
63
- files = pattern_to_files full_name(from_dir), pattern
64
-
65
- files.each do |from_name|
66
- suffix = File.dirname(from_name)[full_name(from_dir).size+1..-1]
67
- dir = suffix.nil? ? to_dir : "#{to_dir}/#{suffix}"
68
-
69
- if File.file?(from_name)
70
- to_name = "#{dir}/#{from_name[full_name(dir).size+1..-1]}"
71
-
72
- add_or_replace_file from_name, to_name
73
- end
74
- end
75
- end
76
- end
77
-
78
- def add_empty_directory(name)
79
- puts "adding empty dir: #{name}"
80
-
81
- #entry = Zip::ZipStreamableDirectory.new "", "#{name}/"
82
- #
83
- #@zos.put_next_entry entry
84
- end
85
-
86
- def pattern_to_files dir, pattern
87
- Dir.glob("#{dir}/#{pattern}")
88
- end
89
-
90
- def strip_dot name
91
- if name[name.length-2..-1] == "/."
92
- name = name[0..name.length-3]
93
- end
94
-
95
- name
96
- end
97
-
98
- def full_name? name
99
- File.expand_path(name) == name
100
- end
101
-
102
- def full_name name
103
- full_name?(name) ? name : "#{from_dir}/#{name}"
104
- end
105
-
106
- end