zip_dsl 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.idea/workspace.xml +147 -102
- data/.idea/zip_dsl.iml +1 -0
- data/Gemfile +1 -1
- data/build/test/directory_builder.rb +105 -0
- data/build/test/version.rb +3 -0
- data/build/test/zip_dsl/version.rb +3 -0
- data/build/test/zip_dsl/zip_dsl.rb +45 -0
- data/build/test/zip_dsl/zip_reader.rb +65 -0
- data/build/test/zip_dsl/zip_writer.rb +108 -0
- data/build/test/zip_dsl.rb +3 -0
- data/build/test/zip_reader.rb +65 -0
- data/build/test/zip_writer.rb +108 -0
- data/lib/directory_builder.rb +20 -13
- data/lib/zip_dsl/version.rb +1 -1
- data/lib/zip_dsl/zip_dsl.rb +1 -1
- data/spec/directory_builder_spec.rb +14 -12
- data/spec/zip_builder_spec.rb +1 -1
- data/zip_dsl.gemspec +1 -0
- metadata +26 -1
data/.idea/workspace.xml
CHANGED
@@ -2,9 +2,6 @@
|
|
2
2
|
<project version="4">
|
3
3
|
<component name="ChangeListManager">
|
4
4
|
<list default="true" id="aafa5aec-b597-47d5-af91-f7b63300321f" name="Default" comment="">
|
5
|
-
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/zip_dsl.iml" afterPath="$PROJECT_DIR$/.idea/zip_dsl.iml" />
|
6
|
-
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
|
7
|
-
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/Gemfile" afterPath="$PROJECT_DIR$/Gemfile" />
|
8
5
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/zip_dsl/version.rb" afterPath="$PROJECT_DIR$/lib/zip_dsl/version.rb" />
|
9
6
|
</list>
|
10
7
|
<ignored path="zip_dsl.iws" />
|
@@ -27,10 +24,10 @@
|
|
27
24
|
</component>
|
28
25
|
<component name="FileEditorManager">
|
29
26
|
<leaf>
|
30
|
-
<file leaf-file-name="
|
31
|
-
<entry file="file://$PROJECT_DIR$/
|
27
|
+
<file leaf-file-name="directory_builder_spec.rb" pinned="false" current="false" current-in-tab="false">
|
28
|
+
<entry file="file://$PROJECT_DIR$/spec/directory_builder_spec.rb">
|
32
29
|
<provider selected="true" editor-type-id="text-editor">
|
33
|
-
<state line="
|
30
|
+
<state line="77" column="54" selection-start="2099" selection-end="2099" vertical-scroll-proportion="0.0">
|
34
31
|
<folding />
|
35
32
|
</state>
|
36
33
|
</provider>
|
@@ -45,46 +42,10 @@
|
|
45
42
|
</provider>
|
46
43
|
</entry>
|
47
44
|
</file>
|
48
|
-
<file leaf-file-name="
|
49
|
-
<entry file="file://$PROJECT_DIR$/
|
50
|
-
<provider selected="true" editor-type-id="text-editor">
|
51
|
-
<state line="13" column="18" selection-start="535" selection-end="535" vertical-scroll-proportion="0.0">
|
52
|
-
<folding />
|
53
|
-
</state>
|
54
|
-
</provider>
|
55
|
-
</entry>
|
56
|
-
</file>
|
57
|
-
<file leaf-file-name="zip_dsl.rb" pinned="false" current="false" current-in-tab="false">
|
58
|
-
<entry file="file://$PROJECT_DIR$/lib/zip_dsl/zip_dsl.rb">
|
59
|
-
<provider selected="true" editor-type-id="text-editor">
|
60
|
-
<state line="3" column="14" selection-start="53" selection-end="53" vertical-scroll-proportion="0.0">
|
61
|
-
<folding />
|
62
|
-
</state>
|
63
|
-
</provider>
|
64
|
-
</entry>
|
65
|
-
</file>
|
66
|
-
<file leaf-file-name="zip_dsl.rb" pinned="false" current="false" current-in-tab="false">
|
67
|
-
<entry file="file://$PROJECT_DIR$/lib/zip_dsl.rb">
|
68
|
-
<provider selected="true" editor-type-id="text-editor">
|
69
|
-
<state line="3" column="136" selection-start="84" selection-end="84" vertical-scroll-proportion="0.0">
|
70
|
-
<folding />
|
71
|
-
</state>
|
72
|
-
</provider>
|
73
|
-
</entry>
|
74
|
-
</file>
|
75
|
-
<file leaf-file-name="Gemfile" pinned="false" current="false" current-in-tab="false">
|
76
|
-
<entry file="file://$PROJECT_DIR$/Gemfile">
|
77
|
-
<provider selected="true" editor-type-id="text-editor">
|
78
|
-
<state line="5" column="15" selection-start="85" selection-end="85" vertical-scroll-proportion="0.0">
|
79
|
-
<folding />
|
80
|
-
</state>
|
81
|
-
</provider>
|
82
|
-
</entry>
|
83
|
-
</file>
|
84
|
-
<file leaf-file-name="directory_builder_spec.rb" pinned="false" current="false" current-in-tab="false">
|
85
|
-
<entry file="file://$PROJECT_DIR$/spec/directory_builder_spec.rb">
|
45
|
+
<file leaf-file-name="directory_builder.rb" pinned="false" current="false" current-in-tab="false">
|
46
|
+
<entry file="file://$PROJECT_DIR$/lib/directory_builder.rb">
|
86
47
|
<provider selected="true" editor-type-id="text-editor">
|
87
|
-
<state line="
|
48
|
+
<state line="37" column="66" selection-start="738" selection-end="783" vertical-scroll-proportion="0.0">
|
88
49
|
<folding />
|
89
50
|
</state>
|
90
51
|
</provider>
|
@@ -106,14 +67,15 @@
|
|
106
67
|
<option value="$PROJECT_DIR$/.rvmrc" />
|
107
68
|
<option value="$PROJECT_DIR$/Rakefile" />
|
108
69
|
<option value="$PROJECT_DIR$/lib/zip_dsl.rb" />
|
109
|
-
<option value="$PROJECT_DIR$/lib/directory_builder.rb" />
|
110
70
|
<option value="$PROJECT_DIR$/spec/spec_helper.rb" />
|
111
|
-
<option value="$PROJECT_DIR$/lib/zip_dsl/zip_dsl.rb" />
|
112
|
-
<option value="$PROJECT_DIR$/spec/zip_builder_spec.rb" />
|
113
71
|
<option value="$PROJECT_DIR$/lib/zip_dsl/zip_writer.rb" />
|
114
72
|
<option value="$PROJECT_DIR$/zip_dsl.gemspec" />
|
115
73
|
<option value="$PROJECT_DIR$/zip_dsl.gemspec.erb" />
|
74
|
+
<option value="$PROJECT_DIR$/lib/zip_dsl/zip_dsl.rb" />
|
116
75
|
<option value="$PROJECT_DIR$/Gemfile" />
|
76
|
+
<option value="$PROJECT_DIR$/spec/zip_builder_spec.rb" />
|
77
|
+
<option value="$PROJECT_DIR$/lib/directory_builder.rb" />
|
78
|
+
<option value="$PROJECT_DIR$/spec/directory_builder_spec.rb" />
|
117
79
|
<option value="$PROJECT_DIR$/lib/zip_dsl/version.rb" />
|
118
80
|
</list>
|
119
81
|
</option>
|
@@ -150,6 +112,7 @@
|
|
150
112
|
<sortByType />
|
151
113
|
</navigator>
|
152
114
|
<panes>
|
115
|
+
<pane id="Scope" />
|
153
116
|
<pane id="ProjectPane">
|
154
117
|
<subPane>
|
155
118
|
<PATH>
|
@@ -216,11 +179,11 @@
|
|
216
179
|
</PATH>
|
217
180
|
</subPane>
|
218
181
|
</pane>
|
219
|
-
<pane id="Scope" />
|
220
182
|
</panes>
|
221
183
|
</component>
|
222
184
|
<component name="PropertiesComponent">
|
223
185
|
<property name="recentsLimit" value="5" />
|
186
|
+
<property name="GoToClass.includeJavaFiles" value="false" />
|
224
187
|
</component>
|
225
188
|
<component name="RecentsManager">
|
226
189
|
<key name="MoveFile.RECENT_KEYS">
|
@@ -228,8 +191,8 @@
|
|
228
191
|
<recent name="$PROJECT_DIR$/lib" />
|
229
192
|
</key>
|
230
193
|
</component>
|
231
|
-
<component name="RunManager" selected="RSpec.
|
232
|
-
<configuration default="false" name="
|
194
|
+
<component name="RunManager" selected="RSpec.directory_builder_spec">
|
195
|
+
<configuration default="false" name="DirectoryBuilder should create new zip file with file created from string" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
|
233
196
|
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
|
234
197
|
<module name="zip_dsl" />
|
235
198
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
@@ -250,18 +213,20 @@
|
|
250
213
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$PROJECT_DIR$/spec/directory_builder_spec.rb" />
|
251
214
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
|
252
215
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
|
253
|
-
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" />
|
216
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="DirectoryBuilder should create new zip file with file created from string" />
|
254
217
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" />
|
255
218
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
|
256
219
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
|
257
220
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" />
|
258
221
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" />
|
259
222
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" />
|
223
|
+
<RunnerSettings RunnerId="RubyDebugRunner" />
|
260
224
|
<RunnerSettings RunnerId="RubyRunner" />
|
225
|
+
<ConfigurationWrapper RunnerId="RubyDebugRunner" />
|
261
226
|
<ConfigurationWrapper RunnerId="RubyRunner" />
|
262
227
|
<method />
|
263
228
|
</configuration>
|
264
|
-
<configuration default="false" name="
|
229
|
+
<configuration default="false" name="DirectoryBuilder should create new zip file with new empty folder" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
|
265
230
|
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
|
266
231
|
<module name="zip_dsl" />
|
267
232
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
@@ -279,21 +244,21 @@
|
|
279
244
|
</COVERAGE_PATTERN>
|
280
245
|
</EXTENSION>
|
281
246
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" />
|
282
|
-
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$PROJECT_DIR$/spec/
|
247
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$PROJECT_DIR$/spec/directory_builder_spec.rb" />
|
283
248
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
|
284
249
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
|
285
|
-
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="
|
250
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="DirectoryBuilder should create new zip file with new empty folder" />
|
286
251
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" />
|
287
252
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
|
288
253
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
|
289
254
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" />
|
290
255
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" />
|
291
256
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" />
|
292
|
-
<RunnerSettings RunnerId="
|
293
|
-
<ConfigurationWrapper RunnerId="
|
257
|
+
<RunnerSettings RunnerId="RubyDebugRunner" />
|
258
|
+
<ConfigurationWrapper RunnerId="RubyDebugRunner" />
|
294
259
|
<method />
|
295
260
|
</configuration>
|
296
|
-
<configuration default="false" name="
|
261
|
+
<configuration default="false" name="DirectoryBuilder should display files in current directory" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
|
297
262
|
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
|
298
263
|
<module name="zip_dsl" />
|
299
264
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
@@ -311,10 +276,10 @@
|
|
311
276
|
</COVERAGE_PATTERN>
|
312
277
|
</EXTENSION>
|
313
278
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" />
|
314
|
-
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$PROJECT_DIR$/spec/
|
279
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$PROJECT_DIR$/spec/directory_builder_spec.rb" />
|
315
280
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
|
316
281
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
|
317
|
-
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="
|
282
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="DirectoryBuilder should display files in current directory" />
|
318
283
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" />
|
319
284
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
|
320
285
|
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
|
@@ -359,6 +324,38 @@
|
|
359
324
|
<ConfigurationWrapper RunnerId="RubyRunner" />
|
360
325
|
<method />
|
361
326
|
</configuration>
|
327
|
+
<configuration default="false" name="directory_builder_spec" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
|
328
|
+
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
|
329
|
+
<module name="zip_dsl" />
|
330
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
331
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$PROJECT_DIR$/spec" />
|
332
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
|
333
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
|
334
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" />
|
335
|
+
<envs>
|
336
|
+
<env name="JRUBY_OPTS" value="-X+O" />
|
337
|
+
</envs>
|
338
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
|
339
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
|
340
|
+
<COVERAGE_PATTERN ENABLED="true">
|
341
|
+
<PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
|
342
|
+
</COVERAGE_PATTERN>
|
343
|
+
</EXTENSION>
|
344
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" />
|
345
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$PROJECT_DIR$/spec/directory_builder_spec.rb" />
|
346
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
|
347
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
|
348
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" />
|
349
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" />
|
350
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
|
351
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
|
352
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" />
|
353
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" />
|
354
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" />
|
355
|
+
<RunnerSettings RunnerId="RubyRunner" />
|
356
|
+
<ConfigurationWrapper RunnerId="RubyRunner" />
|
357
|
+
<method />
|
358
|
+
</configuration>
|
362
359
|
<configuration default="true" type="RSpecRunConfigurationType" factoryName="RSpec">
|
363
360
|
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
|
364
361
|
<module name="" />
|
@@ -429,19 +426,20 @@
|
|
429
426
|
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_OPTIONS" VALUE="" />
|
430
427
|
<method />
|
431
428
|
</configuration>
|
432
|
-
<list size="
|
433
|
-
<item index="0" class="java.lang.String" itemvalue="RSpec.
|
434
|
-
<item index="1" class="java.lang.String" itemvalue="RSpec.
|
435
|
-
<item index="2" class="java.lang.String" itemvalue="RSpec.
|
429
|
+
<list size="5">
|
430
|
+
<item index="0" class="java.lang.String" itemvalue="RSpec.DirectoryBuilder should create new zip file with file created from string" />
|
431
|
+
<item index="1" class="java.lang.String" itemvalue="RSpec.DirectoryBuilder should create new zip file with new empty folder" />
|
432
|
+
<item index="2" class="java.lang.String" itemvalue="RSpec.DirectoryBuilder should display files in current directory" />
|
436
433
|
<item index="3" class="java.lang.String" itemvalue="RSpec.zip_builder_spec" />
|
434
|
+
<item index="4" class="java.lang.String" itemvalue="RSpec.directory_builder_spec" />
|
437
435
|
</list>
|
438
436
|
<recent_temporary>
|
439
437
|
<list size="5">
|
440
|
-
<item index="0" class="java.lang.String" itemvalue="RSpec.
|
441
|
-
<item index="1" class="java.lang.String" itemvalue="RSpec.
|
442
|
-
<item index="2" class="java.lang.String" itemvalue="RSpec.
|
443
|
-
<item index="3" class="java.lang.String" itemvalue="RSpec.
|
444
|
-
<item index="4" class="java.lang.String" itemvalue="RSpec.
|
438
|
+
<item index="0" class="java.lang.String" itemvalue="RSpec.directory_builder_spec" />
|
439
|
+
<item index="1" class="java.lang.String" itemvalue="RSpec.DirectoryBuilder should display files in current directory" />
|
440
|
+
<item index="2" class="java.lang.String" itemvalue="RSpec.directory_builder_spec" />
|
441
|
+
<item index="3" class="java.lang.String" itemvalue="RSpec.zip_builder_spec" />
|
442
|
+
<item index="4" class="java.lang.String" itemvalue="RSpec.directory_builder_spec" />
|
445
443
|
</list>
|
446
444
|
</recent_temporary>
|
447
445
|
</component>
|
@@ -524,92 +522,139 @@
|
|
524
522
|
<option name="FILE_HISTORY_SPLITTER_PROPORTION" value="0.6" />
|
525
523
|
</component>
|
526
524
|
<component name="XDebuggerManager">
|
527
|
-
<breakpoint-manager
|
525
|
+
<breakpoint-manager>
|
526
|
+
<breakpoints>
|
527
|
+
<line-breakpoint enabled="true" type="ruby-line">
|
528
|
+
<url>file://$PROJECT_DIR$/lib/directory_builder.rb</url>
|
529
|
+
<line>37</line>
|
530
|
+
</line-breakpoint>
|
531
|
+
<line-breakpoint enabled="true" type="ruby-line">
|
532
|
+
<url>file://$PROJECT_DIR$/spec/zip_builder_spec.rb</url>
|
533
|
+
<line>10</line>
|
534
|
+
</line-breakpoint>
|
535
|
+
<line-breakpoint enabled="true" type="ruby-line">
|
536
|
+
<url>file://$USER_HOME$/.rvm/gems/ruby-1.9.3-p194@zip_dsl/gems/rubyzip-0.9.8/lib/zip/zip_entry.rb</url>
|
537
|
+
<line>443</line>
|
538
|
+
</line-breakpoint>
|
539
|
+
<line-breakpoint enabled="true" type="ruby-line">
|
540
|
+
<url>file://$USER_HOME$/.rvm/gems/ruby-1.9.3-p194@zip_dsl/gems/rubyzip-0.9.8/lib/zip/zip_central_directory.rb</url>
|
541
|
+
<line>23</line>
|
542
|
+
</line-breakpoint>
|
543
|
+
<line-breakpoint enabled="true" type="ruby-line">
|
544
|
+
<url>file://$USER_HOME$/.rvm/gems/ruby-1.9.3-p194@zip_dsl/gems/rubyzip-0.9.8/lib/zip/zip_output_stream.rb</url>
|
545
|
+
<line>64</line>
|
546
|
+
</line-breakpoint>
|
547
|
+
<line-breakpoint enabled="true" type="ruby-line">
|
548
|
+
<url>file://$PROJECT_DIR$/spec/directory_builder_spec.rb</url>
|
549
|
+
<line>34</line>
|
550
|
+
</line-breakpoint>
|
551
|
+
<line-breakpoint enabled="true" type="ruby-line">
|
552
|
+
<url>file://$PROJECT_DIR$/spec/directory_builder_spec.rb</url>
|
553
|
+
<line>30</line>
|
554
|
+
</line-breakpoint>
|
555
|
+
</breakpoints>
|
556
|
+
</breakpoint-manager>
|
528
557
|
</component>
|
529
558
|
<component name="editorHistoryManager">
|
530
|
-
<entry file="file://$
|
559
|
+
<entry file="file://$USER_HOME$/.rvm/gems/ruby-1.9.3-p194@zip_dsl/gems/rspec-core-2.9.0/lib/rspec/core/example.rb">
|
531
560
|
<provider selected="true" editor-type-id="text-editor">
|
532
|
-
<state line="
|
561
|
+
<state line="104" column="0" selection-start="3599" selection-end="3599" vertical-scroll-proportion="3.0254545">
|
562
|
+
<folding />
|
563
|
+
</state>
|
533
564
|
</provider>
|
534
565
|
</entry>
|
535
|
-
<entry file="file://$PROJECT_DIR$/
|
566
|
+
<entry file="file://$PROJECT_DIR$/Gemfile">
|
536
567
|
<provider selected="true" editor-type-id="text-editor">
|
537
|
-
<state line="
|
568
|
+
<state line="5" column="2" selection-start="71" selection-end="71" vertical-scroll-proportion="0.13445379">
|
569
|
+
<folding />
|
570
|
+
</state>
|
538
571
|
</provider>
|
539
572
|
</entry>
|
540
|
-
<entry file="file://$
|
573
|
+
<entry file="file://$USER_HOME$/.rvm/gems/ruby-1.9.3-p194@zip_dsl/gems/rubyzip-0.9.8/lib/zip/zip_entry.rb">
|
541
574
|
<provider selected="true" editor-type-id="text-editor">
|
542
|
-
<state line="
|
575
|
+
<state line="51" column="20" selection-start="1414" selection-end="1414" vertical-scroll-proportion="0.36134455">
|
576
|
+
<folding />
|
577
|
+
</state>
|
543
578
|
</provider>
|
544
579
|
</entry>
|
545
|
-
<entry file="file://$
|
580
|
+
<entry file="file://$USER_HOME$/.rvm/gems/ruby-1.9.3-p194@zip_dsl/gems/rubyzip-0.9.8/lib/zip/zip_central_directory.rb">
|
546
581
|
<provider selected="true" editor-type-id="text-editor">
|
547
|
-
<state line="
|
582
|
+
<state line="23" column="0" selection-start="594" selection-end="594" vertical-scroll-proportion="0.32090762">
|
583
|
+
<folding />
|
584
|
+
</state>
|
548
585
|
</provider>
|
549
586
|
</entry>
|
550
|
-
<entry file="file://$
|
587
|
+
<entry file="file://$USER_HOME$/.rvm/gems/ruby-1.9.3-p194@zip_dsl/gems/rubyzip-0.9.8/lib/zip/zip_entry_set.rb">
|
551
588
|
<provider selected="true" editor-type-id="text-editor">
|
552
|
-
<state line="
|
553
|
-
<folding />
|
554
|
-
</state>
|
589
|
+
<state line="34" column="0" selection-start="594" selection-end="594" vertical-scroll-proportion="0.32090762" />
|
555
590
|
</provider>
|
556
591
|
</entry>
|
557
|
-
<entry file="file://$
|
592
|
+
<entry file="file://$USER_HOME$/.rvm/gems/ruby-1.9.3-p194@zip_dsl/gems/rubyzip-0.9.8/lib/zip/zip_output_stream.rb">
|
558
593
|
<provider selected="true" editor-type-id="text-editor">
|
559
|
-
<state line="
|
594
|
+
<state line="64" column="0" selection-start="2015" selection-end="2015" vertical-scroll-proportion="0.32090762">
|
595
|
+
<folding />
|
596
|
+
</state>
|
560
597
|
</provider>
|
561
598
|
</entry>
|
562
|
-
<entry file="file://$
|
599
|
+
<entry file="file://$USER_HOME$/.rvm/gems/ruby-1.9.3-p194@zip_dsl/gems/file_utils-1.0.0/lib/file_utils/file_utils.rb">
|
563
600
|
<provider selected="true" editor-type-id="text-editor">
|
564
|
-
<state line="
|
601
|
+
<state line="16" column="0" selection-start="323" selection-end="323" vertical-scroll-proportion="0.0">
|
602
|
+
<folding />
|
603
|
+
</state>
|
565
604
|
</provider>
|
566
605
|
</entry>
|
567
|
-
<entry file="file://$PROJECT_DIR$/lib/zip_dsl/
|
606
|
+
<entry file="file://$PROJECT_DIR$/lib/zip_dsl/zip_writer.rb">
|
568
607
|
<provider selected="true" editor-type-id="text-editor">
|
569
|
-
<state line="
|
608
|
+
<state line="21" column="19" selection-start="418" selection-end="418" vertical-scroll-proportion="0.0">
|
609
|
+
<folding />
|
610
|
+
</state>
|
570
611
|
</provider>
|
571
612
|
</entry>
|
572
|
-
<entry file="file://$PROJECT_DIR$/
|
613
|
+
<entry file="file://$PROJECT_DIR$/lib/zip_dsl/zip_dsl.rb">
|
573
614
|
<provider selected="true" editor-type-id="text-editor">
|
574
|
-
<state line="
|
615
|
+
<state line="19" column="6" selection-start="440" selection-end="440" vertical-scroll-proportion="0.0">
|
616
|
+
<folding />
|
617
|
+
</state>
|
575
618
|
</provider>
|
576
619
|
</entry>
|
577
|
-
<entry file="file://$
|
620
|
+
<entry file="file://$USER_HOME$/.rvm/gems/ruby-1.9.3-p194@zip_dsl/gems/rspec-expectations-2.9.1/lib/rspec/matchers.rb">
|
578
621
|
<provider selected="true" editor-type-id="text-editor">
|
579
|
-
<state line="
|
622
|
+
<state line="194" column="0" selection-start="6592" selection-end="6592" vertical-scroll-proportion="0.33272728">
|
623
|
+
<folding />
|
624
|
+
</state>
|
580
625
|
</provider>
|
581
626
|
</entry>
|
582
|
-
<entry file="file://$
|
627
|
+
<entry file="file://$USER_HOME$/.rvm/gems/ruby-1.9.3-p194@zip_dsl/gems/meta_methods-1.0.1/lib/meta_methods/meta_methods.rb">
|
583
628
|
<provider selected="true" editor-type-id="text-editor">
|
584
|
-
<state line="
|
629
|
+
<state line="43" column="0" selection-start="1013" selection-end="1013" vertical-scroll-proportion="0.0">
|
585
630
|
<folding />
|
586
631
|
</state>
|
587
632
|
</provider>
|
588
633
|
</entry>
|
589
|
-
<entry file="file://$
|
634
|
+
<entry file="file://$USER_HOME$/.rvm/gems/ruby-1.9.3-p194@zip_dsl/gems/rspec-core-2.9.0/lib/rspec/core/subject.rb">
|
590
635
|
<provider selected="true" editor-type-id="text-editor">
|
591
|
-
<state line="
|
636
|
+
<state line="31" column="0" selection-start="1096" selection-end="1096" vertical-scroll-proportion="0.0">
|
592
637
|
<folding />
|
593
638
|
</state>
|
594
639
|
</provider>
|
595
640
|
</entry>
|
596
|
-
<entry file="file://$PROJECT_DIR$/
|
641
|
+
<entry file="file://$PROJECT_DIR$/spec/zip_builder_spec.rb">
|
597
642
|
<provider selected="true" editor-type-id="text-editor">
|
598
|
-
<state line="3" column="
|
643
|
+
<state line="3" column="17" selection-start="85" selection-end="85" vertical-scroll-proportion="0.08067227">
|
599
644
|
<folding />
|
600
645
|
</state>
|
601
646
|
</provider>
|
602
647
|
</entry>
|
603
|
-
<entry file="file://$PROJECT_DIR$/lib/
|
648
|
+
<entry file="file://$PROJECT_DIR$/lib/directory_builder.rb">
|
604
649
|
<provider selected="true" editor-type-id="text-editor">
|
605
|
-
<state line="
|
650
|
+
<state line="37" column="66" selection-start="738" selection-end="783" vertical-scroll-proportion="0.0">
|
606
651
|
<folding />
|
607
652
|
</state>
|
608
653
|
</provider>
|
609
654
|
</entry>
|
610
|
-
<entry file="file://$PROJECT_DIR$/
|
655
|
+
<entry file="file://$PROJECT_DIR$/spec/directory_builder_spec.rb">
|
611
656
|
<provider selected="true" editor-type-id="text-editor">
|
612
|
-
<state line="
|
657
|
+
<state line="77" column="54" selection-start="2099" selection-end="2099" vertical-scroll-proportion="0.0">
|
613
658
|
<folding />
|
614
659
|
</state>
|
615
660
|
</provider>
|
data/.idea/zip_dsl.iml
CHANGED
@@ -16,6 +16,7 @@
|
|
16
16
|
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v2.9.0, RVM: ruby-1.9.3-p194 [zip_dsl]) [gem]" level="application" />
|
17
17
|
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v2.9.1, RVM: ruby-1.9.3-p194 [zip_dsl]) [gem]" level="application" />
|
18
18
|
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v2.9.0, RVM: ruby-1.9.3-p194 [zip_dsl]) [gem]" level="application" />
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="zip (v2.0.2, RVM: ruby-1.9.3-p194 [zip_dsl]) [gem]" level="application" />
|
19
20
|
</component>
|
20
21
|
</module>
|
21
22
|
|
data/Gemfile
CHANGED
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'file_utils/file_utils'
|
2
|
+
require 'meta_methods'
|
3
|
+
|
4
|
+
class DirectoryBuilder
|
5
|
+
include FileUtils
|
6
|
+
include MetaMethods
|
7
|
+
|
8
|
+
def initialize name, basedir
|
9
|
+
@name = name
|
10
|
+
@basedir = File.expand_path(basedir)
|
11
|
+
end
|
12
|
+
|
13
|
+
def build(name=nil, &execute_block)
|
14
|
+
name = name.nil? ? @name : name
|
15
|
+
|
16
|
+
evaluate_dsl(self, nil, execute_block)
|
17
|
+
end
|
18
|
+
|
19
|
+
def entry_exist? entry_name
|
20
|
+
File.exist? full_name("#@name/#{entry_name}")
|
21
|
+
end
|
22
|
+
|
23
|
+
def entries_size
|
24
|
+
list = Dir.glob("#{full_name(@name)}/**/*")
|
25
|
+
|
26
|
+
cnt = 0
|
27
|
+
list.each do |name|
|
28
|
+
cnt += 1 if File.file?(name)
|
29
|
+
end
|
30
|
+
|
31
|
+
cnt
|
32
|
+
end
|
33
|
+
|
34
|
+
def list dir="."
|
35
|
+
list = pattern_to_files full_name("#@name/#{dir}"), "**/*"
|
36
|
+
|
37
|
+
list.each_with_index do |name, index|
|
38
|
+
list[index] = name[full_name("#@name/#{dir}").length+1..-1]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def file params
|
43
|
+
to_dir = to_dir(params[:name], params[:to_dir])
|
44
|
+
|
45
|
+
create_directory full_name(to_dir)
|
46
|
+
|
47
|
+
write_to_file full_name(params[:name]), full_name("#{to_dir}/#{File.basename(params[:name])}")
|
48
|
+
end
|
49
|
+
|
50
|
+
def content params
|
51
|
+
source = params[:source]
|
52
|
+
|
53
|
+
stream = source.kind_of?(String) ? StringIO.new(source) : source
|
54
|
+
content = stream.read
|
55
|
+
|
56
|
+
to_dir = to_dir(params[:name], params[:to_dir])
|
57
|
+
|
58
|
+
create_directory full_name(to_dir)
|
59
|
+
|
60
|
+
write_content_to_file content, full_name("#{to_dir}/#{File.basename(params[:name])}")
|
61
|
+
end
|
62
|
+
|
63
|
+
def directory params
|
64
|
+
if params[:from_dir].nil?
|
65
|
+
create_empty_directory params[:to_dir]
|
66
|
+
else
|
67
|
+
if params[:to_dir] == "." || params[:to_dir].nil?
|
68
|
+
to_dir = "#@name"
|
69
|
+
else
|
70
|
+
to_dir = "#@name/#{params[:to_dir]}"
|
71
|
+
end
|
72
|
+
|
73
|
+
filter = params[:filter].nil? ? "**/*" : params[:filter]
|
74
|
+
|
75
|
+
copy_files full_name(params[:from_dir]), full_name(to_dir), filter
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def to_dir name, dir
|
82
|
+
if dir.nil?
|
83
|
+
from_dir = File.dirname(name)
|
84
|
+
(from_dir == ".") ? @name : "#@name/#{from_dir}"
|
85
|
+
else
|
86
|
+
(dir == ".") ? @name : "#@name/#{dir}"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def create_empty_directory dir
|
91
|
+
to_dir = (dir == ".") ? @name : "#@name/#{dir}"
|
92
|
+
|
93
|
+
create_directory full_name(to_dir)
|
94
|
+
end
|
95
|
+
|
96
|
+
def full_name? name
|
97
|
+
File.expand_path(name) == name
|
98
|
+
end
|
99
|
+
|
100
|
+
def full_name name
|
101
|
+
full_name?(name) ? name : "#@basedir/#{name}"
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'meta_methods'
|
2
|
+
|
3
|
+
class Zip::DSL
|
4
|
+
include MetaMethods
|
5
|
+
|
6
|
+
def initialize name, basedir
|
7
|
+
@name = File.expand_path(name)
|
8
|
+
@basedir = File.expand_path(basedir)
|
9
|
+
end
|
10
|
+
|
11
|
+
def build(name=nil, &execute_block)
|
12
|
+
name = name.nil? ? @name : name
|
13
|
+
|
14
|
+
create_block = lambda { Zip::Writer.new(name, @basedir) }
|
15
|
+
destroy_block = lambda {|writer| writer.close }
|
16
|
+
|
17
|
+
evaluate_dsl(create_block, destroy_block, execute_block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def entry_exist? entry_name
|
21
|
+
create_block = lambda { Zip::Reader.new(@name) }
|
22
|
+
destroy_block = lambda {|reader| reader.close }
|
23
|
+
execute_block = lambda { |reader| reader.entry_exist?(entry_name) }
|
24
|
+
|
25
|
+
evaluate_dsl(create_block, destroy_block, execute_block)
|
26
|
+
end
|
27
|
+
|
28
|
+
def entries_size
|
29
|
+
create_block = lambda { Zip::Reader.new(@name) }
|
30
|
+
destroy_block = lambda {|reader| reader.close }
|
31
|
+
execute_block = lambda { |reader| reader.entries_size }
|
32
|
+
|
33
|
+
evaluate_dsl(create_block, destroy_block, execute_block)
|
34
|
+
end
|
35
|
+
|
36
|
+
def list dir="."
|
37
|
+
create_block = lambda { Zip::Reader.new(@name) }
|
38
|
+
destroy_block = lambda {|reader| reader.close }
|
39
|
+
execute_block = lambda { |reader| reader.list(dir) }
|
40
|
+
|
41
|
+
evaluate_dsl(create_block, destroy_block, execute_block)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'zip/zip'
|
2
|
+
|
3
|
+
class Zip::Reader
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
def initialize name
|
7
|
+
@zis = Zip::ZipInputStream.new(name)
|
8
|
+
end
|
9
|
+
|
10
|
+
def each(&block)
|
11
|
+
@zis.rewind
|
12
|
+
|
13
|
+
while (entry = @zis.get_next_entry)
|
14
|
+
block.call(entry)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def close
|
19
|
+
@zis.close
|
20
|
+
end
|
21
|
+
|
22
|
+
def entry_exist? entry_name
|
23
|
+
found = false
|
24
|
+
|
25
|
+
self.each do |entry|
|
26
|
+
if (entry.name == "./#{entry_name}") ||
|
27
|
+
(entry.name == entry_name) ||
|
28
|
+
!!(entry.name =~ /^#{entry_name}/)
|
29
|
+
found = true
|
30
|
+
break
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
found
|
35
|
+
end
|
36
|
+
|
37
|
+
def entries_size
|
38
|
+
cnt = 0
|
39
|
+
|
40
|
+
self.each { |_| cnt +=1 }
|
41
|
+
|
42
|
+
cnt
|
43
|
+
end
|
44
|
+
|
45
|
+
def list dir="."
|
46
|
+
entries = []
|
47
|
+
|
48
|
+
self.each do |entry|
|
49
|
+
if entry.name =~ /#{dir}/
|
50
|
+
name = (entry.name[0..1] == './') ? entry.name[2..-1] : entry.name
|
51
|
+
|
52
|
+
entries << name
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
entries
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def dir_entry? entry
|
62
|
+
(%r{\/$} =~ entry.name)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'zip/zip'
|
2
|
+
|
3
|
+
class Zip::Writer
|
4
|
+
|
5
|
+
def initialize file_name, basedir
|
6
|
+
@zos = Zip::ZipOutputStream.new(file_name)
|
7
|
+
@basedir = basedir
|
8
|
+
|
9
|
+
@compression_level = Zlib::BEST_COMPRESSION
|
10
|
+
end
|
11
|
+
|
12
|
+
def close
|
13
|
+
@zos.close
|
14
|
+
end
|
15
|
+
|
16
|
+
def file params
|
17
|
+
to_dir = params[:to_dir].nil? ? File.dirname(params[:name]) : strip_dot(params[:to_dir])
|
18
|
+
|
19
|
+
add_file full_name(params[:name]), to_dir
|
20
|
+
end
|
21
|
+
|
22
|
+
def content params
|
23
|
+
to_dir = params[:to_dir].nil? ? File.dirname(params[:name]) : params[:to_dir]
|
24
|
+
|
25
|
+
add params[:name], to_dir, params[:source]
|
26
|
+
end
|
27
|
+
|
28
|
+
def directory params
|
29
|
+
if params[:from_dir].nil?
|
30
|
+
add_empty_directory params[:to_dir]
|
31
|
+
else
|
32
|
+
if params[:to_dir].nil?
|
33
|
+
to_dir = params[:from_dir]
|
34
|
+
else
|
35
|
+
to_dir = params[:to_dir]
|
36
|
+
end
|
37
|
+
|
38
|
+
filter = params[:filter].nil? ? "**/*" : params[:filter]
|
39
|
+
|
40
|
+
add_directory params[:from_dir], to_dir, filter
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def add_file name, to_dir = nil
|
47
|
+
add name, to_dir, File.open(name)
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_directory from_dir, to_dir, filter="**/*"
|
51
|
+
patterns = filter.kind_of?(String) ? [filter] : filter
|
52
|
+
|
53
|
+
patterns.each do |pattern|
|
54
|
+
files = pattern_to_files full_name(from_dir), pattern
|
55
|
+
|
56
|
+
files.each do |file_name|
|
57
|
+
suffix = File.dirname(file_name)["#@basedir/#{from_dir}".size+1..-1]
|
58
|
+
dir = suffix.nil? ? to_dir : "#{to_dir}/#{suffix}"
|
59
|
+
|
60
|
+
if File.file?(file_name)
|
61
|
+
add_file file_name, dir
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def pattern_to_files dir, pattern
|
68
|
+
Dir.glob("#{dir}/#{pattern}")
|
69
|
+
end
|
70
|
+
|
71
|
+
def add_empty_directory(name)
|
72
|
+
entry = Zip::ZipStreamableDirectory.new "", "#{name}/"
|
73
|
+
|
74
|
+
@zos.put_next_entry entry
|
75
|
+
end
|
76
|
+
|
77
|
+
def add name, to_dir, source
|
78
|
+
create_new_entry("#{to_dir}/#{File.basename(name)}", source)
|
79
|
+
end
|
80
|
+
|
81
|
+
def create_new_entry(name, source)
|
82
|
+
stream = source.kind_of?(String) ? StringIO.new(source) : source
|
83
|
+
content = stream.read
|
84
|
+
|
85
|
+
entry = Zip::ZipEntry.new("", name)
|
86
|
+
|
87
|
+
@zos.put_next_entry entry, @compression_level
|
88
|
+
|
89
|
+
@zos.write content
|
90
|
+
end
|
91
|
+
|
92
|
+
def strip_dot name
|
93
|
+
if name[name.length-2..-1] == "/."
|
94
|
+
name = name[0..name.length-3]
|
95
|
+
end
|
96
|
+
|
97
|
+
name
|
98
|
+
end
|
99
|
+
|
100
|
+
def full_name? name
|
101
|
+
File.expand_path(name) == name
|
102
|
+
end
|
103
|
+
|
104
|
+
def full_name name
|
105
|
+
full_name?(name) ? name : "#@basedir/#{name}"
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'zip/zip'
|
2
|
+
|
3
|
+
class Zip::Reader
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
def initialize name
|
7
|
+
@zis = Zip::ZipInputStream.new(name)
|
8
|
+
end
|
9
|
+
|
10
|
+
def each(&block)
|
11
|
+
@zis.rewind
|
12
|
+
|
13
|
+
while (entry = @zis.get_next_entry)
|
14
|
+
block.call(entry)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def close
|
19
|
+
@zis.close
|
20
|
+
end
|
21
|
+
|
22
|
+
def entry_exist? entry_name
|
23
|
+
found = false
|
24
|
+
|
25
|
+
self.each do |entry|
|
26
|
+
if (entry.name == "./#{entry_name}") ||
|
27
|
+
(entry.name == entry_name) ||
|
28
|
+
!!(entry.name =~ /^#{entry_name}/)
|
29
|
+
found = true
|
30
|
+
break
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
found
|
35
|
+
end
|
36
|
+
|
37
|
+
def entries_size
|
38
|
+
cnt = 0
|
39
|
+
|
40
|
+
self.each { |_| cnt +=1 }
|
41
|
+
|
42
|
+
cnt
|
43
|
+
end
|
44
|
+
|
45
|
+
def list dir="."
|
46
|
+
entries = []
|
47
|
+
|
48
|
+
self.each do |entry|
|
49
|
+
if entry.name =~ /#{dir}/
|
50
|
+
name = (entry.name[0..1] == './') ? entry.name[2..-1] : entry.name
|
51
|
+
|
52
|
+
entries << name
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
entries
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def dir_entry? entry
|
62
|
+
(%r{\/$} =~ entry.name)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'zip/zip'
|
2
|
+
|
3
|
+
class Zip::Writer
|
4
|
+
|
5
|
+
def initialize file_name, basedir
|
6
|
+
@zos = Zip::ZipOutputStream.new(file_name)
|
7
|
+
@basedir = basedir
|
8
|
+
|
9
|
+
@compression_level = Zlib::BEST_COMPRESSION
|
10
|
+
end
|
11
|
+
|
12
|
+
def close
|
13
|
+
@zos.close
|
14
|
+
end
|
15
|
+
|
16
|
+
def file params
|
17
|
+
to_dir = params[:to_dir].nil? ? File.dirname(params[:name]) : strip_dot(params[:to_dir])
|
18
|
+
|
19
|
+
add_file full_name(params[:name]), to_dir
|
20
|
+
end
|
21
|
+
|
22
|
+
def content params
|
23
|
+
to_dir = params[:to_dir].nil? ? File.dirname(params[:name]) : params[:to_dir]
|
24
|
+
|
25
|
+
add params[:name], to_dir, params[:source]
|
26
|
+
end
|
27
|
+
|
28
|
+
def directory params
|
29
|
+
if params[:from_dir].nil?
|
30
|
+
add_empty_directory params[:to_dir]
|
31
|
+
else
|
32
|
+
if params[:to_dir].nil?
|
33
|
+
to_dir = params[:from_dir]
|
34
|
+
else
|
35
|
+
to_dir = params[:to_dir]
|
36
|
+
end
|
37
|
+
|
38
|
+
filter = params[:filter].nil? ? "**/*" : params[:filter]
|
39
|
+
|
40
|
+
add_directory params[:from_dir], to_dir, filter
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def add_file name, to_dir = nil
|
47
|
+
add name, to_dir, File.open(name)
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_directory from_dir, to_dir, filter="**/*"
|
51
|
+
patterns = filter.kind_of?(String) ? [filter] : filter
|
52
|
+
|
53
|
+
patterns.each do |pattern|
|
54
|
+
files = pattern_to_files full_name(from_dir), pattern
|
55
|
+
|
56
|
+
files.each do |file_name|
|
57
|
+
suffix = File.dirname(file_name)["#@basedir/#{from_dir}".size+1..-1]
|
58
|
+
dir = suffix.nil? ? to_dir : "#{to_dir}/#{suffix}"
|
59
|
+
|
60
|
+
if File.file?(file_name)
|
61
|
+
add_file file_name, dir
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def pattern_to_files dir, pattern
|
68
|
+
Dir.glob("#{dir}/#{pattern}")
|
69
|
+
end
|
70
|
+
|
71
|
+
def add_empty_directory(name)
|
72
|
+
entry = Zip::ZipStreamableDirectory.new "", "#{name}/"
|
73
|
+
|
74
|
+
@zos.put_next_entry entry
|
75
|
+
end
|
76
|
+
|
77
|
+
def add name, to_dir, source
|
78
|
+
create_new_entry("#{to_dir}/#{File.basename(name)}", source)
|
79
|
+
end
|
80
|
+
|
81
|
+
def create_new_entry(name, source)
|
82
|
+
stream = source.kind_of?(String) ? StringIO.new(source) : source
|
83
|
+
content = stream.read
|
84
|
+
|
85
|
+
entry = Zip::ZipEntry.new("", name)
|
86
|
+
|
87
|
+
@zos.put_next_entry entry, @compression_level
|
88
|
+
|
89
|
+
@zos.write content
|
90
|
+
end
|
91
|
+
|
92
|
+
def strip_dot name
|
93
|
+
if name[name.length-2..-1] == "/."
|
94
|
+
name = name[0..name.length-3]
|
95
|
+
end
|
96
|
+
|
97
|
+
name
|
98
|
+
end
|
99
|
+
|
100
|
+
def full_name? name
|
101
|
+
File.expand_path(name) == name
|
102
|
+
end
|
103
|
+
|
104
|
+
def full_name name
|
105
|
+
full_name?(name) ? name : "#@basedir/#{name}"
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
data/lib/directory_builder.rb
CHANGED
@@ -5,24 +5,23 @@ class DirectoryBuilder
|
|
5
5
|
include FileUtils
|
6
6
|
include MetaMethods
|
7
7
|
|
8
|
-
def initialize name
|
8
|
+
def initialize name, basedir
|
9
9
|
@name = name
|
10
|
+
@basedir = File.expand_path(basedir)
|
10
11
|
end
|
11
12
|
|
12
13
|
def build(name=nil, &execute_block)
|
13
14
|
name = name.nil? ? @name : name
|
14
15
|
|
15
|
-
name = name.nil? ? @name : name
|
16
|
-
|
17
16
|
evaluate_dsl(self, nil, execute_block)
|
18
17
|
end
|
19
18
|
|
20
19
|
def entry_exist? entry_name
|
21
|
-
File.exist? "#@name/#{entry_name}"
|
20
|
+
File.exist? full_name("#@name/#{entry_name}")
|
22
21
|
end
|
23
22
|
|
24
23
|
def entries_size
|
25
|
-
list = Dir.glob("
|
24
|
+
list = Dir.glob("#{full_name(@name)}/**/*")
|
26
25
|
|
27
26
|
cnt = 0
|
28
27
|
list.each do |name|
|
@@ -33,19 +32,19 @@ class DirectoryBuilder
|
|
33
32
|
end
|
34
33
|
|
35
34
|
def list dir="."
|
36
|
-
list = pattern_to_files "#@name/#{dir}", "**/*"
|
35
|
+
list = pattern_to_files full_name("#@name/#{dir}"), "**/*"
|
37
36
|
|
38
37
|
list.each_with_index do |name, index|
|
39
|
-
list[index] = name[
|
38
|
+
list[index] = name[full_name("#@name/#{dir}").length+1..-1]
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
43
42
|
def file params
|
44
43
|
to_dir = to_dir(params[:name], params[:to_dir])
|
45
44
|
|
46
|
-
create_directory to_dir
|
45
|
+
create_directory full_name(to_dir)
|
47
46
|
|
48
|
-
write_to_file params[:name], "#{to_dir}/#{File.basename(params[:name])}"
|
47
|
+
write_to_file full_name(params[:name]), full_name("#{to_dir}/#{File.basename(params[:name])}")
|
49
48
|
end
|
50
49
|
|
51
50
|
def content params
|
@@ -56,9 +55,9 @@ class DirectoryBuilder
|
|
56
55
|
|
57
56
|
to_dir = to_dir(params[:name], params[:to_dir])
|
58
57
|
|
59
|
-
create_directory to_dir
|
58
|
+
create_directory full_name(to_dir)
|
60
59
|
|
61
|
-
write_content_to_file content, "#{to_dir}/#{File.basename(params[:name])}"
|
60
|
+
write_content_to_file content, full_name("#{to_dir}/#{File.basename(params[:name])}")
|
62
61
|
end
|
63
62
|
|
64
63
|
def directory params
|
@@ -73,7 +72,7 @@ class DirectoryBuilder
|
|
73
72
|
|
74
73
|
filter = params[:filter].nil? ? "**/*" : params[:filter]
|
75
74
|
|
76
|
-
copy_files params[:from_dir], to_dir, filter
|
75
|
+
copy_files full_name(params[:from_dir]), full_name(to_dir), filter
|
77
76
|
end
|
78
77
|
end
|
79
78
|
|
@@ -91,7 +90,15 @@ class DirectoryBuilder
|
|
91
90
|
def create_empty_directory dir
|
92
91
|
to_dir = (dir == ".") ? @name : "#@name/#{dir}"
|
93
92
|
|
94
|
-
create_directory to_dir
|
93
|
+
create_directory full_name(to_dir)
|
94
|
+
end
|
95
|
+
|
96
|
+
def full_name? name
|
97
|
+
File.expand_path(name) == name
|
98
|
+
end
|
99
|
+
|
100
|
+
def full_name name
|
101
|
+
full_name?(name) ? name : "#@basedir/#{name}"
|
95
102
|
end
|
96
103
|
|
97
104
|
end
|
data/lib/zip_dsl/version.rb
CHANGED
data/lib/zip_dsl/zip_dsl.rb
CHANGED
@@ -6,22 +6,23 @@ require 'file_utils/file_utils'
|
|
6
6
|
describe DirectoryBuilder do
|
7
7
|
include FileUtils
|
8
8
|
|
9
|
-
|
9
|
+
let(:basedir) { File.expand_path("..") }
|
10
|
+
subject { DirectoryBuilder.new("build/test", "..") }
|
10
11
|
|
11
12
|
before do
|
12
|
-
delete_directory "build
|
13
|
+
delete_directory "#{basedir}/build"
|
13
14
|
end
|
14
15
|
|
15
16
|
it "should create new zip file with files at particular folder" do
|
16
17
|
subject.build do
|
17
18
|
file :name => "Gemfile"
|
18
|
-
file :name => "
|
19
|
-
file :name => "
|
19
|
+
file :name => "Rakefile", :to_dir => "my_config"
|
20
|
+
file :name => "spec/spec_helper.rb", :to_dir => "my_config"
|
20
21
|
end
|
21
22
|
|
22
23
|
subject.entry_exist?("Gemfile").should be_true
|
23
|
-
subject.entry_exist?("my_config/
|
24
|
-
subject.entry_exist?("my_config/
|
24
|
+
subject.entry_exist?("my_config/Rakefile").should be_true
|
25
|
+
subject.entry_exist?("my_config/spec_helper.rb").should be_true
|
25
26
|
|
26
27
|
subject.entries_size.should == 3
|
27
28
|
end
|
@@ -36,8 +37,9 @@ describe DirectoryBuilder do
|
|
36
37
|
end
|
37
38
|
|
38
39
|
it "should create new zip file with file created from file" do
|
40
|
+
src = File.open("#{basedir}/Rakefile")
|
39
41
|
subject.build do
|
40
|
-
content :name => "Rakefile", :source =>
|
42
|
+
content :name => "Rakefile", :source => src
|
41
43
|
end
|
42
44
|
|
43
45
|
subject.entry_exist?("Rakefile").should be_true
|
@@ -60,20 +62,20 @@ describe DirectoryBuilder do
|
|
60
62
|
subject.entry_exist?("my_config").should be_true
|
61
63
|
end
|
62
64
|
|
63
|
-
it "should display files in
|
65
|
+
it "should display files in current directory" do
|
64
66
|
subject.build do
|
65
|
-
directory :from_dir => "
|
67
|
+
directory :from_dir => "spec"
|
66
68
|
end
|
67
69
|
|
68
|
-
subject.list.
|
70
|
+
subject.list.should include "spec_helper.rb"
|
69
71
|
end
|
70
72
|
|
71
73
|
it "should display files in specified subdirectory" do
|
72
74
|
subject.build do
|
73
|
-
directory :from_dir => "
|
75
|
+
directory :from_dir => "lib"
|
74
76
|
end
|
75
77
|
|
76
|
-
subject.list("
|
78
|
+
subject.list("zip_dsl").first.should =~ %r{version.rb}
|
77
79
|
end
|
78
80
|
|
79
81
|
end
|
data/spec/zip_builder_spec.rb
CHANGED
data/zip_dsl.gemspec
CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.version = ZipDSL::VERSION
|
17
17
|
|
18
18
|
spec.add_runtime_dependency "meta_methods", [">= 0"]
|
19
|
+
spec.add_runtime_dependency "zip", [">= 0"]
|
19
20
|
spec.add_runtime_dependency "rubyzip", ["= 0.9.8"]
|
20
21
|
spec.add_runtime_dependency "file_utils", [">= 0"]
|
21
22
|
spec.add_development_dependency "gemspec_deps_gen", [">= 0"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zip_dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: zip
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: rubyzip
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -113,6 +129,15 @@ files:
|
|
113
129
|
- LICENSE
|
114
130
|
- README.md
|
115
131
|
- Rakefile
|
132
|
+
- build/test/directory_builder.rb
|
133
|
+
- build/test/version.rb
|
134
|
+
- build/test/zip_dsl.rb
|
135
|
+
- build/test/zip_dsl/version.rb
|
136
|
+
- build/test/zip_dsl/zip_dsl.rb
|
137
|
+
- build/test/zip_dsl/zip_reader.rb
|
138
|
+
- build/test/zip_dsl/zip_writer.rb
|
139
|
+
- build/test/zip_reader.rb
|
140
|
+
- build/test/zip_writer.rb
|
116
141
|
- lib/directory_builder.rb
|
117
142
|
- lib/zip_dsl.rb
|
118
143
|
- lib/zip_dsl/version.rb
|