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.
data/.idea/zip_dsl.iml CHANGED
@@ -36,7 +36,7 @@
36
36
  <ConfigurationWrapper RunnerId="RubyDebugRunner" />
37
37
  <method />
38
38
  </configuration>
39
- <configuration default="false" name="ZipDSL" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
39
+ <configuration default="false" name="ZipDSL#build excludes specified directory: zip_dsl" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
40
40
  <predefined_log_file id="RUBY_RSPEC" enabled="true" />
41
41
  <module name="zip_dsl" />
42
42
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
@@ -59,7 +59,7 @@
59
59
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/spec/zip_dsl_spec.rb" />
60
60
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
61
61
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
62
- <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="ZipDSL" />
62
+ <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="ZipDSL#build excludes specified directory" />
63
63
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" />
64
64
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
65
65
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
@@ -68,11 +68,13 @@
68
68
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" />
69
69
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPRING" VALUE="false" />
70
70
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" />
71
+ <RunnerSettings RunnerId="RubyDebugRunner" />
71
72
  <RunnerSettings RunnerId="RubyRunner" />
73
+ <ConfigurationWrapper RunnerId="RubyDebugRunner" />
72
74
  <ConfigurationWrapper RunnerId="RubyRunner" />
73
75
  <method />
74
76
  </configuration>
75
- <configuration default="false" name="zip_dsl_spec" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
77
+ <configuration default="false" name="ZipDSL#build should create new zip file with new empty folder: zip_dsl" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
76
78
  <predefined_log_file id="RUBY_RSPEC" enabled="true" />
77
79
  <module name="zip_dsl" />
78
80
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
@@ -95,7 +97,7 @@
95
97
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/spec/zip_dsl_spec.rb" />
96
98
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
97
99
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
98
- <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" />
100
+ <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="ZipDSL#build should create new zip file with new empty folder" />
99
101
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" />
100
102
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
101
103
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
@@ -108,7 +110,7 @@
108
110
  <ConfigurationWrapper RunnerId="RubyRunner" />
109
111
  <method />
110
112
  </configuration>
111
- <configuration default="false" name="ZipDSL should display files in specified subdirectory: zip_dsl" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
113
+ <configuration default="false" name="ZipDSL#build updates existing zip file: zip_dsl" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
112
114
  <predefined_log_file id="RUBY_RSPEC" enabled="true" />
113
115
  <module name="zip_dsl" />
114
116
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
@@ -119,7 +121,7 @@
119
121
  <envs>
120
122
  <env name="JRUBY_OPTS" value="-X+O" />
121
123
  </envs>
122
- <EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="false" />
124
+ <EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
123
125
  <EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
124
126
  <EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
125
127
  <COVERAGE_PATTERN ENABLED="true">
@@ -131,7 +133,7 @@
131
133
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/spec/zip_dsl_spec.rb" />
132
134
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
133
135
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
134
- <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="ZipDSL should display files in specified subdirectory" />
136
+ <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="ZipDSL#build updates existing zip file" />
135
137
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" />
136
138
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
137
139
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
@@ -144,7 +146,7 @@
144
146
  <ConfigurationWrapper RunnerId="RubyRunner" />
145
147
  <method />
146
148
  </configuration>
147
- <configuration default="false" name="ZipDSL#read: zip_dsl" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
149
+ <configuration default="false" name="Run spec 'zip_dsl_spec': zip_dsl" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
148
150
  <predefined_log_file id="RUBY_RSPEC" enabled="true" />
149
151
  <module name="zip_dsl" />
150
152
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
@@ -155,7 +157,7 @@
155
157
  <envs>
156
158
  <env name="JRUBY_OPTS" value="-X+O" />
157
159
  </envs>
158
- <EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="false" />
160
+ <EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
159
161
  <EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
160
162
  <EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
161
163
  <COVERAGE_PATTERN ENABLED="true">
@@ -167,7 +169,7 @@
167
169
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/spec/zip_dsl_spec.rb" />
168
170
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
169
171
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
170
- <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="ZipDSL#read" />
172
+ <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" />
171
173
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" />
172
174
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
173
175
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
@@ -176,11 +178,13 @@
176
178
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" />
177
179
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPRING" VALUE="false" />
178
180
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" />
181
+ <RunnerSettings RunnerId="RubyDebugRunner" />
179
182
  <RunnerSettings RunnerId="RubyRunner" />
