facets 2.6.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY.rdoc +331 -35
- data/MANIFEST +685 -826
- data/{doc/guide/notes.rd → NOTES} +0 -0
- data/README.rdoc +73 -25
- data/Rakefile +245 -2
- data/TODO +5 -0
- data/demo/hook.rd +47 -0
- data/demo/scenario_require.rd +9 -0
- data/doc/README.more +24 -6
- data/doc/manual/about.rb +47 -0
- data/doc/manual/annotations.rdoc +60 -0
- data/doc/manual/associations.rdoc +55 -0
- data/doc/manual/blockups.rdoc +101 -0
- data/doc/manual/capsule.rdoc +34 -0
- data/doc/manual/command.rdoc +177 -0
- data/doc/manual/core.rdoc +37 -0
- data/doc/manual/faq.rdoc +32 -0
- data/doc/manual/typecast.html +112 -0
- data/lib/core/facets.rb +359 -11
- data/lib/core/facets/array/combination.rb +3 -3
- data/lib/core/facets/array/index.rb +4 -1
- data/lib/core/facets/array/permutation.rb +2 -2
- data/lib/core/facets/array/product.rb +1 -1
- data/lib/core/facets/binding/eval.rb +1 -1
- data/lib/core/facets/denumerable.rb +76 -0
- data/lib/core/facets/duplicable.rb +34 -0
- data/lib/core/facets/enumerable/count.rb +10 -4
- data/lib/core/facets/enumerable/defer.rb +77 -0
- data/lib/core/facets/enumerable/each_by.rb +1 -1
- data/lib/core/facets/enumerable/every.rb +35 -0
- data/lib/{more/facets/elementwise.rb → core/facets/enumerable/ewise.rb} +0 -0
- data/lib/core/facets/enumerable/filter.rb +25 -0
- data/lib/core/facets/enumerable/group_by.rb +1 -1
- data/lib/core/facets/enumerable/none.rb +3 -2
- data/lib/core/facets/enumerable/one.rb +3 -2
- data/lib/core/facets/enumerable/per.rb +61 -0
- data/lib/core/facets/exception/raised.rb +14 -0
- data/lib/core/facets/integer/odd.rb +5 -1
- data/lib/core/facets/kernel/__dir__.rb +13 -3
- data/lib/core/facets/kernel/__here__.rb +14 -0
- data/lib/core/facets/kernel/__method__.rb +9 -3
- data/lib/core/facets/kernel/ask.rb +1 -0
- data/lib/core/facets/kernel/equate.rb +13 -0
- data/lib/core/facets/kernel/extension.rb +9 -0
- data/lib/core/facets/kernel/identical.rb +4 -0
- data/lib/core/facets/kernel/instance_exec.rb +2 -1
- data/lib/core/facets/kernel/method.rb +49 -0
- data/lib/core/facets/kernel/object_send.rb +2 -2
- data/lib/core/facets/kernel/{state.rb → object_state.rb} +23 -12
- data/lib/core/facets/kernel/require_all.rb +6 -1
- data/lib/core/facets/kernel/require_local.rb +8 -1
- data/lib/core/facets/kernel/require_relative.rb +52 -0
- data/lib/core/facets/kernel/source_location.rb +13 -0
- data/lib/core/facets/kernel/tap.rb +13 -6
- data/lib/core/facets/module/attr_setter.rb +57 -0
- data/lib/core/facets/module/instance_method.rb +24 -0
- data/lib/core/facets/module/module_load.rb +60 -44
- data/lib/core/facets/module/module_require.rb +1 -0
- data/lib/core/facets/nilclass/to_f.rb +1 -1
- data/lib/core/facets/objectspace/op_fetch.rb +3 -0
- data/lib/core/facets/proc/curry.rb +4 -3
- data/lib/core/facets/string/bytes.rb +10 -4
- data/lib/core/facets/string/camelcase.rb +6 -5
- data/lib/core/facets/string/chars.rb +5 -1
- data/lib/core/facets/string/each_char.rb +1 -1
- data/lib/core/facets/string/each_word.rb +1 -1
- data/lib/core/facets/string/lines.rb +11 -4
- data/lib/core/facets/string/start_with.rb +9 -2
- data/lib/core/facets/string/unfold.rb +27 -0
- data/lib/core/facets/symbol/succ.rb +3 -3
- data/lib/core/facets/symbol/thrown.rb +20 -0
- data/lib/core/facets/symbol/to_proc.rb +3 -2
- data/lib/core/facets/time/to_time.rb +1 -1
- data/lib/core/facets/to_hash.rb +41 -100
- data/lib/core/facets/unboundmethod/name.rb +20 -23
- data/lib/more/facets/ansicode.rb +1 -10
- data/lib/more/facets/autoarray.rb +3 -31
- data/lib/more/facets/basicobject.rb +73 -0
- data/lib/more/facets/blankslate.rb +2 -66
- data/lib/{lore → more}/facets/cgi.rb +0 -0
- data/lib/more/facets/class_extend.rb +1 -0
- data/lib/{lore → more}/facets/continuation.rb +0 -0
- data/lib/{lore → more}/facets/date.rb +3 -3
- data/lib/more/facets/enumargs.rb +192 -0
- data/lib/more/facets/enumerablepass.rb +2 -216
- data/lib/more/facets/enumerator.rb +62 -0
- data/lib/more/facets/{equatable.rb → equitable.rb} +11 -11
- data/lib/more/facets/expirable.rb +13 -41
- data/lib/{lore → more}/facets/fileutils.rb +0 -0
- data/lib/{lore → more}/facets/fileutils/head.rb +0 -0
- data/lib/{lore → more}/facets/fileutils/safe_ln.rb +0 -0
- data/lib/{lore → more}/facets/fileutils/slice.rb +0 -0
- data/lib/{lore → more}/facets/fileutils/tail.rb +0 -0
- data/lib/{lore → more}/facets/fileutils/wc.rb +0 -0
- data/lib/{lore → more}/facets/fileutils/whereis.rb +0 -0
- data/lib/{lore → more}/facets/fileutils/which.rb +0 -0
- data/lib/{lore → more}/facets/getoptlong.rb +0 -0
- data/lib/more/facets/hook.rb +2 -29
- data/lib/more/facets/inheritor.rb +2 -2
- data/lib/more/facets/instance_eval.rb +50 -0
- data/lib/more/facets/instance_function.rb +78 -0
- data/lib/more/facets/main.rb +20 -15
- data/lib/more/facets/memoize.rb +1 -113
- data/lib/more/facets/module/attr.rb +83 -0
- data/lib/more/facets/module/attr_tester.rb +44 -0
- data/lib/more/facets/module/attr_toggler.rb +59 -0
- data/lib/more/facets/module/attr_validator.rb +34 -0
- data/lib/more/facets/{class_extension.rb → module/class_extend.rb} +21 -13
- data/lib/more/facets/once.rb +59 -0
- data/lib/more/facets/openmodule.rb +1 -0
- data/lib/more/facets/orderedhash.rb +1 -33
- data/lib/{lore → more}/facets/ostruct.rb +0 -0
- data/lib/more/facets/ostructable.rb +1 -4
- data/lib/more/facets/partial.rb +18 -16
- data/lib/{lore → more}/facets/pathname.rb +0 -0
- data/lib/more/facets/preinitialize.rb +157 -0
- data/lib/{lore → more}/facets/rbconfig.rb +0 -0
- data/lib/more/facets/recorder.rb +1 -2
- data/lib/{lore → more}/facets/set.rb +0 -0
- data/lib/{lore → more}/facets/shellwords.rb +0 -0
- data/lib/{lore → more}/facets/uri.rb +0 -0
- data/lib/{lore → more}/facets/yaml.rb +0 -0
- data/lib/{lore → more}/facets/zlib.rb +0 -0
- data/meta/loadpath +0 -1
- data/meta/sitemap +4 -0
- data/meta/version +1 -1
- data/test/core/enumerable/test_count.rb +1 -1
- data/test/{more/test_filter.rb → core/enumerable/test_defer.rb} +24 -22
- data/test/{more/test_elementor.rb → core/enumerable/test_every.rb} +2 -15
- data/test/core/enumerable/test_ewise.rb +23 -0
- data/test/core/enumerable/test_per.rb +18 -0
- data/test/core/enumerable/test_take.rb +13 -0
- data/test/core/kernel/test_deepcopy.rb +1 -1
- data/test/{more/test_1stclassmethod.rb → core/kernel/test_method.rb} +2 -7
- data/test/core/kernel/test_tap.rb +1 -1
- data/test/core/proc/test_curry.rb +11 -0
- data/test/core/string/test_bytes.rb +1 -1
- data/test/core/string/test_camelcase.rb +23 -6
- data/test/core/string/test_lines.rb +1 -1
- data/test/core/string/test_unfold.rb +14 -0
- data/test/{more → core}/test_blank.rb +0 -0
- data/test/{more → core}/test_boolean.rb +0 -0
- data/test/{more → core}/test_functor.rb +0 -0
- data/test/{lore → more}/test_basicobject.rb +0 -0
- data/test/more/{test_class_extension.rb → test_class_extend.rb} +6 -6
- data/test/{lore → more}/test_continuation.rb +0 -0
- data/test/{lore → more}/test_date.rb +0 -0
- data/test/more/{test_enumerablepass.rb → test_enumargs.rb} +2 -4
- data/test/more/{test_equatable.rb → test_equitable.rb} +2 -2
- data/test/more/{test_instantise.rb → test_instance_function.rb} +3 -2
- data/test/more/test_memoize.rb +1 -1
- data/test/{lore → more}/test_ostruct.rb +0 -0
- metadata +865 -1016
- data/RELEASE +0 -38
- data/doc/README.lore +0 -51
- data/doc/log/basic_stats/index.html +0 -39
- data/doc/log/changelog.html +0 -648
- data/doc/log/changelog.txt +0 -217
- data/doc/log/stats/index.html +0 -39
- data/doc/log/testlog.txt +0 -278
- data/doc/notes/CHANGES +0 -2529
- data/doc/rdoc/lore/classes/Array.html +0 -176
- data/doc/rdoc/lore/classes/CGI.html +0 -191
- data/doc/rdoc/lore/classes/Config.html +0 -135
- data/doc/rdoc/lore/classes/Continuation.html +0 -113
- data/doc/rdoc/lore/classes/Date.html +0 -631
- data/doc/rdoc/lore/classes/DateTime.html +0 -583
- data/doc/rdoc/lore/classes/Enumerable.html +0 -89
- data/doc/rdoc/lore/classes/Enumerable/Enumerator.html +0 -147
- data/doc/rdoc/lore/classes/File.html +0 -128
- data/doc/rdoc/lore/classes/FileUtils.html +0 -434
- data/doc/rdoc/lore/classes/GetoptLong.html +0 -118
- data/doc/rdoc/lore/classes/GetoptLong/DSL.html +0 -208
- data/doc/rdoc/lore/classes/Kernel.html +0 -135
- data/doc/rdoc/lore/classes/Logger.html +0 -229
- data/doc/rdoc/lore/classes/Logger/Ansicolor.html +0 -277
- data/doc/rdoc/lore/classes/Logger/LogDevice.html +0 -121
- data/doc/rdoc/lore/classes/NilClass.html +0 -119
- data/doc/rdoc/lore/classes/OpenStruct.html +0 -432
- data/doc/rdoc/lore/classes/Pathname.html +0 -353
- data/doc/rdoc/lore/classes/Set.html +0 -117
- data/doc/rdoc/lore/classes/Shellwords.html +0 -111
- data/doc/rdoc/lore/classes/String.html +0 -140
- data/doc/rdoc/lore/classes/Time.html +0 -154
- data/doc/rdoc/lore/classes/URI.html +0 -454
- data/doc/rdoc/lore/classes/URI/Hash.html +0 -105
- data/doc/rdoc/lore/classes/URI/Kernel.html +0 -122
- data/doc/rdoc/lore/classes/Zlib.html +0 -188
- data/doc/rdoc/lore/created.rid +0 -1
- data/doc/rdoc/lore/files/README.html +0 -286
- data/doc/rdoc/lore/files/doc/README_lore.html +0 -155
- data/doc/rdoc/lore/files/lib/lore/facets/basicobject_rb.html +0 -118
- data/doc/rdoc/lore/files/lib/lore/facets/cgi_rb.html +0 -111
- data/doc/rdoc/lore/files/lib/lore/facets/continuation_rb.html +0 -147
- data/doc/rdoc/lore/files/lib/lore/facets/date_rb.html +0 -97
- data/doc/rdoc/lore/files/lib/lore/facets/enumerator_rb.html +0 -111
- data/doc/rdoc/lore/files/lib/lore/facets/fileutils/head_rb.html +0 -96
- data/doc/rdoc/lore/files/lib/lore/facets/fileutils/safe_ln_rb.html +0 -96
- data/doc/rdoc/lore/files/lib/lore/facets/fileutils/slice_rb.html +0 -96
- data/doc/rdoc/lore/files/lib/lore/facets/fileutils/tail_rb.html +0 -96
- data/doc/rdoc/lore/files/lib/lore/facets/fileutils/wc_rb.html +0 -96
- data/doc/rdoc/lore/files/lib/lore/facets/fileutils/whereis_rb.html +0 -96
- data/doc/rdoc/lore/files/lib/lore/facets/fileutils/which_rb.html +0 -96
- data/doc/rdoc/lore/files/lib/lore/facets/fileutils_rb.html +0 -131
- data/doc/rdoc/lore/files/lib/lore/facets/getoptlong_rb.html +0 -135
- data/doc/rdoc/lore/files/lib/lore/facets/logger_rb.html +0 -142
- data/doc/rdoc/lore/files/lib/lore/facets/ostruct_rb.html +0 -135
- data/doc/rdoc/lore/files/lib/lore/facets/pathname_rb.html +0 -145
- data/doc/rdoc/lore/files/lib/lore/facets/rbconfig_rb.html +0 -124
- data/doc/rdoc/lore/files/lib/lore/facets/set_rb.html +0 -96
- data/doc/rdoc/lore/files/lib/lore/facets/shellwords_rb.html +0 -124
- data/doc/rdoc/lore/files/lib/lore/facets/uri_rb.html +0 -125
- data/doc/rdoc/lore/files/lib/lore/facets/yaml_rb.html +0 -146
- data/doc/rdoc/lore/files/lib/lore/facets/zlib_rb.html +0 -97
- data/doc/rdoc/lore/fr_class_index.html +0 -73
- data/doc/rdoc/lore/fr_file_index.html +0 -71
- data/doc/rdoc/lore/fr_method_index.html +0 -177
- data/doc/rdoc/lore/index.html +0 -26
- data/doc/rdoc/lore/rdoc-style.css +0 -177
- data/doc/release-notes/RELEASE-2.0.5 +0 -8
- data/doc/release-notes/RELEASE-2.1.0 +0 -9
- data/doc/release-notes/RELEASE-2.1.1 +0 -5
- data/doc/release-notes/RELEASE-2.1.2 +0 -6
- data/doc/release-notes/RELEASE-2.1.3 +0 -5
- data/doc/release-notes/RELEASE-2.2.0 +0 -14
- data/doc/release-notes/RELEASE-2.2.1 +0 -4
- data/doc/release-notes/RELEASE-2.3.0 +0 -6
- data/doc/release-notes/RELEASE-2.4.0 +0 -70
- data/doc/release-notes/RELEASE-2.4.1 +0 -8
- data/doc/release-notes/RELEASE-2.4.2 +0 -4
- data/doc/release-notes/RELEASE-2.4.3 +0 -78
- data/doc/release-notes/RELEASE-2.4.4 +0 -38
- data/doc/release-notes/RELEASE-2.4.5 +0 -37
- data/doc/release-notes/RELEASE-2.5.0 +0 -83
- data/lib/core/facets/kernel/instance.rb +0 -19
- data/lib/lore/facets/basicobject.rb +0 -14
- data/lib/lore/facets/enumerator.rb +0 -67
- data/lib/lore/facets/logger.rb +0 -291
- data/lib/more/facets/1stclassmethod.rb +0 -140
- data/lib/more/facets/advisable.rb +0 -162
- data/lib/more/facets/association.rb +0 -210
- data/lib/more/facets/attr.rb +0 -209
- data/lib/more/facets/basex.rb +0 -37
- data/lib/more/facets/bbcode.rb +0 -397
- data/lib/more/facets/bicrypt.rb +0 -265
- data/lib/more/facets/binreadable.rb +0 -221
- data/lib/more/facets/censor.rb +0 -97
- data/lib/more/facets/classmethods.rb +0 -199
- data/lib/more/facets/consoleutils.rb +0 -99
- data/lib/more/facets/crypt.rb +0 -166
- data/lib/more/facets/dependency.rb +0 -151
- data/lib/more/facets/downloader.rb +0 -281
- data/lib/more/facets/duplicable.rb +0 -43
- data/lib/more/facets/elementor.rb +0 -133
- data/lib/more/facets/filter.rb +0 -121
- data/lib/more/facets/heap.rb +0 -22
- data/lib/more/facets/infinity.rb +0 -193
- data/lib/more/facets/ini.rb +0 -264
- data/lib/more/facets/instantise.rb +0 -1
- data/lib/more/facets/instantize.rb +0 -95
- data/lib/more/facets/interval.rb +0 -282
- data/lib/more/facets/iteration.rb +0 -65
- data/lib/more/facets/linkedlist.rb +0 -222
- data/lib/more/facets/lrucache.rb +0 -157
- data/lib/more/facets/matcher.rb +0 -140
- data/lib/more/facets/memoizer.rb +0 -74
- data/lib/more/facets/minitar.rb +0 -1063
- data/lib/more/facets/nackclass.rb +0 -41
- data/lib/more/facets/net/smtp_tls.rb +0 -131
- data/lib/more/facets/nilstatus.rb +0 -48
- data/lib/more/facets/overload.rb +0 -94
- data/lib/more/facets/paramix.rb +0 -202
- data/lib/more/facets/pool.rb +0 -91
- data/lib/more/facets/pqueue.rb +0 -449
- data/lib/more/facets/pry.rb +0 -32
- data/lib/more/facets/reflection.rb +0 -145
- data/lib/more/facets/semaphore.rb +0 -92
- data/lib/more/facets/settings.rb +0 -248
- data/lib/more/facets/snapshot.rb +0 -209
- data/lib/more/facets/sparse_array.rb +0 -809
- data/lib/more/facets/string/mask.rb +0 -278
- data/lib/more/facets/string/obfuscate.rb +0 -65
- data/lib/more/facets/string/stylize.rb +0 -169
- data/lib/more/facets/string/words.rb +0 -167
- data/lib/more/facets/syncarray.rb +0 -114
- data/lib/more/facets/synchash.rb +0 -157
- data/lib/more/facets/typecast.rb +0 -261
- data/lib/more/facets/uninheritable.rb +0 -50
- data/lib/more/facets/xmlhash.rb +0 -112
- data/lib/more/facets/xoxo.rb +0 -259
- data/lib/more/facets/ziputils.rb +0 -490
- data/task/conflicts +0 -63
- data/task/coverage.rake +0 -37
- data/task/methods +0 -49
- data/task/rdoc.rake +0 -17
- data/task/setup.rake +0 -38
- data/task/test.rake +0 -145
- data/test/more/test_advisable.rb +0 -71
- data/test/more/test_association.rb +0 -38
- data/test/more/test_bbcode.rb +0 -21
- data/test/more/test_binreadable.rb +0 -50
- data/test/more/test_buildable.rb +0 -73
- data/test/more/test_classmethods.rb +0 -56
- data/test/more/test_crypt.rb +0 -32
- data/test/more/test_dependency.rb +0 -69
- data/test/more/test_elementwise.rb +0 -25
- data/test/more/test_infinity.rb +0 -40
- data/test/more/test_interval.rb +0 -151
- data/test/more/test_linkedlist.rb +0 -41
- data/test/more/test_lrucache.rb +0 -14
- data/test/more/test_overload.rb +0 -160
- data/test/more/test_paramix.rb +0 -170
- data/test/more/test_prototype.rb +0 -35
- data/test/more/test_snapshot.rb +0 -21
- data/test/more/test_sparsearray.rb +0 -279
- data/test/more/test_syncarray.rb +0 -15
- data/test/more/test_synchash.rb +0 -16
- data/test/more/test_typecast.rb +0 -54
- data/test/more/test_uninheritable.rb +0 -31
- data/test/more/test_xoxo.rb +0 -274
- data/test/test_facets.rb +0 -9
@@ -1,151 +0,0 @@
|
|
1
|
-
# = Dependency
|
2
|
-
#
|
3
|
-
# == Synopsis
|
4
|
-
#
|
5
|
-
# This module is included in Object and allows methods to be given prerequisite
|
6
|
-
# dependencies, i.e. methods that must be run before they are.
|
7
|
-
#
|
8
|
-
# A dependency will only ever be run once per method call.
|
9
|
-
#
|
10
|
-
# include MethodDependency
|
11
|
-
#
|
12
|
-
# def one; @str << '1'; end
|
13
|
-
# def two; @str << '2'; end
|
14
|
-
#
|
15
|
-
# def show; @str ; end
|
16
|
-
#
|
17
|
-
# depend :show => [ :x, :y ]
|
18
|
-
#
|
19
|
-
# show #=> '12'
|
20
|
-
#
|
21
|
-
# You can add this functionality to the whole system
|
22
|
-
# by simply including it at the toplevel.
|
23
|
-
#
|
24
|
-
# == Author
|
25
|
-
#
|
26
|
-
# * Thomas Sawyer
|
27
|
-
#
|
28
|
-
# == Notes
|
29
|
-
#
|
30
|
-
# * The #included call back does a comparison to Object.
|
31
|
-
# This is a bit of a hack b/c there is actually no way to
|
32
|
-
# check if it is the toplevel --a flaw w/ Ruby's toplevel proxy.
|
33
|
-
#
|
34
|
-
# == Todo
|
35
|
-
#
|
36
|
-
# * Need to be more flexible with passing arguments to
|
37
|
-
# dependency methods.
|
38
|
-
# * Avoid global variable. How?
|
39
|
-
#
|
40
|
-
# == Copying
|
41
|
-
#
|
42
|
-
# Copyright (c) 2006 Thomas Sawyer
|
43
|
-
#
|
44
|
-
# Ruby License
|
45
|
-
#
|
46
|
-
# This module is free software. You may use, modify, and/or redistribute this
|
47
|
-
# software under the same terms as Ruby.
|
48
|
-
#
|
49
|
-
# This program is distributed in the hope that it will be useful, but WITHOUT
|
50
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
51
|
-
# FOR A PARTICULAR PURPOSE.
|
52
|
-
|
53
|
-
require 'facets/hash/to_h'
|
54
|
-
|
55
|
-
$toplevel = self
|
56
|
-
|
57
|
-
# = MethodDependency
|
58
|
-
#
|
59
|
-
# This module is included in Object and allows methods to be given prerequisite
|
60
|
-
# dependencies, i.e. methods that must be run before they are.
|
61
|
-
#
|
62
|
-
# A dependency will only ever be run once per method call.
|
63
|
-
#
|
64
|
-
# == Synopis
|
65
|
-
#
|
66
|
-
# include MethodDependency
|
67
|
-
#
|
68
|
-
# def one; @str << '1'; end
|
69
|
-
# def two; @str << '2'; end
|
70
|
-
#
|
71
|
-
# def show; @str ; end
|
72
|
-
#
|
73
|
-
# depend :show => [ :x, :y ]
|
74
|
-
#
|
75
|
-
# show #=> '12'
|
76
|
-
#
|
77
|
-
# You can add this functionality to the whole system
|
78
|
-
# by simply including it at the toplevel.
|
79
|
-
|
80
|
-
class Module
|
81
|
-
|
82
|
-
#def self.included( base )
|
83
|
-
# if base == Object #$toplevel
|
84
|
-
# require 'facets/remain.rb'
|
85
|
-
# end
|
86
|
-
#end
|
87
|
-
|
88
|
-
#
|
89
|
-
|
90
|
-
def depend( name_and_deps=nil )
|
91
|
-
if Hash === name_and_deps
|
92
|
-
name_and_deps.to_h.each do |name, deps|
|
93
|
-
deps = [deps].flatten
|
94
|
-
define_dependency(name, *deps)
|
95
|
-
end
|
96
|
-
elsif name_and_deps
|
97
|
-
@dependency ||= {}
|
98
|
-
@dependency[name_and_deps.to_sym]
|
99
|
-
else
|
100
|
-
@dependency ||= {}
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
# Compile list of all unique prerequisite calls.
|
105
|
-
|
106
|
-
def dependencies(name, build=[])
|
107
|
-
@dependency ||= {}
|
108
|
-
deps = @dependency[name.to_sym]
|
109
|
-
return build unless deps
|
110
|
-
deps.each do |dep|
|
111
|
-
build.unshift(dep)
|
112
|
-
dependencies(dep,build)
|
113
|
-
end
|
114
|
-
build.uniq!
|
115
|
-
build
|
116
|
-
end
|
117
|
-
|
118
|
-
#
|
119
|
-
|
120
|
-
def define_dependency( name, *deps )
|
121
|
-
@dependency ||= {}
|
122
|
-
if @dependency[name.to_sym]
|
123
|
-
@dependency[name.to_sym] = deps
|
124
|
-
else
|
125
|
-
@dependency[name.to_sym] = deps
|
126
|
-
deplist = lambda{ dependencies(name) }
|
127
|
-
alias_method("#{name}:execute",name)
|
128
|
-
define_method(name) do |*a|
|
129
|
-
# run dependencies
|
130
|
-
deplist.call.each do |d|
|
131
|
-
if respond_to?("#{d}:execute")
|
132
|
-
send("#{d}:execute",*a) #,&b)
|
133
|
-
else
|
134
|
-
send(d,*a) #,&b)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
# run core method
|
138
|
-
send("#{name}:execute",*a) #,&b)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
end
|
144
|
-
|
145
|
-
#class RecursiveDependency < StandardError; end
|
146
|
-
|
147
|
-
|
148
|
-
#class Module
|
149
|
-
# include MethodDependency
|
150
|
-
#end
|
151
|
-
|
@@ -1,281 +0,0 @@
|
|
1
|
-
# = Downloader
|
2
|
-
#
|
3
|
-
# Tool module for downloading files and extracting
|
4
|
-
# archive files. Currently this is console-based
|
5
|
-
# but in the future will have SOC for any interface.
|
6
|
-
#
|
7
|
-
# == Authors
|
8
|
-
#
|
9
|
-
# * Thomas Sawyer
|
10
|
-
#
|
11
|
-
# == Todo
|
12
|
-
#
|
13
|
-
# * Should thre be two classes? The main Downloader which is
|
14
|
-
# independent of any interface. The second "Console::Downloader"
|
15
|
-
# using the first but with a console interface?
|
16
|
-
#
|
17
|
-
# == Copying
|
18
|
-
#
|
19
|
-
# Copyright (c) 2005 Thomas Sawyer
|
20
|
-
#
|
21
|
-
# Ruby License
|
22
|
-
#
|
23
|
-
# This module is free software. You may use, modify, and/or redistribute this
|
24
|
-
# software under the same terms as Ruby.
|
25
|
-
#
|
26
|
-
# This program is distributed in the hope that it will be useful, but WITHOUT
|
27
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
28
|
-
# FOR A PARTICULAR PURPOSE.
|
29
|
-
|
30
|
-
require 'digest/md5'
|
31
|
-
require 'open-uri'
|
32
|
-
|
33
|
-
require 'facets/string/bracket' # for unbracket
|
34
|
-
require 'facets/progressbar'
|
35
|
-
|
36
|
-
# = Downloader
|
37
|
-
#
|
38
|
-
# Tool module for downloading files and extracting
|
39
|
-
# archive files. Currently this is console-based
|
40
|
-
# but in the future will have SOC for any interface.
|
41
|
-
#
|
42
|
-
class Downloader
|
43
|
-
|
44
|
-
#class DownloadError < StandardError #:nodoc:
|
45
|
-
#end
|
46
|
-
|
47
|
-
class Checksum < StandardError #:nodoc:
|
48
|
-
end
|
49
|
-
|
50
|
-
class Mirror #:nodoc:
|
51
|
-
def initialize( url, region=nil )
|
52
|
-
@url = url
|
53
|
-
@region = region
|
54
|
-
@interface = nil
|
55
|
-
end
|
56
|
-
attr_accessor :url, :region
|
57
|
-
end
|
58
|
-
|
59
|
-
# delegate to an interface (under development)
|
60
|
-
|
61
|
-
def interface ; @interface; end
|
62
|
-
def interface=(iface)
|
63
|
-
@interface = iface
|
64
|
-
end
|
65
|
-
|
66
|
-
def initialize( destination, mirrors=nil, region=nil, &config )
|
67
|
-
@destination = destination
|
68
|
-
@mirrors = []
|
69
|
-
add_mirrors( mirrors ) if mirrors
|
70
|
-
@region = (region || 'US').to_s
|
71
|
-
config.call(self) if config
|
72
|
-
end
|
73
|
-
|
74
|
-
attr_accessor :destination, :region
|
75
|
-
|
76
|
-
def add_mirror( url, region=nil )
|
77
|
-
@mirrors << Mirror.new( url, region )
|
78
|
-
end
|
79
|
-
|
80
|
-
def add_mirrors( mirrors )
|
81
|
-
mirrors.each { |mirror|
|
82
|
-
case mirror
|
83
|
-
when String
|
84
|
-
url, rgn = *mirror.strip.split(' ')
|
85
|
-
add_mirror( url, rgn.unbracket )
|
86
|
-
when Array
|
87
|
-
add_mirror( *mirror )
|
88
|
-
when Hash
|
89
|
-
add_mirror( mirror[:url], mirror[:region] )
|
90
|
-
when Mirror
|
91
|
-
@mirrors << mirror
|
92
|
-
else
|
93
|
-
raise "unrecogized mirror definition #{mirror.inspect}"
|
94
|
-
end
|
95
|
-
}
|
96
|
-
end
|
97
|
-
|
98
|
-
def mirrors
|
99
|
-
@mirrors.sort{ |a,b| a.region == region ? 1 : ( b.region == region ? -1 : 0 ) }
|
100
|
-
end
|
101
|
-
|
102
|
-
# fetch
|
103
|
-
|
104
|
-
def fetch( file, checksum=0, est_size=0, force=false )
|
105
|
-
urls = mirrors.collect { |m| "#{m.url.chomp('/')}/#{file}" }
|
106
|
-
urls = prioritize_urls( urls )
|
107
|
-
filepath = "#{destination.chomp('/')}/#{file}"
|
108
|
-
monitored_download( urls, filepath, checksum, est_size, force )
|
109
|
-
end
|
110
|
-
|
111
|
-
# def download_verbose
|
112
|
-
# @download_verbose ||= $VERBOSE
|
113
|
-
# true
|
114
|
-
# end
|
115
|
-
#
|
116
|
-
# def download_verbose=(x)
|
117
|
-
# @download_verbose = x ? true : false
|
118
|
-
# end
|
119
|
-
|
120
|
-
# regional_urls - array of arrays of [ url, region, md5, expected_size ]
|
121
|
-
# local_region - region of the user's system
|
122
|
-
# to_dir - where to store downloaded file (full path)
|
123
|
-
# force - download even if file already exists locally
|
124
|
-
|
125
|
-
def monitored_download( urls, filepath, checksum, est_size=0, force=false )
|
126
|
-
|
127
|
-
checksum = checksum.to_s.strip
|
128
|
-
est_size = nil if est_size == 0
|
129
|
-
|
130
|
-
success=nil
|
131
|
-
|
132
|
-
# source file exists and passes checksum then we need not fetch
|
133
|
-
#file_path = File.join(to_dir,File.basename(url[0]))
|
134
|
-
if File.exists?(filepath)
|
135
|
-
if compute_checksum(filepath) == checksum and ! force
|
136
|
-
interface.report("File has already been fetched and passes checksum.")
|
137
|
-
success = filepath
|
138
|
-
else
|
139
|
-
File.delete(filepath)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
unless success
|
144
|
-
# download
|
145
|
-
urls.each do |url|
|
146
|
-
begin
|
147
|
-
#file_path = File.join(to_dir,File.basename(url[0]))
|
148
|
-
#file_checksum = url[2].to_s.strip
|
149
|
-
#file_size = url[3].to_i
|
150
|
-
success = self.download( url, filepath, checksum, est_size )
|
151
|
-
break if success
|
152
|
-
rescue
|
153
|
-
next
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
return success
|
159
|
-
end
|
160
|
-
|
161
|
-
# In the future we may test each connection for fastest download
|
162
|
-
|
163
|
-
def prioritize_urls( urls )
|
164
|
-
urls
|
165
|
-
# put local region first
|
166
|
-
#prioritized_urls = regional_urls.find_all { |a| a[1] == local_region }
|
167
|
-
#prioritized_urls.concat regional_urls.find_all { |a| a[1] != local_region }
|
168
|
-
#return prioritized_urls
|
169
|
-
end
|
170
|
-
|
171
|
-
# currently can only download a single compressed file
|
172
|
-
# does not handle downloading an uncompressed directory tree (should it? doubt it)
|
173
|
-
#
|
174
|
-
# currently this displays progress to STDOUT; either their should
|
175
|
-
# be a way to activate/deactivate or preferably use ducktype singletons
|
176
|
-
# (more on that later, see google://_whytheluckystiff if interested)
|
177
|
-
# of course I prefer chain messaging but matz said no :(
|
178
|
-
|
179
|
-
def download( url, filepath, checksum='', est_size=nil )
|
180
|
-
|
181
|
-
checksum = checksum.to_s.strip
|
182
|
-
est_size = nil if est_size == 0
|
183
|
-
|
184
|
-
download_complete = nil
|
185
|
-
|
186
|
-
if interface
|
187
|
-
interface.preparing_to_download( File.basename( filepath ), url, est_size )
|
188
|
-
end
|
189
|
-
|
190
|
-
progress_total = est_size ? est_size : 100000000 # pretend 100MB if no size
|
191
|
-
pbar = ProgressBar.new( "Status", progress_total, STDOUT )
|
192
|
-
pbar.bar_mark = "="
|
193
|
-
pbar.format = "%-6s %3d%% %s %s"
|
194
|
-
pbar.file_transfer_mode if est_size
|
195
|
-
|
196
|
-
progress_proc = proc { |posit| pbar.set(posit) }
|
197
|
-
|
198
|
-
STDOUT.sync = true
|
199
|
-
begin
|
200
|
-
local_file = File.open( filepath, 'wb' )
|
201
|
-
remote_file = open( url, :progress_proc => progress_proc )
|
202
|
-
local_file << remote_file.read
|
203
|
-
rescue
|
204
|
-
pbar.halt
|
205
|
-
download_complete = nil
|
206
|
-
raise
|
207
|
-
else
|
208
|
-
pbar.finish
|
209
|
-
download_complete = filepath
|
210
|
-
ensure
|
211
|
-
remote_file.close unless remote_file.nil?
|
212
|
-
local_file.close unless local_file.nil?
|
213
|
-
STDOUT.sync = false
|
214
|
-
end
|
215
|
-
|
216
|
-
unless checksum.empty?
|
217
|
-
raise ChecksumError if compute_checksum(filepath) != checksum
|
218
|
-
end
|
219
|
-
|
220
|
-
if interface
|
221
|
-
if checksum.empty?
|
222
|
-
interface.lacks_checksum( compute_checksum(filepath), :md5 )
|
223
|
-
end
|
224
|
-
unless est_size
|
225
|
-
interface.lacks_size( File.size(filepath) )
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
if download_complete
|
230
|
-
if interface
|
231
|
-
interface.downloaded( filepath )
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
return download_complete
|
236
|
-
end
|
237
|
-
|
238
|
-
# compute_checksum
|
239
|
-
|
240
|
-
def compute_checksum( local_path )
|
241
|
-
if File.exists?( local_path )
|
242
|
-
File.open( local_path ) do |local_file|
|
243
|
-
return Digest::MD5.new( local_file.read ).hexdigest
|
244
|
-
end
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
# extract
|
249
|
-
|
250
|
-
def extract( local_path )
|
251
|
-
success = false
|
252
|
-
local_dir = File.dirname(local_path)
|
253
|
-
local_file = File.basename(local_path)
|
254
|
-
current_dir = Dir.getwd
|
255
|
-
begin
|
256
|
-
Dir.chdir(local_dir)
|
257
|
-
case local_file
|
258
|
-
when /.*gz$/
|
259
|
-
system "tar -xzf #{local_file}"
|
260
|
-
when /.*bz2$/
|
261
|
-
system "tar -xjf #{local_file}"
|
262
|
-
when /.zip$/
|
263
|
-
system "unzip #{local_file}"
|
264
|
-
else
|
265
|
-
success = false
|
266
|
-
end
|
267
|
-
rescue
|
268
|
-
success = false
|
269
|
-
else
|
270
|
-
success = true
|
271
|
-
ensure
|
272
|
-
Dir.chdir(current_dir)
|
273
|
-
end
|
274
|
-
if interface
|
275
|
-
interface.extracted( local_path)
|
276
|
-
end
|
277
|
-
return success
|
278
|
-
end
|
279
|
-
|
280
|
-
end
|
281
|
-
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# = Duplicable
|
2
|
-
#
|
3
|
-
# This is not a mixin, since nearly all objects have this baehavior.
|
4
|
-
#
|
5
|
-
# Is this the same as immutable? Whould that be a better name?
|
6
|
-
|
7
|
-
class Object
|
8
|
-
# Can you safely .dup this object?
|
9
|
-
# False for nil, false, true, symbols, and numbers; true otherwise.
|
10
|
-
def duplicable?
|
11
|
-
true
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class NilClass #:nodoc:
|
16
|
-
def duplicable?
|
17
|
-
false
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class FalseClass #:nodoc:
|
22
|
-
def duplicable?
|
23
|
-
false
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class TrueClass #:nodoc:
|
28
|
-
def duplicable?
|
29
|
-
false
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class Symbol #:nodoc:
|
34
|
-
def duplicable?
|
35
|
-
false
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
class Numeric #:nodoc:
|
40
|
-
def duplicable?
|
41
|
-
false
|
42
|
-
end
|
43
|
-
end
|