sprout 1.0.32.pre → 1.0.35.pre
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sprout might be problematic. Click here for more details.
- data/Gemfile +2 -1
- data/Gemfile.lock +4 -2
- data/README.textile +12 -13
- data/VERSION +1 -0
- data/doc/Dir.html +288 -0
- data/doc/Rake/Task.html +184 -0
- data/doc/Sprout.html +144 -0
- data/doc/Sprout/ArchiveUnpacker.html +1246 -0
- data/doc/Sprout/Base.html +126 -0
- data/doc/Sprout/Base/ClassMethods.html +434 -0
- data/doc/Sprout/Concern.html +353 -0
- data/doc/Sprout/Daemon.html +166 -0
- data/doc/Sprout/Daemon/ClassMethods.html +244 -0
- data/doc/Sprout/Daemon/InstanceMethods.html +601 -0
- data/doc/Sprout/Errors.html +101 -0
- data/doc/Sprout/Errors/ArchiveUnpackerError.html +125 -0
- data/doc/Sprout/Errors/DestinationExistsError.html +133 -0
- data/doc/Sprout/Errors/DuplicateMemberError.html +132 -0
- data/doc/Sprout/Errors/ExecutableError.html +125 -0
- data/doc/Sprout/Errors/ExecutableRegistrationError.html +132 -0
- data/doc/Sprout/Errors/ExecutionError.html +121 -0
- data/doc/Sprout/Errors/GeneratorError.html +125 -0
- data/doc/Sprout/Errors/InvalidArgumentError.html +132 -0
- data/doc/Sprout/Errors/LoadError.html +121 -0
- data/doc/Sprout/Errors/MissingArgumentError.html +132 -0
- data/doc/Sprout/Errors/MissingExecutableError.html +132 -0
- data/doc/Sprout/Errors/MissingGeneratorError.html +132 -0
- data/doc/Sprout/Errors/MissingTemplateError.html +132 -0
- data/doc/Sprout/Errors/ProcessRunnerError.html +121 -0
- data/doc/Sprout/Errors/RemoteFileLoaderError.html +110 -0
- data/doc/Sprout/Errors/SproutError.html +114 -0
- data/doc/Sprout/Errors/UnknownArchiveType.html +122 -0
- data/doc/Sprout/Errors/UsageError.html +121 -0
- data/doc/Sprout/Errors/ValidationError.html +121 -0
- data/doc/Sprout/Errors/VersionRequirementNotMetError.html +121 -0
- data/doc/Sprout/Executable.html +173 -0
- data/doc/Sprout/Executable/Boolean.html +483 -0
- data/doc/Sprout/Executable/ClassMethods.html +417 -0
- data/doc/Sprout/Executable/CollectionParam.html +483 -0
- data/doc/Sprout/Executable/FileParam.html +484 -0
- data/doc/Sprout/Executable/Files.html +292 -0
- data/doc/Sprout/Executable/InstanceMethods.html +2006 -0
- data/doc/Sprout/Executable/Number.html +141 -0
- data/doc/Sprout/Executable/Param.html +2818 -0
- data/doc/Sprout/Executable/ParameterFactory.html +232 -0
- data/doc/Sprout/Executable/Path.html +223 -0
- data/doc/Sprout/Executable/Paths.html +253 -0
- data/doc/Sprout/Executable/StringParam.html +213 -0
- data/doc/Sprout/Executable/Strings.html +167 -0
- data/doc/Sprout/Executable/Url.html +160 -0
- data/doc/Sprout/Executable/Urls.html +170 -0
- data/doc/Sprout/FileTarget.html +1109 -0
- data/doc/Sprout/Generator.html +689 -0
- data/doc/Sprout/Generator/Base.html +1626 -0
- data/doc/Sprout/Generator/Command.html +690 -0
- data/doc/Sprout/Generator/DirectoryManifest.html +476 -0
- data/doc/Sprout/Generator/FileManifest.html +572 -0
- data/doc/Sprout/Generator/Manifest.html +377 -0
- data/doc/Sprout/Generator/TemplateManifest.html +196 -0
- data/doc/Sprout/GeneratorGenerator.html +1018 -0
- data/doc/Sprout/Library.html +1141 -0
- data/doc/Sprout/LibraryGenerator.html +309 -0
- data/doc/Sprout/Log.html +496 -0
- data/doc/Sprout/MXMLC.html +6373 -0
- data/doc/Sprout/Platform.html +714 -0
- data/doc/Sprout/ProcessRunner.html +1352 -0
- data/doc/Sprout/ProgressBar.html +376 -0
- data/doc/Sprout/ProgressBarImpl.html +2119 -0
- data/doc/Sprout/ProgressBarManager.html +434 -0
- data/doc/Sprout/ProgressBarOutputStream.html +416 -0
- data/doc/Sprout/RDocParser.html +211 -0
- data/doc/Sprout/RemoteFileLoader.html +172 -0
- data/doc/Sprout/RemoteFileTarget.html +679 -0
- data/doc/Sprout/ReversedProgressBar.html +194 -0
- data/doc/Sprout/RubyFeature.html +155 -0
- data/doc/Sprout/RubyFeature/ClassMethods.html +1065 -0
- data/doc/Sprout/RubyGenerator.html +764 -0
- data/doc/Sprout/Specification.html +767 -0
- data/doc/Sprout/System.html +191 -0
- data/doc/Sprout/System/BaseSystem.html +1455 -0
- data/doc/Sprout/System/JavaSystem.html +122 -0
- data/doc/Sprout/System/OSXSystem.html +335 -0
- data/doc/Sprout/System/ThreadMock.html +193 -0
- data/doc/Sprout/System/UnixSystem.html +584 -0
- data/doc/Sprout/System/VistaSystem.html +251 -0
- data/doc/Sprout/System/WinNixSystem.html +325 -0
- data/doc/Sprout/System/WinSystem.html +571 -0
- data/doc/Sprout/ToolGenerator.html +931 -0
- data/doc/Sprout/VERSION.html +128 -0
- data/doc/SproutTestCase.html +1412 -0
- data/doc/String.html +286 -0
- data/doc/_index.html +1035 -0
- data/doc/class_list.html +36 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +53 -0
- data/doc/css/style.css +310 -0
- data/doc/file.README.html +96 -0
- data/doc/file.archive_unpacker.html +288 -0
- data/doc/file.base.html +208 -0
- data/doc/file.base_system.html +278 -0
- data/doc/file.boolean.html +135 -0
- data/doc/file.collection_param.html +139 -0
- data/doc/file.command.html +126 -0
- data/doc/file.concern.html +136 -0
- data/doc/file.daemon.html +309 -0
- data/doc/file.dir.html +76 -0
- data/doc/file.directory_manifest.html +122 -0
- data/doc/file.errors.html +147 -0
- data/doc/file.executable.html +638 -0
- data/doc/file.file_manifest.html +109 -0
- data/doc/file.file_param.html +120 -0
- data/doc/file.file_target.html +140 -0
- data/doc/file.files.html +85 -0
- data/doc/file.generator.html +296 -0
- data/doc/file.generator_class.html +72 -0
- data/doc/file.generator_generator.html +137 -0
- data/doc/file.generator_test.html +92 -0
- data/doc/file.generator_test_helper.html +67 -0
- data/doc/file.java_system.html +62 -0
- data/doc/file.library.html +291 -0
- data/doc/file.library_generator.html +74 -0
- data/doc/file.log.html +100 -0
- data/doc/file.manifest.html +67 -0
- data/doc/file.mxmlc.html +740 -0
- data/doc/file.number.html +67 -0
- data/doc/file.osx_system.html +79 -0
- data/doc/file.param.html +491 -0
- data/doc/file.parameter_factory.html +119 -0
- data/doc/file.path.html +81 -0
- data/doc/file.paths.html +80 -0
- data/doc/file.platform.html +124 -0
- data/doc/file.process_runner.html +224 -0
- data/doc/file.progress_bar.html +390 -0
- data/doc/file.rdoc_parser.html +145 -0
- data/doc/file.remote_file_loader.html +117 -0
- data/doc/file.remote_file_target.html +176 -0
- data/doc/file.ruby_base.html +64 -0
- data/doc/file.ruby_feature.html +244 -0
- data/doc/file.ruby_generator.html +118 -0
- data/doc/file.ruby_input.html +62 -0
- data/doc/file.ruby_test_case.html +78 -0
- data/doc/file.ruby_test_helper.html +61 -0
- data/doc/file.specification.html +248 -0
- data/doc/file.sprout.html +64 -0
- data/doc/file.sprout_test_case.html +280 -0
- data/doc/file.string.html +72 -0
- data/doc/file.string_param.html +76 -0
- data/doc/file.strings.html +71 -0
- data/doc/file.system.html +86 -0
- data/doc/file.template_manifest.html +67 -0
- data/doc/file.tool.html +92 -0
- data/doc/file.tool_generator.html +90 -0
- data/doc/file.unix_system.html +128 -0
- data/doc/file.url.html +71 -0
- data/doc/file.urls.html +70 -0
- data/doc/file.version.html +71 -0
- data/doc/file.vista_system.html +69 -0
- data/doc/file.win_nix_system.html +88 -0
- data/doc/file.win_system.html +129 -0
- data/doc/file_list.html +230 -0
- data/doc/frames.html +13 -0
- data/doc/index.html +96 -0
- data/doc/js/app.js +202 -0
- data/doc/js/full_list.js +149 -0
- data/doc/js/jquery.js +154 -0
- data/doc/method_list.html +3355 -0
- data/doc/top-level-namespace.html +192 -0
- data/lib/sprout/archive_unpacker.rb +203 -137
- data/lib/sprout/base.rb +38 -11
- data/lib/sprout/concern.rb +51 -0
- data/lib/sprout/daemon.rb +256 -0
- data/lib/sprout/executable.rb +40 -11
- data/lib/sprout/executable/boolean.rb +47 -1
- data/lib/sprout/executable/collection_param.rb +33 -1
- data/lib/sprout/executable/file_param.rb +16 -3
- data/lib/sprout/executable/files.rb +5 -0
- data/lib/sprout/executable/number.rb +5 -1
- data/lib/sprout/executable/param.rb +232 -16
- data/lib/sprout/executable/parameter_factory.rb +39 -1
- data/lib/sprout/executable/path.rb +7 -1
- data/lib/sprout/executable/paths.rb +6 -1
- data/lib/sprout/executable/string_param.rb +8 -1
- data/lib/sprout/executable/strings.rb +7 -1
- data/lib/sprout/executable/url.rb +8 -1
- data/lib/sprout/executable/urls.rb +7 -1
- data/lib/sprout/file_target.rb +11 -11
- data/lib/sprout/generator.rb +244 -0
- data/lib/sprout/generator/base.rb +0 -94
- data/lib/sprout/generators/generator/generator_generator.rb +35 -1
- data/lib/sprout/generators/generator/templates/generator_class.rb +3 -3
- data/lib/sprout/library.rb +75 -0
- data/lib/sprout/log.rb +11 -12
- data/lib/sprout/process_runner.rb +29 -9
- data/lib/sprout/remote_file_target.rb +20 -9
- data/lib/sprout/system/base_system.rb +11 -3
- data/lib/sprout/test/sprout_test_case.rb +1 -0
- data/lib/sprout/version.rb +7 -11
- data/rakefile.rb +7 -12
- data/script/add_param_handler.rb +43 -0
- data/sprout.gemspec +2 -3
- data/test/fixtures/executable/fdb.rb +764 -0
- data/test/fixtures/executable/flex3sdk_gem/fdb +60 -0
- data/test/fixtures/executable/mxmlc.rb +9 -11
- data/test/unit/daemon_test.rb +61 -0
- data/test/unit/process_runner_test.rb +21 -0
- data/test/unit/remote_file_target_test.rb +45 -11
- data/test/unit/sprout_test_helper.rb +1 -1
- metadata +210 -29
@@ -0,0 +1,288 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta name="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
<title>File: archive_unpacker</title>
|
7
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
|
8
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
9
|
+
|
10
|
+
<script type="text/javascript" charset="utf-8">
|
11
|
+
relpath = '';
|
12
|
+
if (relpath != '') relpath += '/';
|
13
|
+
</script>
|
14
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
15
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
16
|
+
|
17
|
+
</head>
|
18
|
+
<body>
|
19
|
+
<script type="text/javascript" charset="utf-8">
|
20
|
+
if (window.top.frames.main) document.body.className = 'frames';
|
21
|
+
</script>
|
22
|
+
|
23
|
+
<div id="header">
|
24
|
+
<div id="menu">
|
25
|
+
|
26
|
+
<a href="_index.html" title="Index">Index</a> »
|
27
|
+
<span class="title">File: archive_unpacker</span>
|
28
|
+
|
29
|
+
|
30
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
31
|
+
</div>
|
32
|
+
|
33
|
+
<div id="search">
|
34
|
+
<a id="class_list_link" href="#">Class List</a>
|
35
|
+
<a id="method_list_link" href="#">Method List</a>
|
36
|
+
<a id ="file_list_link" href="#">File List</a>
|
37
|
+
</div>
|
38
|
+
|
39
|
+
<div class="clear"></div>
|
40
|
+
</div>
|
41
|
+
|
42
|
+
<iframe id="search_frame"></iframe>
|
43
|
+
|
44
|
+
<div id="content"><div id='filecontents'>
|
45
|
+
<p>require ‘zip/zip’ require ‘sprout/version’ require ‘archive/tar/minitar’</p>
|
46
|
+
|
47
|
+
<p>## # Given a source, destination and archive type (or ability to infer it),
|
48
|
+
# unpack the provided archive. # # unpacker = Sprout::ArchiveUnpacker.new
|
49
|
+
# unpacker.unpack “Foo.zip”, “unpacked/” # class Sprout::ArchiveUnpacker</p>
|
50
|
+
|
51
|
+
<pre class="code"><span class='comment'>##
|
52
|
+
</span><span class='comment'># Unpack the provided +archive+ into the provided +destination+.
|
53
|
+
</span><span class='comment'>#
|
54
|
+
</span><span class='comment'># If a +type+ is not provided, a type will be inferred from the file name suffix.
|
55
|
+
</span><span class='comment'>#
|
56
|
+
</span><span class='comment'># @param archive [File] Path to the archive that will be unpacked (or copied)
|
57
|
+
</span><span class='comment'># @param destination [Path] Path to the folder where unpacked files should be placed (or copied).
|
58
|
+
</span><span class='comment'># @param type [Symbol] The type of the archive in cases where it can't be inferred
|
59
|
+
</span><span class='comment'># from the name. Acceptable values are: :zip, :tgz, :swc, :exe or :rb
|
60
|
+
</span><span class='comment'># @param clobber [Boolean] If the destination already contains the expected file(s),
|
61
|
+
</span><span class='comment'># the unpacker will not run unless +clobber+ is true.
|
62
|
+
</span><span class='comment'># @return [String] path to the unpacked files (usually same as destination).
|
63
|
+
</span><span class='comment'># @raise Sprout::Errors::UnknownArchiveType If the archive type cannot be inferred and a valid type is not provided.
|
64
|
+
</span><span class='kw'>def</span> <span class='id unpack'>unpack</span> <span class='id archive'>archive</span><span class='comma'>,</span> <span class='id destination'>destination</span><span class='comma'>,</span> <span class='id type'>type</span><span class='op'>=</span><span class='kw'>nil</span><span class='comma'>,</span> <span class='id clobber'>clobber</span><span class='op'>=</span><span class='kw'>nil</span>
|
65
|
+
<span class='kw'>return</span> <span class='id unpack_zip'>unpack_zip</span><span class='lparen'>(</span><span class='id archive'>archive</span><span class='comma'>,</span> <span class='id destination'>destination</span><span class='comma'>,</span> <span class='id clobber'>clobber</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id is_zip?'>is_zip?</span><span class='lparen'>(</span><span class='id archive'>archive</span><span class='comma'>,</span> <span class='id type'>type</span><span class='rparen'>)</span>
|
66
|
+
<span class='kw'>return</span> <span class='id unpack_tgz'>unpack_tgz</span><span class='lparen'>(</span><span class='id archive'>archive</span><span class='comma'>,</span> <span class='id destination'>destination</span><span class='comma'>,</span> <span class='id clobber'>clobber</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id is_tgz?'>is_tgz?</span><span class='lparen'>(</span><span class='id archive'>archive</span><span class='comma'>,</span> <span class='id type'>type</span><span class='rparen'>)</span>
|
67
|
+
|
68
|
+
<span class='comment'># This is definitely debatable, should we copy the file even if it's
|
69
|
+
</span> <span class='comment'># not an archive that we're about to unpack?
|
70
|
+
</span> <span class='comment'># If so, why would we only do this with some subset of file types?
|
71
|
+
</span> <span class='comment'># Opinions welcome here...
|
72
|
+
</span> <span class='kw'>return</span> <span class='id copy_file'>copy_file</span><span class='lparen'>(</span><span class='id archive'>archive</span><span class='comma'>,</span> <span class='id destination'>destination</span><span class='comma'>,</span> <span class='id clobber'>clobber</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id is_copyable?'>is_copyable?</span><span class='lparen'>(</span><span class='id archive'>archive</span><span class='rparen'>)</span>
|
73
|
+
|
74
|
+
<span class='id raise'>raise</span> <span class='const'>Sprout</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>UnknownArchiveType</span><span class='period'>.</span><span class='id new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unsupported or unknown archive type encountered with: </span><span class='embexpr_beg'>#{</span><span class='id archive'>archive</span><span class='rbrace'>}</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
75
|
+
<span class='kw'>end</span>
|
76
|
+
|
77
|
+
<span class='comment'>##
|
78
|
+
</span><span class='comment'># Unpack zip archives on any platform using whatever strategy is most
|
79
|
+
</span><span class='comment'># efficient and reliable.
|
80
|
+
</span><span class='comment'>#
|
81
|
+
</span><span class='comment'># @param archive [File] Path to the archive that will be unpacked.
|
82
|
+
</span><span class='comment'># @param destination [Path] Path to the folder where unpacked files should be placed.
|
83
|
+
</span><span class='comment'># @param clobber [Boolean] If the destination already contains the expected file(s),
|
84
|
+
</span><span class='comment'># the unpacker will not run unless +clobber+ is true.
|
85
|
+
</span><span class='comment'># @return [File] the file or directory that was created.
|
86
|
+
</span><span class='kw'>def</span> <span class='id unpack_zip'>unpack_zip</span> <span class='id archive'>archive</span><span class='comma'>,</span> <span class='id destination'>destination</span><span class='comma'>,</span> <span class='id clobber'>clobber</span><span class='op'>=</span><span class='kw'>nil</span>
|
87
|
+
<span class='id validate'>validate</span> <span class='id archive'>archive</span><span class='comma'>,</span> <span class='id destination'>destination</span>
|
88
|
+
|
89
|
+
<span class='comment'>##
|
90
|
+
</span> <span class='comment'># As it turns out, the Rubyzip library corrupts
|
91
|
+
</span> <span class='comment'># binary files (like the Flash Player) on OSX and is also
|
92
|
+
</span> <span class='comment'># horribly slow for large archives (like the ~120MB Flex SDK)
|
93
|
+
</span> <span class='comment'># on all platforms.
|
94
|
+
</span> <span class='kw'>if</span> <span class='id is_darwin?'>is_darwin?</span>
|
95
|
+
<span class='id unpack_zip_on_darwin'>unpack_zip_on_darwin</span> <span class='id archive'>archive</span><span class='comma'>,</span> <span class='id destination'>destination</span><span class='comma'>,</span> <span class='id clobber'>clobber</span>
|
96
|
+
<span class='kw'>else</span>
|
97
|
+
<span class='const'>Zip</span><span class='op'>::</span><span class='const'>ZipFile</span><span class='period'>.</span><span class='id open'>open</span> <span class='id archive'>archive</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id zipfile'>zipfile</span><span class='op'>|</span>
|
98
|
+
<span class='id zipfile'>zipfile</span><span class='period'>.</span><span class='id each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id entry'>entry</span><span class='op'>|</span>
|
99
|
+
<span class='kw'>next</span> <span class='kw'>if</span> <span class='id entry'>entry</span><span class='period'>.</span><span class='id name'>name</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>__MACOSX</span><span class='regexp_end'>/</span></span> <span class='kw'>or</span> <span class='id entry'>entry</span><span class='period'>.</span><span class='id name'>name</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>\.DS_Store</span><span class='regexp_end'>/</span></span>
|
100
|
+
<span class='id unpack_zip_entry'>unpack_zip_entry</span> <span class='id entry'>entry</span><span class='comma'>,</span> <span class='id destination'>destination</span><span class='comma'>,</span> <span class='id clobber'>clobber</span>
|
101
|
+
<span class='kw'>end</span>
|
102
|
+
<span class='kw'>end</span>
|
103
|
+
<span class='kw'>end</span>
|
104
|
+
<span class='kw'>end</span>
|
105
|
+
|
106
|
+
<span class='comment'>##
|
107
|
+
</span><span class='comment'># Return true if we're on a Darwin native system (OSX).
|
108
|
+
</span><span class='comment'># @return [Boolean]
|
109
|
+
</span><span class='kw'>def</span> <span class='id is_darwin?'>is_darwin?</span>
|
110
|
+
<span class='const'>Sprout</span><span class='period'>.</span><span class='id current_system'>current_system</span><span class='period'>.</span><span class='id is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Sprout</span><span class='op'>::</span><span class='const'>System</span><span class='op'>::</span><span class='const'>OSXSystem</span><span class='rparen'>)</span>
|
111
|
+
<span class='kw'>end</span>
|
112
|
+
|
113
|
+
<span class='comment'>##
|
114
|
+
</span><span class='comment'># Optimization for zip files on OSX. Uses the native
|
115
|
+
</span><span class='comment'># 'unzip' utility which is much faster (and more reliable)
|
116
|
+
</span><span class='comment'># than Ruby for large archives (like the Flex SDK) and
|
117
|
+
</span><span class='comment'># binaries that Ruby corrupts (like the Flash Player).
|
118
|
+
</span><span class='comment'>#
|
119
|
+
</span><span class='comment'># @return [File] the file or directory that was created.
|
120
|
+
</span><span class='kw'>def</span> <span class='id unpack_zip_on_darwin'>unpack_zip_on_darwin</span> <span class='id archive'>archive</span><span class='comma'>,</span> <span class='id destination'>destination</span><span class='comma'>,</span> <span class='id clobber'>clobber</span>
|
121
|
+
<span class='comment'># Unzipping on OS X
|
122
|
+
</span> <span class='const'>FileUtils</span><span class='period'>.</span><span class='id makedirs'>makedirs</span> <span class='id destination'>destination</span>
|
123
|
+
<span class='id zip_dir'>zip_dir</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id expand_path'>expand_path</span> <span class='const'>File</span><span class='period'>.</span><span class='id dirname'>dirname</span><span class='lparen'>(</span><span class='id archive'>archive</span><span class='rparen'>)</span>
|
124
|
+
<span class='id zip_name'>zip_name</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id basename'>basename</span> <span class='id archive'>archive</span>
|
125
|
+
<span class='id output'>output</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id expand_path'>expand_path</span> <span class='id destination'>destination</span>
|
126
|
+
<span class='comment'># puts ">> zip_dir: #{zip_dir} zip_name: #{zip_name} output: #{output}"
|
127
|
+
</span> <span class='backtick'>%x(</span><span class='tstring_content'>cd </span><span class='embexpr_beg'>#{</span><span class='id zip_dir'>zip_dir</span><span class='rbrace'>}</span><span class='tstring_content'>;unzip </span><span class='embexpr_beg'>#{</span><span class='id zip_name'>zip_name</span><span class='rbrace'>}</span><span class='tstring_content'> -d </span><span class='embexpr_beg'>#{</span><span class='id output'>output</span><span class='rbrace'>}</span><span class='tstring_end'>)</span></span>
|
128
|
+
<span class='kw'>end</span>
|
129
|
+
|
130
|
+
<span class='comment'>##
|
131
|
+
</span><span class='comment'># Unpack tar.gz or .tgz files on any platform.
|
132
|
+
</span><span class='comment'>#
|
133
|
+
</span><span class='comment'># @return [File] the file or directory that was created.
|
134
|
+
</span><span class='kw'>def</span> <span class='id unpack_tgz'>unpack_tgz</span> <span class='id archive'>archive</span><span class='comma'>,</span> <span class='id destination'>destination</span><span class='comma'>,</span> <span class='id clobber'>clobber</span><span class='op'>=</span><span class='kw'>nil</span>
|
135
|
+
<span class='id validate'>validate</span> <span class='id archive'>archive</span><span class='comma'>,</span> <span class='id destination'>destination</span>
|
136
|
+
|
137
|
+
<span class='id tar'>tar</span> <span class='op'>=</span> <span class='const'>Zlib</span><span class='op'>::</span><span class='const'>GzipReader</span><span class='period'>.</span><span class='id new'>new</span><span class='lparen'>(</span><span class='const'>File</span><span class='period'>.</span><span class='id open'>open</span><span class='lparen'>(</span><span class='id archive'>archive</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>rb</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
138
|
+
<span class='kw'>if</span><span class='lparen'>(</span><span class='op'>!</span><span class='id should_unpack_tgz?'>should_unpack_tgz?</span><span class='lparen'>(</span><span class='id destination'>destination</span><span class='comma'>,</span> <span class='id clobber'>clobber</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
139
|
+
<span class='id raise'>raise</span> <span class='const'>Sprout</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>DestinationExistsError</span><span class='period'>.</span><span class='id new'>new</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unable to unpack </span><span class='embexpr_beg'>#{</span><span class='id archive'>archive</span><span class='rbrace'>}</span><span class='tstring_content'> into </span><span class='embexpr_beg'>#{</span><span class='id destination'>destination</span><span class='rbrace'>}</span><span class='tstring_content'> without explicit :clobber argument</span><span class='tstring_end'>"</span></span>
|
140
|
+
<span class='kw'>end</span>
|
141
|
+
|
142
|
+
<span class='const'>Archive</span><span class='op'>::</span><span class='const'>Tar</span><span class='op'>::</span><span class='const'>Minitar</span><span class='period'>.</span><span class='id unpack'>unpack</span><span class='lparen'>(</span><span class='id tar'>tar</span><span class='comma'>,</span> <span class='id destination'>destination</span><span class='rparen'>)</span>
|
143
|
+
|
144
|
+
<span class='comment'># Recurse and unpack gzipped children (Adobe did this double
|
145
|
+
</span> <span class='comment'># gzip with the Linux FlashPlayer for some weird reason)
|
146
|
+
</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id destination'>destination</span><span class='rbrace'>}</span><span class='tstring_content'>/**/*.tgz</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id destination'>destination</span><span class='rbrace'>}</span><span class='tstring_content'>/**/*.tar.gz</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id pattern'>pattern</span><span class='op'>|</span>
|
147
|
+
<span class='const'>Dir</span><span class='period'>.</span><span class='id glob'>glob</span><span class='lparen'>(</span><span class='id pattern'>pattern</span><span class='rparen'>)</span><span class='period'>.</span><span class='id each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id child'>child</span><span class='op'>|</span>
|
148
|
+
<span class='kw'>if</span><span class='lparen'>(</span><span class='id child'>child</span> <span class='op'>!=</span> <span class='id archive'>archive</span> <span class='op'>&&</span> <span class='id dir'>dir</span> <span class='op'>!=</span> <span class='const'>File</span><span class='period'>.</span><span class='id dirname'>dirname</span><span class='lparen'>(</span><span class='id child'>child</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
149
|
+
<span class='id unpack_tgz'>unpack_tgz</span><span class='lparen'>(</span><span class='id child'>child</span><span class='comma'>,</span> <span class='const'>File</span><span class='period'>.</span><span class='id dirname'>dirname</span><span class='lparen'>(</span><span class='id child'>child</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
150
|
+
<span class='kw'>end</span>
|
151
|
+
<span class='kw'>end</span>
|
152
|
+
<span class='kw'>end</span>
|
153
|
+
<span class='kw'>end</span>
|
154
|
+
|
155
|
+
<span class='comment'>##
|
156
|
+
</span><span class='comment'># Rather than unpacking, safely copy the file from one location
|
157
|
+
</span><span class='comment'># to another.
|
158
|
+
</span><span class='comment'># This method is generally used when .exe files are downloaded
|
159
|
+
</span><span class='comment'># directly.
|
160
|
+
</span><span class='comment'>#
|
161
|
+
</span><span class='comment'># @return [File] the file or directory that was created.
|
162
|
+
</span><span class='kw'>def</span> <span class='id copy_file'>copy_file</span> <span class='id file'>file</span><span class='comma'>,</span> <span class='id destination'>destination</span><span class='comma'>,</span> <span class='id clobber'>clobber</span><span class='op'>=</span><span class='kw'>nil</span>
|
163
|
+
<span class='id validate'>validate</span> <span class='id file'>file</span><span class='comma'>,</span> <span class='id destination'>destination</span>
|
164
|
+
<span class='id target'>target</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id expand_path'>expand_path</span><span class='lparen'>(</span> <span class='const'>File</span><span class='period'>.</span><span class='id join'>join</span><span class='lparen'>(</span><span class='id destination'>destination</span><span class='comma'>,</span> <span class='const'>File</span><span class='period'>.</span><span class='id basename'>basename</span><span class='lparen'>(</span><span class='id file'>file</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='rparen'>)</span>
|
165
|
+
<span class='kw'>if</span><span class='lparen'>(</span><span class='const'>File</span><span class='period'>.</span><span class='id exists?'>exists?</span><span class='lparen'>(</span><span class='id target'>target</span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='id clobber'>clobber</span> <span class='op'>!=</span> <span class='symbol'>:clobber</span><span class='rparen'>)</span>
|
166
|
+
<span class='id raise'>raise</span> <span class='const'>Sprout</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>DestinationExistsError</span><span class='period'>.</span><span class='id new'>new</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Unable to copy </span><span class='embexpr_beg'>#{</span><span class='id file'>file</span><span class='rbrace'>}</span><span class='tstring_content'> to </span><span class='embexpr_beg'>#{</span><span class='id target'>target</span><span class='rbrace'>}</span><span class='tstring_content'> because target already exists and we were not asked to :clobber it</span><span class='tstring_end'>"</span></span>
|
167
|
+
<span class='kw'>end</span>
|
168
|
+
<span class='const'>FileUtils</span><span class='period'>.</span><span class='id mkdir_p'>mkdir_p</span> <span class='id destination'>destination</span>
|
169
|
+
<span class='const'>FileUtils</span><span class='period'>.</span><span class='id cp_r'>cp_r</span> <span class='id file'>file</span><span class='comma'>,</span> <span class='id destination'>destination</span>
|
170
|
+
|
171
|
+
<span class='id destination'>destination</span>
|
172
|
+
<span class='kw'>end</span>
|
173
|
+
|
174
|
+
<span class='comment'>##
|
175
|
+
</span><span class='comment'># Returns true if the provided file name looks like a zip file or the +type+ argument is +:zip+.
|
176
|
+
</span><span class='comment'># @return [Boolean]
|
177
|
+
</span><span class='kw'>def</span> <span class='id is_zip?'>is_zip?</span> <span class='id archive'>archive</span><span class='comma'>,</span> <span class='id type'>type</span><span class='op'>=</span><span class='kw'>nil</span>
|
178
|
+
<span class='id type'>type</span> <span class='op'>==</span> <span class='symbol'>:zip</span> <span class='op'>||</span> <span class='op'>!</span><span class='id archive'>archive</span><span class='period'>.</span><span class='id match'>match</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>\.zip$</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id nil?'>nil?</span>
|
179
|
+
<span class='kw'>end</span>
|
180
|
+
|
181
|
+
<span class='comment'>##
|
182
|
+
</span><span class='comment'># Return true if the provided file name looks like a tar.gz file or the +type+ argument is +:tgz+.
|
183
|
+
</span><span class='comment'># @return [Boolean]
|
184
|
+
</span><span class='kw'>def</span> <span class='id is_tgz?'>is_tgz?</span> <span class='id archive'>archive</span><span class='comma'>,</span> <span class='id type'>type</span><span class='op'>=</span><span class='kw'>nil</span>
|
185
|
+
<span class='id type'>type</span> <span class='op'>==</span> <span class='symbol'>:tgz</span> <span class='op'>||</span> <span class='op'>!</span><span class='id archive'>archive</span><span class='period'>.</span><span class='id match'>match</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>\.tgz$</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id nil?'>nil?</span> <span class='op'>||</span> <span class='op'>!</span><span class='id archive'>archive</span><span class='period'>.</span><span class='id match'>match</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>\.tar.gz$</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id nil?'>nil?</span>
|
186
|
+
<span class='kw'>end</span>
|
187
|
+
|
188
|
+
<span class='comment'>##
|
189
|
+
</span><span class='comment'># Return true if the downloaded archive is a .exe file or the +type+ argument is +:exe+.
|
190
|
+
</span><span class='comment'># @return [Boolean]
|
191
|
+
</span><span class='kw'>def</span> <span class='id is_exe?'>is_exe?</span> <span class='id archive'>archive</span><span class='comma'>,</span> <span class='id type'>type</span><span class='op'>=</span><span class='kw'>nil</span>
|
192
|
+
<span class='id type'>type</span> <span class='op'>==</span> <span class='symbol'>:exe</span> <span class='op'>||</span> <span class='op'>!</span><span class='id archive'>archive</span><span class='period'>.</span><span class='id match'>match</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>\.exe$</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id nil?'>nil?</span>
|
193
|
+
<span class='kw'>end</span>
|
194
|
+
|
195
|
+
<span class='comment'>##
|
196
|
+
</span><span class='comment'># Return true if the downloaded archive is a .swc file or the +type+ argument is +:swc+.
|
197
|
+
</span><span class='comment'># @return [Boolean]
|
198
|
+
</span><span class='kw'>def</span> <span class='id is_swc?'>is_swc?</span> <span class='id archive'>archive</span><span class='comma'>,</span> <span class='id type'>type</span><span class='op'>=</span><span class='kw'>nil</span>
|
199
|
+
<span class='id type'>type</span> <span class='op'>==</span> <span class='symbol'>:swc</span> <span class='op'>||</span> <span class='op'>!</span><span class='id archive'>archive</span><span class='period'>.</span><span class='id match'>match</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>\.swc$</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id nil?'>nil?</span>
|
200
|
+
<span class='kw'>end</span>
|
201
|
+
|
202
|
+
<span class='comment'>##
|
203
|
+
</span><span class='comment'># Return true if the downloaded archive is a .rb file or the +type+ argument is +:rb+.
|
204
|
+
</span><span class='comment'># @return [Boolean]
|
205
|
+
</span><span class='kw'>def</span> <span class='id is_rb?'>is_rb?</span> <span class='id archive'>archive</span><span class='comma'>,</span> <span class='id type'>type</span><span class='op'>=</span><span class='kw'>nil</span>
|
206
|
+
<span class='id type'>type</span> <span class='op'>==</span> <span class='symbol'>:rb</span> <span class='op'>||</span> <span class='op'>!</span><span class='id archive'>archive</span><span class='period'>.</span><span class='id match'>match</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>\.rb$</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id nil?'>nil?</span>
|
207
|
+
<span class='kw'>end</span>
|
208
|
+
|
209
|
+
<span class='id private'>private</span>
|
210
|
+
|
211
|
+
<span class='comment'>##
|
212
|
+
</span><span class='comment'># Return true if the provided archive should be copied as-is, rather
|
213
|
+
</span><span class='comment'># than being unpacked first.
|
214
|
+
</span><span class='comment'># @return [Boolean]
|
215
|
+
</span><span class='kw'>def</span> <span class='id is_copyable?'>is_copyable?</span> <span class='id archive'>archive</span>
|
216
|
+
<span class='lparen'>(</span><span class='id is_exe?'>is_exe?</span><span class='lparen'>(</span><span class='id archive'>archive</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='id is_swc?'>is_swc?</span><span class='lparen'>(</span><span class='id archive'>archive</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='id is_rb?'>is_rb?</span><span class='lparen'>(</span><span class='id archive'>archive</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
217
|
+
<span class='kw'>end</span>
|
218
|
+
|
219
|
+
<span class='comment'>##
|
220
|
+
</span><span class='comment'># Return true if the tgz should be unpacked.
|
221
|
+
</span><span class='comment'># @return [Boolean]
|
222
|
+
</span><span class='kw'>def</span> <span class='id should_unpack_tgz?'>should_unpack_tgz?</span> <span class='id dir'>dir</span><span class='comma'>,</span> <span class='id clobber'>clobber</span><span class='op'>=</span><span class='kw'>nil</span>
|
223
|
+
<span class='kw'>return</span> <span class='op'>!</span><span class='id directory_has_children?'>directory_has_children?</span><span class='lparen'>(</span><span class='id dir'>dir</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='id clobber'>clobber</span> <span class='op'>==</span> <span class='symbol'>:clobber</span>
|
224
|
+
|
225
|
+
<span class='kw'>end</span>
|
226
|
+
|
227
|
+
<span class='comment'>##
|
228
|
+
</span><span class='comment'># Return true if the provided directory has one or more chidren.
|
229
|
+
</span><span class='comment'># @return [Boolean]
|
230
|
+
</span><span class='kw'>def</span> <span class='id directory_has_children?'>directory_has_children?</span> <span class='id dir'>dir</span>
|
231
|
+
<span class='lparen'>(</span><span class='const'>Dir</span><span class='period'>.</span><span class='id entries'>entries</span><span class='lparen'>(</span><span class='id dir'>dir</span><span class='rparen'>)</span> <span class='op'>-</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>.</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>..</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='period'>.</span><span class='id size'>size</span> <span class='op'>></span> <span class='int'>0</span>
|
232
|
+
<span class='kw'>end</span>
|
233
|
+
|
234
|
+
<span class='comment'>##
|
235
|
+
</span><span class='comment'># @return [Boolean] true if the +archive+ and +destination+ exist.
|
236
|
+
</span><span class='comment'># @raise Sprout::Errors::ArchiveUnpackerError if the +archive+ or +destination+ don't exist.
|
237
|
+
</span><span class='kw'>def</span> <span class='id validate'>validate</span> <span class='id archive'>archive</span><span class='comma'>,</span> <span class='id destination'>destination</span>
|
238
|
+
<span class='id archive_message'>archive_message</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Archive could not be found at: </span><span class='embexpr_beg'>#{</span><span class='id archive'>archive</span><span class='rbrace'>}</span><span class='tstring_end'>"</span></span>
|
239
|
+
<span class='id raise'>raise</span> <span class='const'>Sprout</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>ArchiveUnpackerError</span><span class='period'>.</span><span class='id new'>new</span><span class='lparen'>(</span><span class='id archive_message'>archive_message</span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='id valid_path?'>valid_path?</span><span class='lparen'>(</span><span class='id archive'>archive</span><span class='rparen'>)</span>
|
240
|
+
<span class='id destination_message'>destination_message</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Destination could not be found at: </span><span class='embexpr_beg'>#{</span><span class='id destination'>destination</span><span class='rbrace'>}</span><span class='tstring_end'>"</span></span>
|
241
|
+
<span class='id raise'>raise</span> <span class='const'>Sprout</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>ArchiveUnpackerError</span><span class='period'>.</span><span class='id new'>new</span><span class='lparen'>(</span><span class='id destination_message'>destination_message</span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='id valid_path?'>valid_path?</span><span class='lparen'>(</span><span class='id destination'>destination</span><span class='rparen'>)</span>
|
242
|
+
<span class='kw'>true</span>
|
243
|
+
<span class='kw'>end</span>
|
244
|
+
|
245
|
+
<span class='comment'>##
|
246
|
+
</span><span class='comment'># @return [Boolean] true if the provided +path+ is not nil and exists on disk.
|
247
|
+
</span><span class='kw'>def</span> <span class='id valid_path?'>valid_path?</span> <span class='id path'>path</span>
|
248
|
+
<span class='op'>!</span><span class='id path'>path</span><span class='period'>.</span><span class='id nil?'>nil?</span> <span class='op'>&&</span> <span class='const'>File</span><span class='period'>.</span><span class='id exists?'>exists?</span><span class='lparen'>(</span><span class='id path'>path</span><span class='rparen'>)</span>
|
249
|
+
<span class='kw'>end</span>
|
250
|
+
|
251
|
+
<span class='comment'>##
|
252
|
+
</span><span class='comment'># Unpack an entry from a zip archive. This is an _inconvenience_ method
|
253
|
+
</span><span class='comment'># thanks to the way Ruby zip handles zip archives.
|
254
|
+
</span><span class='kw'>def</span> <span class='id unpack_zip_entry'>unpack_zip_entry</span> <span class='id entry'>entry</span><span class='comma'>,</span> <span class='id destination'>destination</span><span class='comma'>,</span> <span class='id clobber'>clobber</span>
|
255
|
+
<span class='comment'># Ensure hidden mac files don't get written to disk:
|
256
|
+
</span> <span class='id path'>path</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id join'>join</span> <span class='id destination'>destination</span><span class='comma'>,</span> <span class='id entry'>entry</span><span class='period'>.</span><span class='id name'>name</span>
|
257
|
+
|
258
|
+
<span class='kw'>if</span> <span class='id entry'>entry</span><span class='period'>.</span><span class='id directory?'>directory?</span>
|
259
|
+
<span class='comment'># If an archive has empty directories:
|
260
|
+
</span> <span class='const'>FileUtils</span><span class='period'>.</span><span class='id mkdir_p'>mkdir_p</span> <span class='id path'>path</span>
|
261
|
+
<span class='kw'>elsif</span> <span class='id entry'>entry</span><span class='period'>.</span><span class='id file?'>file?</span>
|
262
|
+
<span class='comment'># On Windows, we don't get the entry for
|
263
|
+
</span> <span class='comment'># each parent directory:
|
264
|
+
</span> <span class='const'>FileUtils</span><span class='period'>.</span><span class='id mkdir_p'>mkdir_p</span> <span class='const'>File</span><span class='period'>.</span><span class='id dirname'>dirname</span><span class='lparen'>(</span><span class='id path'>path</span><span class='rparen'>)</span>
|
265
|
+
<span class='kw'>begin</span>
|
266
|
+
<span class='id entry'>entry</span><span class='period'>.</span><span class='id extract'>extract</span> <span class='id path'>path</span>
|
267
|
+
<span class='kw'>rescue</span> <span class='const'>Zip</span><span class='op'>::</span><span class='const'>ZipDestinationFileExistsError</span> <span class='op'>=></span> <span class='id zip_dest_error'>zip_dest_error</span>
|
268
|
+
<span class='kw'>if</span><span class='lparen'>(</span><span class='id clobber'>clobber</span> <span class='op'>==</span> <span class='symbol'>:clobber</span><span class='rparen'>)</span>
|
269
|
+
<span class='const'>FileUtils</span><span class='period'>.</span><span class='id rm_rf'>rm_rf</span> <span class='id path'>path</span>
|
270
|
+
<span class='id entry'>entry</span><span class='period'>.</span><span class='id extract'>extract</span> <span class='id path'>path</span>
|
271
|
+
<span class='kw'>else</span>
|
272
|
+
<span class='id raise'>raise</span> <span class='const'>Sprout</span><span class='op'>::</span><span class='const'>Errors</span><span class='op'>::</span><span class='const'>DestinationExistsError</span><span class='period'>.</span><span class='id new'>new</span> <span class='id zip_dest_error'>zip_dest_error</span><span class='period'>.</span><span class='id message'>message</span>
|
273
|
+
<span class='kw'>end</span>
|
274
|
+
<span class='kw'>end</span>
|
275
|
+
<span class='kw'>end</span>
|
276
|
+
<span class='kw'>end</span></pre>
|
277
|
+
|
278
|
+
<p>end</p>
|
279
|
+
</div></div>
|
280
|
+
|
281
|
+
<div id="footer">
|
282
|
+
Generated on Wed Dec 22 11:58:31 2010 by
|
283
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
284
|
+
0.6.3 (ruby-1.9.2).
|
285
|
+
</div>
|
286
|
+
|
287
|
+
</body>
|
288
|
+
</html>
|
data/doc/file.base.html
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta name="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
<title>File: base</title>
|
7
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
|
8
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
9
|
+
|
10
|
+
<script type="text/javascript" charset="utf-8">
|
11
|
+
relpath = '';
|
12
|
+
if (relpath != '') relpath += '/';
|
13
|
+
</script>
|
14
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
15
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
16
|
+
|
17
|
+
</head>
|
18
|
+
<body>
|
19
|
+
<script type="text/javascript" charset="utf-8">
|
20
|
+
if (window.top.frames.main) document.body.className = 'frames';
|
21
|
+
</script>
|
22
|
+
|
23
|
+
<div id="header">
|
24
|
+
<div id="menu">
|
25
|
+
|
26
|
+
<a href="_index.html" title="Index">Index</a> »
|
27
|
+
<span class="title">File: base</span>
|
28
|
+
|
29
|
+
|
30
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
31
|
+
</div>
|
32
|
+
|
33
|
+
<div id="search">
|
34
|
+
<a id="class_list_link" href="#">Class List</a>
|
35
|
+
<a id="method_list_link" href="#">Method List</a>
|
36
|
+
<a id ="file_list_link" href="#">File List</a>
|
37
|
+
</div>
|
38
|
+
|
39
|
+
<div class="clear"></div>
|
40
|
+
</div>
|
41
|
+
|
42
|
+
<iframe id="search_frame"></iframe>
|
43
|
+
|
44
|
+
<div id="content"><div id='filecontents'>
|
45
|
+
<p>module Sprout</p>
|
46
|
+
|
47
|
+
<pre class="code"><span class='kw'>module</span> <span class='const'>Generator</span>
|
48
|
+
|
49
|
+
<span class='kw'>class</span> <span class='const'>Base</span>
|
50
|
+
<span class='id include'>include</span> <span class='const'>Sprout</span><span class='op'>::</span><span class='const'>Executable</span>
|
51
|
+
|
52
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id inherited'>inherited</span> <span class='id base'>base</span>
|
53
|
+
<span class='comment'># NOTE: We can NOT instantiate the class here,
|
54
|
+
</span> <span class='comment'># because only it's first line has been interpreted, if we
|
55
|
+
</span> <span class='comment'># instantiate here, none of the code declared in the class body will
|
56
|
+
</span> <span class='comment'># be associated with this instance.
|
57
|
+
</span> <span class='comment'>#
|
58
|
+
</span> <span class='comment'># Go ahead and register the class and update instances afterwards.
|
59
|
+
</span> <span class='const'>Sprout</span><span class='op'>::</span><span class='const'>Generator</span><span class='period'>.</span><span class='id register'>register</span> <span class='id base'>base</span><span class='comma'>,</span> <span class='id template_from_caller'>template_from_caller</span><span class='lparen'>(</span><span class='id caller'>caller</span><span class='period'>.</span><span class='id first'>first</span><span class='rparen'>)</span>
|
60
|
+
<span class='kw'>end</span>
|
61
|
+
|
62
|
+
<span class='comment'>##
|
63
|
+
</span> <span class='comment'># The directory where files will be created.
|
64
|
+
</span> <span class='id add_param'>add_param</span> <span class='symbol'>:path</span><span class='comma'>,</span> <span class='const'>Path</span><span class='comma'>,</span> <span class='lbrace'>{</span> <span class='symbol'>:default</span> <span class='op'>=></span> <span class='const'>Dir</span><span class='period'>.</span><span class='id pwd'>pwd</span> <span class='rbrace'>}</span>
|
65
|
+
|
66
|
+
<span class='comment'>##
|
67
|
+
</span> <span class='comment'># Insteast of creating, destroy the files.
|
68
|
+
</span> <span class='id add_param'>add_param</span> <span class='symbol'>:destroy</span><span class='comma'>,</span> <span class='const'>Boolean</span>
|
69
|
+
|
70
|
+
<span class='comment'>##
|
71
|
+
</span> <span class='comment'># Force the creation of files without prompting.
|
72
|
+
</span> <span class='id add_param'>add_param</span> <span class='symbol'>:force</span><span class='comma'>,</span> <span class='const'>Boolean</span>
|
73
|
+
|
74
|
+
<span class='comment'>##
|
75
|
+
</span> <span class='comment'># Run the generator in Quiet mode - do not write
|
76
|
+
</span> <span class='comment'># status to standard output.
|
77
|
+
</span> <span class='id add_param'>add_param</span> <span class='symbol'>:quiet</span><span class='comma'>,</span> <span class='const'>Boolean</span>
|
78
|
+
|
79
|
+
<span class='comment'>##
|
80
|
+
</span> <span class='comment'># A collection of paths to look in for named templates.
|
81
|
+
</span> <span class='id add_param'>add_param</span> <span class='symbol'>:templates</span><span class='comma'>,</span> <span class='const'>Paths</span>
|
82
|
+
|
83
|
+
<span class='comment'>##
|
84
|
+
</span> <span class='comment'># The primary input for the application or component.
|
85
|
+
</span> <span class='id add_param'>add_param</span> <span class='symbol'>:input</span><span class='comma'>,</span> <span class='const'>String</span><span class='comma'>,</span> <span class='lbrace'>{</span> <span class='symbol'>:hidden_name</span> <span class='op'>=></span> <span class='kw'>true</span><span class='comma'>,</span> <span class='symbol'>:required</span> <span class='op'>=></span> <span class='kw'>true</span> <span class='rbrace'>}</span>
|
86
|
+
|
87
|
+
<span class='comment'>##
|
88
|
+
</span> <span class='comment'># Set the default name for generators.
|
89
|
+
</span> <span class='id set'>set</span> <span class='symbol'>:name</span><span class='comma'>,</span> <span class='symbol'>:application</span>
|
90
|
+
|
91
|
+
<span class='comment'>##
|
92
|
+
</span> <span class='comment'># The symbol name for which this generator is most
|
93
|
+
</span> <span class='comment'># appropriate.
|
94
|
+
</span> <span class='comment'>#
|
95
|
+
</span> <span class='comment'># This value defaults to :application so, if you're working on an
|
96
|
+
</span> <span class='comment'># application generator, you can leave it as the default.
|
97
|
+
</span> <span class='comment'>#
|
98
|
+
</span> <span class='comment'># For all other generator types, you'll want to select the most
|
99
|
+
</span> <span class='comment'># general project type that this generator may be useful in.
|
100
|
+
</span> <span class='comment'>#
|
101
|
+
</span> <span class='comment'># Following are some example values:
|
102
|
+
</span> <span class='comment'>#
|
103
|
+
</span> <span class='comment'># :as3, :flex3, :flex4, :air2
|
104
|
+
</span> <span class='comment'>#
|
105
|
+
</span> <span class='comment'># or core libraries:
|
106
|
+
</span> <span class='comment'>#
|
107
|
+
</span> <span class='comment'># :asunit4, :flexunit4
|
108
|
+
</span> <span class='comment'>#
|
109
|
+
</span> <span class='comment'># or even other libraries:
|
110
|
+
</span> <span class='comment'>#
|
111
|
+
</span> <span class='comment'># :puremvc, :robotlegs, :swizz
|
112
|
+
</span> <span class='comment'>#
|
113
|
+
</span> <span class='id attr_accessor'>attr_accessor</span> <span class='symbol'>:name</span>
|
114
|
+
<span class='id attr_accessor'>attr_accessor</span> <span class='symbol'>:logger</span>
|
115
|
+
<span class='id attr_accessor'>attr_accessor</span> <span class='symbol'>:pkg_name</span>
|
116
|
+
<span class='id attr_accessor'>attr_accessor</span> <span class='symbol'>:pkg_version</span>
|
117
|
+
|
118
|
+
<span class='comment'>##
|
119
|
+
</span> <span class='comment'># Record the actions and trigger them
|
120
|
+
</span> <span class='kw'>def</span> <span class='id execute'>execute</span>
|
121
|
+
<span class='kw'>return</span> <span class='id prepare_command'>prepare_command</span><span class='period'>.</span><span class='id unexecute'>unexecute</span> <span class='kw'>if</span> <span class='id destroy'>destroy</span>
|
122
|
+
<span class='id prepare_command'>prepare_command</span><span class='period'>.</span><span class='id execute'>execute</span>
|
123
|
+
<span class='kw'>end</span>
|
124
|
+
|
125
|
+
<span class='comment'>##
|
126
|
+
</span> <span class='comment'># Rollback the generator
|
127
|
+
</span> <span class='kw'>def</span> <span class='id unexecute'>unexecute</span>
|
128
|
+
<span class='id prepare_command'>prepare_command</span><span class='period'>.</span><span class='id unexecute'>unexecute</span>
|
129
|
+
<span class='kw'>end</span>
|
130
|
+
|
131
|
+
<span class='kw'>def</span> <span class='id say'>say</span> <span class='id message'>message</span>
|
132
|
+
<span class='id logger'>logger</span><span class='period'>.</span><span class='id puts'>puts</span> <span class='id message'>message</span><span class='period'>.</span><span class='id gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id path'>path</span><span class='rbrace'>}</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>.</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='id quiet'>quiet</span>
|
133
|
+
<span class='kw'>end</span>
|
134
|
+
|
135
|
+
<span class='comment'>##
|
136
|
+
</span> <span class='comment'># TODO: Add support for arbitrary templating languages.
|
137
|
+
</span> <span class='comment'># For now, just support ERB...
|
138
|
+
</span> <span class='comment'>#
|
139
|
+
</span> <span class='comment'># TODO: This is also a possible spot where those of you that don't want
|
140
|
+
</span> <span class='comment'># to snuggle might put pretty-print code or some such
|
141
|
+
</span> <span class='comment'># modifiers...
|
142
|
+
</span> <span class='kw'>def</span> <span class='id resolve_template'>resolve_template</span> <span class='id content'>content</span>
|
143
|
+
<span class='id require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>erb</span><span class='tstring_end'>'</span></span>
|
144
|
+
<span class='const'>ERB</span><span class='period'>.</span><span class='id new'>new</span><span class='lparen'>(</span><span class='id content'>content</span><span class='comma'>,</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>></span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id result'>result</span><span class='lparen'>(</span><span class='id binding'>binding</span><span class='rparen'>)</span>
|
145
|
+
<span class='kw'>end</span>
|
146
|
+
|
147
|
+
<span class='comment'>##
|
148
|
+
</span> <span class='comment'># Returns a collection of templates that were provided on the
|
149
|
+
</span> <span class='comment'># command line, followed by templates that are created by a
|
150
|
+
</span> <span class='comment'># concrete generator, followed by the
|
151
|
+
</span> <span class='comment'># Sprout::Generator.search_paths + 'templates' folders.
|
152
|
+
</span> <span class='comment'>#
|
153
|
+
</span> <span class='kw'>def</span> <span class='id template_paths'>template_paths</span>
|
154
|
+
<span class='id templates'>templates</span> <span class='op'><<</span> <span class='const'>Sprout</span><span class='op'>::</span><span class='const'>Generator</span><span class='op'>::</span><span class='id template_folder_for'>template_folder_for</span><span class='lparen'>(</span><span class='kw'>self</span><span class='rparen'>)</span>
|
155
|
+
<span class='id templates'>templates</span><span class='period'>.</span><span class='id concat'>concat</span> <span class='id default_search_paths'>default_search_paths</span>
|
156
|
+
<span class='kw'>end</span>
|
157
|
+
|
158
|
+
<span class='id protected'>protected</span>
|
159
|
+
|
160
|
+
<span class='kw'>def</span> <span class='id default_search_paths'>default_search_paths</span>
|
161
|
+
<span class='const'>Sprout</span><span class='op'>::</span><span class='const'>Generator</span><span class='period'>.</span><span class='id search_paths'>search_paths</span><span class='period'>.</span><span class='id collect'>collect</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id path'>path</span><span class='op'>|</span> <span class='const'>File</span><span class='period'>.</span><span class='id join'>join</span><span class='lparen'>(</span><span class='id path'>path</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>templates</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
162
|
+
<span class='kw'>end</span>
|
163
|
+
|
164
|
+
<span class='kw'>def</span> <span class='id prepare_command'>prepare_command</span>
|
165
|
+
<span class='ivar'>@logger</span> <span class='op'>||=</span> <span class='gvar'>$stdout</span>
|
166
|
+
<span class='ivar'>@command</span> <span class='op'>=</span> <span class='const'>Command</span><span class='period'>.</span><span class='id new'>new</span> <span class='kw'>self</span>
|
167
|
+
<span class='ivar'>@command</span><span class='period'>.</span><span class='id logger'>logger</span> <span class='op'>=</span> <span class='id logger'>logger</span>
|
168
|
+
<span class='id manifest'>manifest</span>
|
169
|
+
<span class='ivar'>@command</span>
|
170
|
+
<span class='kw'>end</span>
|
171
|
+
|
172
|
+
<span class='kw'>def</span> <span class='id directory'>directory</span> <span class='id name'>name</span><span class='comma'>,</span> <span class='op'>&</span><span class='id block'>block</span>
|
173
|
+
<span class='ivar'>@command</span><span class='period'>.</span><span class='id directory'>directory</span> <span class='id name'>name</span><span class='comma'>,</span> <span class='op'>&</span><span class='id block'>block</span>
|
174
|
+
<span class='kw'>end</span>
|
175
|
+
|
176
|
+
<span class='kw'>def</span> <span class='id file'>file</span> <span class='id name'>name</span><span class='comma'>,</span> <span class='id template'>template</span><span class='op'>=</span><span class='kw'>nil</span>
|
177
|
+
<span class='ivar'>@command</span><span class='period'>.</span><span class='id file'>file</span> <span class='id name'>name</span><span class='comma'>,</span> <span class='id template'>template</span>
|
178
|
+
<span class='kw'>end</span>
|
179
|
+
|
180
|
+
<span class='kw'>def</span> <span class='id template'>template</span> <span class='id name'>name</span><span class='comma'>,</span> <span class='id template'>template</span><span class='op'>=</span><span class='kw'>nil</span>
|
181
|
+
<span class='ivar'>@command</span><span class='period'>.</span><span class='id template'>template</span> <span class='id name'>name</span><span class='comma'>,</span> <span class='id template'>template</span>
|
182
|
+
<span class='kw'>end</span>
|
183
|
+
|
184
|
+
<span class='kw'>def</span> <span class='id generator'>generator</span> <span class='id name'>name</span><span class='comma'>,</span> <span class='id options'>options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span>
|
185
|
+
<span class='ivar'>@command</span><span class='period'>.</span><span class='id generator'>generator</span> <span class='id name'>name</span><span class='comma'>,</span> <span class='id to_hash'>to_hash</span><span class='period'>.</span><span class='id merge'>merge</span><span class='lparen'>(</span><span class='id options'>options</span><span class='rparen'>)</span>
|
186
|
+
<span class='kw'>end</span>
|
187
|
+
|
188
|
+
<span class='id private'>private</span>
|
189
|
+
|
190
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id template_from_caller'>template_from_caller</span> <span class='id caller_string'>caller_string</span>
|
191
|
+
<span class='id file'>file</span> <span class='op'>=</span> <span class='const'>Sprout</span><span class='period'>.</span><span class='id file_from_caller'>file_from_caller</span> <span class='id caller_string'>caller_string</span>
|
192
|
+
<span class='const'>File</span><span class='period'>.</span><span class='id join'>join</span><span class='lparen'>(</span><span class='const'>File</span><span class='period'>.</span><span class='id dirname'>dirname</span><span class='lparen'>(</span><span class='id file'>file</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>templates</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
193
|
+
<span class='kw'>end</span>
|
194
|
+
|
195
|
+
<span class='kw'>end</span>
|
196
|
+
<span class='kw'>end</span></pre>
|
197
|
+
|
198
|
+
<p>end</p>
|
199
|
+
</div></div>
|
200
|
+
|
201
|
+
<div id="footer">
|
202
|
+
Generated on Wed Dec 22 11:58:32 2010 by
|
203
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
204
|
+
0.6.3 (ruby-1.9.2).
|
205
|
+
</div>
|
206
|
+
|
207
|
+
</body>
|
208
|
+
</html>
|