183
+ <ConfigurationWrapper RunnerId="RubyDebugRunner" />
180
184
  <ConfigurationWrapper RunnerId="RubyRunner" />
181
185
  <method />
182
186
  </configuration>
183
- <configuration default="false" name="ZipDSL#build should create new zip file with files at particular folder: zip_dsl" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
187
+ <configuration default="false" name="ZipDSL#build excludes specified directories: zip_dsl" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
184
188
  <predefined_log_file id="RUBY_RSPEC" enabled="true" />
185
189
  <module name="zip_dsl" />
186
190
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
@@ -191,7 +195,7 @@
191
195
  <envs>
192
196
  <env name="JRUBY_OPTS" value="-X+O" />
193
197
  </envs>
194
- <EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="false" />
198
+ <EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
195
199
  <EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
196
200
  <EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
197
201
  <COVERAGE_PATTERN ENABLED="true">
@@ -203,7 +207,7 @@
203
207
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/spec/zip_dsl_spec.rb" />
204
208
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
205
209
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
206
- <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="ZipDSL#build should create new zip file with files at particular folder" />
210
+ <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="ZipDSL#build excludes specified directories" />
207
211
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" />
208
212
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
209
213
  <RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
@@ -221,21 +225,20 @@
221
225
  </component>
222
226
  <component name="NewModuleRootManager">
223
227
  <content url="file://$MODULE_DIR$" />
224
- <orderEntry type="jdk" jdkName="RVM: ruby-1.9.3-p550 [zip_dsl]" jdkType="RUBY_SDK" />
228
+ <orderEntry type="jdk" jdkName="RVM: ruby-2.2.0 [zip_dsl]" jdkType="RUBY_SDK" />
225
229
  <orderEntry type="sourceFolder" forTests="false" />
226
- <orderEntry type="library" scope="PROVIDED" name="bundler (v1.7.4, RVM: ruby-1.9.3-p550 [zip_dsl]) [gem]" level="application" />
227
- <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.5, RVM: ruby-1.9.3-p550 [zip_dsl]) [gem]" level="application" />
228
- <orderEntry type="library" scope="PROVIDED" name="file_utils (v1.0.7, RVM: ruby-1.9.3-p550 [zip_dsl]) [gem]" level="application" />
229
- <orderEntry type="library" scope="PROVIDED" name="gemcutter (v0.7.1, RVM: ruby-1.9.3-p550 [zip_dsl]) [gem]" level="application" />
230
- <orderEntry type="library" scope="PROVIDED" name="gemspec_deps_gen (v1.1.2, RVM: ruby-1.9.3-p550 [zip_dsl]) [gem]" level="application" />
231
- <orderEntry type="library" scope="PROVIDED" name="meta_methods (v1.2.0, RVM: ruby-1.9.3-p550 [zip_dsl]) [gem]" level="application" />
232
- <orderEntry type="library" scope="PROVIDED" name="metaclass (v0.0.4, RVM: ruby-1.9.3-p550 [zip_dsl]) [gem]" level="application" />
233
- <orderEntry type="library" scope="PROVIDED" name="mocha (v1.1.0, RVM: ruby-1.9.3-p550 [zip_dsl]) [gem]" level="application" />
234
- <orderEntry type="library" scope="PROVIDED" name="rspec (v3.1.0, RVM: ruby-1.9.3-p550 [zip_dsl]) [gem]" level="application" />
235
- <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.1.7, RVM: ruby-1.9.3-p550 [zip_dsl]) [gem]" level="application" />
236
- <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.1.2, RVM: ruby-1.9.3-p550 [zip_dsl]) [gem]" level="application" />
237
- <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.1.3, RVM: ruby-1.9.3-p550 [zip_dsl]) [gem]" level="application" />
238
- <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.1.2, RVM: ruby-1.9.3-p550 [zip_dsl]) [gem]" level="application" />
239
- <orderEntry type="library" scope="PROVIDED" name="zip (v2.0.2, RVM: ruby-1.9.3-p550 [zip_dsl]) [gem]" level="application" />
230
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v1.7.9, RVM: ruby-2.2.0 [zip_dsl]) [gem]" level="application" />
231
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.5, RVM: ruby-2.2.0 [zip_dsl]) [gem]" level="application" />
232
+ <orderEntry type="library" scope="PROVIDED" name="gemcutter (v0.7.1, RVM: ruby-2.2.0 [zip_dsl]) [gem]" level="application" />
233
+ <orderEntry type="library" scope="PROVIDED" name="gemspec_deps_gen (v1.1.2, RVM: ruby-2.2.0 [zip_dsl]) [gem]" level="application" />
234
+ <orderEntry type="library" scope="PROVIDED" name="meta_methods (v1.3.0, RVM: ruby-2.2.0 [zip_dsl]) [gem]" level="application" />
235
+ <orderEntry type="library" scope="PROVIDED" name="metaclass (v0.0.4, RVM: ruby-2.2.0 [zip_dsl]) [gem]" level="application" />
236
+ <orderEntry type="library" scope="PROVIDED" name="mocha (v1.1.0, RVM: ruby-2.2.0 [zip_dsl]) [gem]" level="application" />
237
+ <orderEntry type="library" scope="PROVIDED" name="rspec (v3.2.0, RVM: ruby-2.2.0 [zip_dsl]) [gem]" level="application" />
238
+ <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.2.0, RVM: ruby-2.2.0 [zip_dsl]) [gem]" level="application" />
239
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.2.0, RVM: ruby-2.2.0 [zip_dsl]) [gem]" level="application" />
240
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.2.0, RVM: ruby-2.2.0 [zip_dsl]) [gem]" level="application" />
241
+ <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.2.1, RVM: ruby-2.2.0 [zip_dsl]) [gem]" level="application" />
242
+ <orderEntry type="library" scope="PROVIDED" name="zip (v2.0.2, RVM: ruby-2.2.0 [zip_dsl]) [gem]" level="application" />
240
243
  </component>
241
244
  </module>
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.4
1
+ 2.2.0
data/CHANGES CHANGED
@@ -48,4 +48,10 @@
48
48
 
49
49
  * Bug fix.
50
50
 
51
+ == Version 1.5.0
52
+
53
+ * Merging zip_updated into zip_writer.
54
+ * Use directory_scanner
55
+ * Introduce includes/excludes
56
+
51
57
 
@@ -1,3 +1,3 @@
1
1
  class ZipDSL
2
- VERSION = "1.4.4"
2
+ VERSION = "1.5.0"
3
3
  end
@@ -3,9 +3,11 @@ require 'meta_methods/dsl_builder'
3
3
  class ZipDSL
4
4
  attr_reader :name, :from_dir
5
5
 
6
- def initialize name, from_dir = nil
6
+ def initialize name, from_dir=".", params={}
7
7
  @name = name
8
- @from_dir = from_dir.nil? ? from_dir : File.expand_path(from_dir)
8
+ @from_dir = File.expand_path(from_dir)
9
+ @includes = params[:includes]
10
+ @excludes = params[:excludes]
9
11
 
10
12
  to_root = File.expand_path(File.dirname(name))
11
13
  FileUtils.mkdir_p(to_root) unless File.exists? to_root
@@ -14,21 +16,12 @@ class ZipDSL
14
16
  def build(name=nil, &execute_block)
15
17
  name = name.nil? ? @name : name
16
18
 
17
- create_block = lambda { ZipWriter.new(name, from_dir) }
19
+ create_block = lambda { ZipWriter.new(name, from_dir, @includes, @excludes) }
18
20
  destroy_block = lambda {|writer| writer.close }
19
21
 
20
22
  MetaMethods::DslBuilder.instance.evaluate_dsl(create_block, destroy_block, execute_block)
21
23
  end
22
24
 
23
- def update(name=nil, &execute_block)
24
- name = name.nil? ? @name : name
25
-
26
- create_block = lambda { ZipUpdater.new(name, from_dir) }
27
- destroy_block = lambda {|updater| updater.close }
28
-
29
- MetaMethods::DslBuilder.instance.evaluate_dsl(create_block, destroy_block, execute_block)
30
- end
31
-
32
25
  def entry_exist? entry_name
33
26
  create_block = lambda { ZipReader.new(name) }
34
27
  destroy_block = lambda {|reader| reader.close }
@@ -1,24 +1,36 @@
1
+ require 'file_utils/directory_scanner'
1
2
  require 'zip/zip'
2
3
 
3
4
  class ZipWriter
4
5
  attr_reader :from_dir
5
6
 
6
- def initialize name, from_dir
7
+ def initialize name, from_dir, includes=[], excludes=[]
7
8
  @from_dir = from_dir
9
+ @global_includes = includes
10
+ @global_excludes = excludes
8
11
 
9
- @zos = Zip::ZipOutputStream.new(name)
10
-
11
- @compression_level = Zlib::BEST_COMPRESSION
12
+ if File.exist?(name)
13
+ @zipfile = Zip::ZipFile.open(name)
14
+ @new_file = false
15
+ else
16
+ @compression_level = Zlib::BEST_COMPRESSION
17
+ @zos = Zip::ZipOutputStream.new(name)
18
+ @new_file = true
19
+ end
12
20
  end
13
21
 
14
22
  def close
15
- @zos.close
23
+ @new_file ? @zos.close : @zipfile.close
16
24
  end
17
25
 
18
26
  def file params
19
27
  to_dir = params[:to_dir].nil? ? File.dirname(params[:name]) : strip_dot(params[:to_dir])
20
28
 
21
- add_file full_name(params[:name]), to_dir
29
+ if @new_file
30
+ add_file full_name(params[:name]), to_dir
31
+ else
32
+ add_or_replace_file full_name(params[:name]), "#{to_dir}/#{params[:name]}"
33
+ end
22
34
  end
23
35
 
24
36
  def content params
@@ -37,43 +49,66 @@ class ZipWriter
37
49
  to_dir = params[:to_dir]
38
50
  end
39
51
 
40
- filter = params[:filter].nil? ? "**/*" : params[:filter]
52
+ includes = build_filter(params[:includes], @global_includes)
53
+ excludes = build_filter(params[:excludes], @global_excludes)
41
54
 
42
- add_directory params[:from_dir], to_dir, filter
55
+ add_directory File.expand_path(params[:from_dir]), to_dir, includes, excludes
43
56
  end
44
57
  end
45
58
 
46
59
  private
47
60
 
61
+ def build_filter from1, from2
62
+ from1 = from1.nil? ? [] : from1
63
+ from2 = from2.nil? ? [] : from2
64
+
65
+ from1 + from2
66
+ end
67
+
68
+ def add_or_replace_file from_name, to_name
69
+ begin
70
+ @zipfile.add to_name, from_name
71
+ rescue Zip::ZipEntryExistsError
72
+ @zipfile.replace to_name, from_name
73
+ end
74
+ end
75
+
48
76
  def add_file name, to_dir = nil
49
77
  add name, to_dir, File.open(name)
50
78
  end
51
79
 
52
- def add_directory from_dir, to_dir, filter="**/*"
53
- patterns = filter.kind_of?(String) ? [filter] : filter
54
-
55
- patterns.each do |pattern|
56
- files = pattern_to_files full_name(from_dir), pattern
80
+ def add_directory from, to_dir, includes, excludes
81
+ scanner = DirectoryScanner.new
82
+ files = scanner.scan full_name(from), false, :includes => includes, :excludes => excludes
57
83
 
58
- files.each do |file_name|
59
- suffix = File.dirname(file_name)[full_name(from_dir).size+1..-1]
60
- dir = suffix.nil? ? to_dir : "#{to_dir}/#{suffix}"
84
+ files.each do |file_name|
85
+ suffix = File.dirname(file_name)[full_name(from).size+1..-1]
86
+ dir = suffix.nil? ? to_dir : "#{to_dir}/#{suffix}"
61
87
 
62
- if File.file?(file_name)
88
+ if File.file?(file_name)
89
+ if @new_file
63
90
  add_file file_name, dir
91
+ else
92
+ to_name = "#{dir}/#{file_name[full_name(dir).size+1..-1]}"
93
+
94
+ add_or_replace_file file_name, to_name
64
95
  end
65
96
  end
66
97
  end
67
98
  end
68
99
 
69
- def pattern_to_files dir, pattern
70
- Dir.glob("#{dir}/#{pattern}")
71
- end
72
-
73
100
  def add_empty_directory(name)
74
- entry = Zip::ZipStreamableDirectory.new "", "#{name}/"
101
+ if @new_file
102
+ entry = Zip::ZipStreamableDirectory.new "", "#{name}/"
103
+
104
+ @zos.put_next_entry entry
105
+ else
106
+ puts "adding empty dir: #{name}"
75
107
 
76
- @zos.put_next_entry entry
108
+ #entry = Zip::ZipStreamableDirectory.new "", "#{name}/"
109
+ #
110
+ #@zos.put_next_entry entry
111
+ end
77
112
  end
78
113
 
79
114
  def add name, to_dir, source
data/lib/zip_dsl.rb CHANGED
@@ -1,4 +1,3 @@
1
1
  require 'zip_dsl/zip_reader'
2
2
  require 'zip_dsl/zip_writer'
3
- require 'zip_dsl/zip_updater'
4
3
  require 'zip_dsl/zip_dsl'
data/spec/zip_dsl_spec.rb CHANGED
@@ -15,7 +15,7 @@ describe ZipDSL do
15
15
  end
16
16
 
17
17
  describe "#build" do
18
- it "should create new zip file with files at particular folder" do
18
+ it "creates new zip file with files at particular folder" do
19
19
  subject.build do
20
20
  file :name => "Gemfile"
21
21
  file :name => "Rakefile", :to_dir => "my_config"
@@ -29,7 +29,7 @@ describe ZipDSL do
29
29
  expect(subject.entries_size).to eq 3
30
30
  end
31
31
 
32
- it "should create new zip file with file created from string" do
32
+ it "creates new zip file with file created from string" do
33
33
  subject.build do
34
34
  content :name => "README", :source => "My README file content"
35
35
  end
@@ -38,7 +38,7 @@ describe ZipDSL do
38
38
  expect(subject.entries_size).to eq 1
39
39
  end
40
40
 
41
- it "should create new zip file with file created from file" do
41
+ it "creates new zip file with file created from file" do
42
42
  src = File.open("#{from_dir}/Rakefile")
43
43
  subject.build do
44
44
  content :name => "Rakefile", :source => src
@@ -57,7 +57,7 @@ describe ZipDSL do
57
57
  expect(subject.entries_size).to eq 1
58
58
  end
59
59
 
60
- it "should create new zip file with new folder" do
60
+ it "creates new zip file with new folder" do
61
61
  subject.build do
62
62
  directory :from_dir => "spec", :to_dir => "my_config"
63
63
  end
@@ -65,10 +65,8 @@ describe ZipDSL do
65
65
  expect(subject.entry_exist?("my_config")).to be_truthy
66
66
  expect(subject.entries_size).to be > 1
67
67
  end
68
- end
69
68
 
70
- describe "#update" do
71
- it "should update existing zip file" do
69
+ it "updates existing zip file" do
72
70
  subject.build do
73
71
  file :name => "Gemfile"
74
72
  end
@@ -76,7 +74,7 @@ describe ZipDSL do
76
74
  expect(File.exist?(subject.name)).to be_truthy
77
75
  expect(subject.entry_exist?("Gemfile")).to be_truthy
78
76
 
79
- subject.update do
77
+ subject.build do
80
78
  file :name => "README.md"
81
79
  directory :from_dir => "lib"
82
80
  end
@@ -85,10 +83,21 @@ describe ZipDSL do
85
83
  expect(subject.entry_exist?("README.md")).to be_truthy
86
84
  expect(subject.entry_exist?("lib/zip_dsl/version.rb")).to be_truthy
87
85
  end
86
+
87
+ it "excludes specified directories" do
88
+ subject = ZipDSL.new "build/test.zip", from_dir, :excludes => [".git", ".idea", ".DS_Store"]
89
+
90
+ subject.build do
91
+ directory :from_dir => ".", :excludes => ["build"]
92
+ end
93
+
94
+ expect(subject.entry_exist?("build")).to be_falsey
95
+ expect(subject.entry_exist?(".git")).to be_falsey
96
+ end
88
97
  end
89
98
 
90
99
  describe "#list" do
91
- it "should display files in current directory" do
100
+ it "displays files in current directory" do
92
101
  subject.build do
93
102
  directory :from_dir => "spec"
94
103
  end
@@ -96,7 +105,7 @@ describe ZipDSL do
96
105
  expect(subject.list).to include "spec/spec_helper.rb"
97
106
  end
98
107
 
99
- it "should display files in specified subdirectory" do
108
+ it "displays files in specified subdirectory" do
100
109
  subject.build do
101
110
  directory :from_dir => "lib"
102
111
  end
@@ -106,7 +115,7 @@ describe ZipDSL do
106
115
  end
107
116
 
108
117
  describe "#each_entry" do
109
- it "should display files in specified subdirectory" do
118
+ it "displays files in specified subdirectory" do
110
119
  subject.build do
111
120
  directory :from_dir => "lib"
112
121
  end
metadata CHANGED
@@ -1,105 +1,105 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zip_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.4
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Shvets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-07 00:00:00.000000000 Z
11
+ date: 2015-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zip
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: file_utils
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: meta_methods
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: gemspec_deps_gen
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: gemcutter
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: ! 'Library for working with zip file in DSL-way '
83
+ description: 'Library for working with zip file in DSL-way '
84
84
  email: alexander.shvets@gmail.com
85
85
  executables: []
86
86
  extensions: []
87
87
  extra_rdoc_files: []
88
88
  files:
89
- - .gitignore
90
- - .idea/.name
91
- - .idea/.rakeTasks
92
- - .idea/cssxfire.xml
93
- - .idea/encodings.xml
94
- - .idea/misc.xml
95
- - .idea/modules.xml
96
- - .idea/runConfigurations/rake.xml
97
- - .idea/scopes/scope_settings.xml
98
- - .idea/vcs.xml
99
- - .idea/workspace.xml
100
- - .idea/zip_dsl.iml
101
- - .ruby-gemset
102
- - .ruby-version
89
+ - ".gitignore"
90
+ - ".idea/.name"
91
+ - ".idea/.rakeTasks"
92
+ - ".idea/cssxfire.xml"
93
+ - ".idea/encodings.xml"
94
+ - ".idea/misc.xml"
95
+ - ".idea/modules.xml"
96
+ - ".idea/runConfigurations/rake.xml"
97
+ - ".idea/scopes/scope_settings.xml"
98
+ - ".idea/vcs.xml"
99
+ - ".idea/workspace.xml"
100
+ - ".idea/zip_dsl.iml"
101
+ - ".ruby-gemset"
102
+ - ".ruby-version"
103
103
  - CHANGES
104
104
  - Gemfile
105
105
  - LICENSE
@@ -109,7 +109,6 @@ files:
109
109
  - lib/zip_dsl/version.rb
110
110
  - lib/zip_dsl/zip_dsl.rb
111
111
  - lib/zip_dsl/zip_reader.rb
112
- - lib/zip_dsl/zip_updater.rb
113
112
  - lib/zip_dsl/zip_writer.rb
114
113
  - spec/spec_helper.rb
115
114
  - spec/zip_dsl_spec.rb
@@ -125,17 +124,17 @@ require_paths:
125
124
  - lib
126
125
  required_ruby_version: !ruby/object:Gem::Requirement
127
126
  requirements:
128
- - - ! '>='
127
+ - - ">="
129
128
  - !ruby/object:Gem::Version
130
129
  version: '0'
131
130
  required_rubygems_version: !ruby/object:Gem::Requirement
132
131
  requirements:
133
- - - ! '>='
132
+ - - ">="
134
133
  - !ruby/object:Gem::Version
135
134
  version: '0'
136
135
  requirements: []
137
136
  rubyforge_project:
138
- rubygems_version: 2.2.2
137
+ rubygems_version: 2.4.5
139
138
  signing_key:
140
139
  specification_version: 4
141
140
  summary: Library for working with zip file in DSL-way