facets 2.6.0 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/lib/more/facets/censor.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
# = TITLE:
|
2
|
-
#
|
3
|
-
# Censor
|
4
|
-
#
|
5
|
-
# = DESCRIPTION:
|
6
|
-
#
|
7
|
-
# Reusable class for filtering and rewriting strings.
|
8
|
-
#
|
9
|
-
# = AUTHORS:
|
10
|
-
#
|
11
|
-
# - George Moschovitis
|
12
|
-
# - Trans
|
13
|
-
#
|
14
|
-
|
15
|
-
# = Censor
|
16
|
-
#
|
17
|
-
# Formaly known as TextFilter, this class allows one to define a
|
18
|
-
# resuable text filter. This is useful for removing or replacing
|
19
|
-
# cursewords or senstive information from user input.
|
20
|
-
#
|
21
|
-
class Censor
|
22
|
-
|
23
|
-
# Abritraty rules.
|
24
|
-
attr :rules
|
25
|
-
|
26
|
-
# Word-oriented rules.
|
27
|
-
attr :word_rules
|
28
|
-
|
29
|
-
# New Censor object.
|
30
|
-
#
|
31
|
-
def initialize()
|
32
|
-
@rules = []
|
33
|
-
@word_rules = []
|
34
|
-
end
|
35
|
-
|
36
|
-
# Create new rule. A rule consists of a string or regexp
|
37
|
-
# to match against.
|
38
|
-
#
|
39
|
-
# NOTE: The rules must be applied in order! So we cannot
|
40
|
-
# use a hash because the ordering is not guaranteed. So
|
41
|
-
# an array is used instead.
|
42
|
-
#
|
43
|
-
def rule(match, &edit)
|
44
|
-
edit = lambda{''} unless edit
|
45
|
-
@rules << [match, edit]
|
46
|
-
end
|
47
|
-
|
48
|
-
# Rules that apply only to words. This takes the regular
|
49
|
-
# expression and add word boundry matches to either side.
|
50
|
-
#
|
51
|
-
# filter.word_rule(/damn/){ |w| 'darn' }
|
52
|
-
#
|
53
|
-
# Is equivalent to teh regular rule:
|
54
|
-
#
|
55
|
-
# filter.rule(/\bdamn\b/){ |w| 'darn' }
|
56
|
-
#
|
57
|
-
def word_rule(match, &edit)
|
58
|
-
edit = lambda{''} unless edit
|
59
|
-
@word_rules << [/\b#{match}\b/, edit]
|
60
|
-
end
|
61
|
-
|
62
|
-
# Apply the set of rules (regular expression matches) to
|
63
|
-
# a string.
|
64
|
-
#
|
65
|
-
def filter(string)
|
66
|
-
rewritten_string = string.dup
|
67
|
-
rules.each do |match,edit|
|
68
|
-
rewritten_string.gsub!(match,edit)
|
69
|
-
end
|
70
|
-
return (rewritten_string or string)
|
71
|
-
end
|
72
|
-
|
73
|
-
alias_method :apply, :filter
|
74
|
-
|
75
|
-
# Is the string clear of any matching rules?
|
76
|
-
#
|
77
|
-
# Note that running a filter does not necessarily clear a
|
78
|
-
# a string of all matches, since the filter could apply
|
79
|
-
# edits that would also match the filter expressions.
|
80
|
-
#
|
81
|
-
def censored?(string)
|
82
|
-
case string
|
83
|
-
when *matches
|
84
|
-
false
|
85
|
-
else
|
86
|
-
true
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
#
|
91
|
-
#
|
92
|
-
def matches
|
93
|
-
rules.collect{ |match, modify| match }
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
|
@@ -1,199 +0,0 @@
|
|
1
|
-
# = ClassMethods
|
2
|
-
#
|
3
|
-
# Miniframework provides a very convenient way to have modules
|
4
|
-
# pass along class methods in the inheritance chain.
|
5
|
-
#
|
6
|
-
# An oddity of Ruby, when including modules, class/module methods
|
7
|
-
# are not inherited. To achieve this behavior requires some clever
|
8
|
-
# Ruby Karate. Instead ClassMethods provides an easy to use and clean
|
9
|
-
# solution. Simply place the class inheritable methods in a block of
|
10
|
-
# the special module method #ClassMetods.
|
11
|
-
#
|
12
|
-
# module Mix
|
13
|
-
# def inst_meth
|
14
|
-
# puts 'inst_meth'
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# class_methods do
|
18
|
-
# def class_meth
|
19
|
-
# "Class Method!"
|
20
|
-
# end
|
21
|
-
# end
|
22
|
-
# end
|
23
|
-
#
|
24
|
-
# class X
|
25
|
-
# include Mix
|
26
|
-
# end
|
27
|
-
#
|
28
|
-
# X.class_meth #=> "Class Method!"
|
29
|
-
#
|
30
|
-
# This is equivalent to the original (but still functional) techinique of
|
31
|
-
# putting the class/module methods in a nested ClassMethods module
|
32
|
-
# and extending the original module *manually*. Eg.
|
33
|
-
#
|
34
|
-
# module Mix
|
35
|
-
# def inst_meth
|
36
|
-
# puts 'inst_meth'
|
37
|
-
# end
|
38
|
-
#
|
39
|
-
# module ClassMethods
|
40
|
-
# def class_meth
|
41
|
-
# "Class Method!"
|
42
|
-
# end
|
43
|
-
# end
|
44
|
-
#
|
45
|
-
# extend ClassMethods
|
46
|
-
# end
|
47
|
-
#
|
48
|
-
# class X
|
49
|
-
# include Mix
|
50
|
-
# end
|
51
|
-
#
|
52
|
-
# X.class_meth #=> "Class Method!"
|
53
|
-
#
|
54
|
-
# Also note that #class_inherit is an available alias
|
55
|
-
# for #class_methods for the sake of backward compatability.
|
56
|
-
# And #class_extension is alias (potentially) looking forward
|
57
|
-
# to a future version on Ruby.
|
58
|
-
#
|
59
|
-
# == On Topic
|
60
|
-
#
|
61
|
-
# Just a quick comment on the need for this behavior.
|
62
|
-
#
|
63
|
-
# A module is an encapsulation of code, hence when a module is included
|
64
|
-
# (or extends), the module itself should have discretion over how it
|
65
|
-
# effects the receiving class/module. That is the very embodiment of
|
66
|
-
# encapsulation. Having it otherwise, as Ruby now does, stymies the
|
67
|
-
# practice --and we end up with "hacks", like this and ClassMethods,
|
68
|
-
# to compensate.
|
69
|
-
#
|
70
|
-
# Ruby would be much improved by making this bevaivor standard.
|
71
|
-
# And making non-inheritance the exception, which is alwasy easy
|
72
|
-
# enough to achieve: put the code in a separate (and thus uninherited)
|
73
|
-
# module.
|
74
|
-
#
|
75
|
-
# == Notes
|
76
|
-
#
|
77
|
-
# * There are currently two approaches to this, ClassMethods and class_extensions.
|
78
|
-
# A third is being worked on called Component with the idea that a "component"
|
79
|
-
# is like a module except that it's class-level methods are mixed-in as well.
|
80
|
-
# This is an idea solution, however it is less that ideal to implement.
|
81
|
-
#
|
82
|
-
# == History
|
83
|
-
#
|
84
|
-
# Thanks to Nobu and Ulysses for their original work on this.
|
85
|
-
#
|
86
|
-
# == Authors
|
87
|
-
#
|
88
|
-
# * Nobu Nakada
|
89
|
-
# * Thomas Sawyer
|
90
|
-
# * Ulysses
|
91
|
-
#
|
92
|
-
# == Copying
|
93
|
-
#
|
94
|
-
# Copyright (c) 2005 Nobu Nakada, Thomas Sawyer
|
95
|
-
#
|
96
|
-
# Ruby License
|
97
|
-
#
|
98
|
-
# This module is free software. You may use, modify, and/or redistribute this
|
99
|
-
# software under the same terms as Ruby.
|
100
|
-
#
|
101
|
-
# This program is distributed in the hope that it will be useful, but WITHOUT
|
102
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
103
|
-
# FOR A PARTICULAR PURPOSE.
|
104
|
-
|
105
|
-
|
106
|
-
# = ClassMethods
|
107
|
-
#
|
108
|
-
# ClassMethods provides an easy to use and clean
|
109
|
-
# solution. Simply place the class inheritable methods in a block of
|
110
|
-
# the special module method #ClassMetods.
|
111
|
-
#
|
112
|
-
# module Mix
|
113
|
-
# def inst_meth
|
114
|
-
# puts 'inst_meth'
|
115
|
-
# end
|
116
|
-
#
|
117
|
-
# class_methods do
|
118
|
-
# def class_meth
|
119
|
-
# "Class Method!"
|
120
|
-
# end
|
121
|
-
# end
|
122
|
-
# end
|
123
|
-
#
|
124
|
-
# class X
|
125
|
-
# include Mix
|
126
|
-
# end
|
127
|
-
#
|
128
|
-
# X.class_meth #=> "Class Method!"
|
129
|
-
#
|
130
|
-
# This is equivalent to the original (but still functional) techinique of
|
131
|
-
# putting the class/module methods in a nested ClassMethods module
|
132
|
-
# and extending the original module *manually*. Eg.
|
133
|
-
#
|
134
|
-
# module Mix
|
135
|
-
# def inst_meth
|
136
|
-
# puts 'inst_meth'
|
137
|
-
# end
|
138
|
-
#
|
139
|
-
# module ClassMethods
|
140
|
-
# def class_meth
|
141
|
-
# "Class Method!"
|
142
|
-
# end
|
143
|
-
# end
|
144
|
-
#
|
145
|
-
# extend ClassMethods
|
146
|
-
# end
|
147
|
-
#
|
148
|
-
# class X
|
149
|
-
# include Mix
|
150
|
-
# end
|
151
|
-
#
|
152
|
-
# X.class_meth #=> "Class Method!"
|
153
|
-
#
|
154
|
-
# Also note that #class_inherit is an available alias
|
155
|
-
# for #class_methods for the sake of backward compatability.
|
156
|
-
# And #class_extension is alias (potentially) looking forward
|
157
|
-
# to a future version on Ruby.
|
158
|
-
|
159
|
-
class Module
|
160
|
-
|
161
|
-
alias_method :append_features_without_classmethods, :append_features
|
162
|
-
|
163
|
-
def append_features( base )
|
164
|
-
result = append_features_without_classmethods( base )
|
165
|
-
if const_defined?( :ClassMethods )
|
166
|
-
base.extend( self::ClassMethods )
|
167
|
-
unless base.is_a?( Class )
|
168
|
-
unless base.const_defined?( :ClassMethods )
|
169
|
-
base.const_set( :ClassMethods, Module.new )
|
170
|
-
end
|
171
|
-
my = self
|
172
|
-
base::ClassMethods.class_eval do
|
173
|
-
include my::ClassMethods
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
result
|
178
|
-
end
|
179
|
-
|
180
|
-
def class_methods( &yld )
|
181
|
-
if const_defined?( :ClassMethods )
|
182
|
-
self::ClassMethods.class_eval( &yld )
|
183
|
-
else
|
184
|
-
self.const_set( :ClassMethods, Module.new( &yld ) )
|
185
|
-
end
|
186
|
-
extend( self::ClassMethods )
|
187
|
-
self::ClassMethods
|
188
|
-
end
|
189
|
-
|
190
|
-
# For compatibility with old rendition.
|
191
|
-
alias_method :class_inherit, :class_methods
|
192
|
-
|
193
|
-
end
|
194
|
-
|
195
|
-
class Class
|
196
|
-
undef_method :class_methods
|
197
|
-
undef_method :class_inherit
|
198
|
-
end
|
199
|
-
|
@@ -1,99 +0,0 @@
|
|
1
|
-
warn "WARNING: facets/consoleutils.rb will be deprecated. Use alternate solution, such as Clio, for future versions."
|
2
|
-
|
3
|
-
# = ConsoleUtils
|
4
|
-
#
|
5
|
-
# ConsoleUtils provides methods that are
|
6
|
-
# generally useful in the context of
|
7
|
-
# creating console output.
|
8
|
-
#
|
9
|
-
module ConsoleUtils
|
10
|
-
|
11
|
-
module_function
|
12
|
-
|
13
|
-
# Convenient method to get simple console reply.
|
14
|
-
|
15
|
-
def ask(question, answers=nil)
|
16
|
-
print "#{question}"
|
17
|
-
print " [#{answers}] " if answers
|
18
|
-
until inp = $stdin.gets ; sleep 1 ; end
|
19
|
-
inp
|
20
|
-
end
|
21
|
-
|
22
|
-
# Convenience method for puts. Use this instead of
|
23
|
-
# puts when the output should be supressed if the
|
24
|
-
# global $QUIET option is set.
|
25
|
-
|
26
|
-
#def say(statement)
|
27
|
-
# puts statement #unless quiet? $QUIET
|
28
|
-
#end
|
29
|
-
|
30
|
-
# Ask for a password. (FIXME: only for unix so far)
|
31
|
-
|
32
|
-
def password(msg=nil)
|
33
|
-
msg ||= "Enter Password: "
|
34
|
-
inp = ''
|
35
|
-
|
36
|
-
$stdout << msg
|
37
|
-
|
38
|
-
begin
|
39
|
-
system "stty -echo"
|
40
|
-
inp = gets.chomp
|
41
|
-
ensure
|
42
|
-
system "stty echo"
|
43
|
-
end
|
44
|
-
|
45
|
-
return inp
|
46
|
-
end
|
47
|
-
|
48
|
-
# Console screen width (taken from progress bar)
|
49
|
-
#
|
50
|
-
# TODO: Don't know how portable #screen_width is.
|
51
|
-
|
52
|
-
def screen_width(out=STDERR)
|
53
|
-
default_width = ENV['COLUMNS'] || 80
|
54
|
-
begin
|
55
|
-
tiocgwinsz = 0x5413
|
56
|
-
data = [0, 0, 0, 0].pack("SSSS")
|
57
|
-
if out.ioctl(tiocgwinsz, data) >= 0 then
|
58
|
-
rows, cols, xpixels, ypixels = data.unpack("SSSS")
|
59
|
-
if cols >= 0 then cols else default_width end
|
60
|
-
else
|
61
|
-
default_width
|
62
|
-
end
|
63
|
-
rescue Exception
|
64
|
-
default_width
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
# Print a justified line with left and right entries.
|
69
|
-
#
|
70
|
-
# A fill option can be given to fill in any empty space
|
71
|
-
# between the two. And a ratio option can be given which defaults
|
72
|
-
# to 0.8 (eg. 80/20)
|
73
|
-
|
74
|
-
def print_justified(left, right, options={})
|
75
|
-
fill = options[:fill] || '.'
|
76
|
-
fill = ' ' if fill == ''
|
77
|
-
fill = fill[0,1]
|
78
|
-
|
79
|
-
ratio = options[:ratio] || 0.8
|
80
|
-
ratio = 1 + ratio if ratio < 0
|
81
|
-
|
82
|
-
width = (@screen_width ||= screen_width) - 1
|
83
|
-
|
84
|
-
#l = (width * ratio).to_i
|
85
|
-
r = (width * (1 - ratio)).to_i
|
86
|
-
l = width - r
|
87
|
-
|
88
|
-
left = left[0,l]
|
89
|
-
right = right[0,r]
|
90
|
-
|
91
|
-
str = fill * width
|
92
|
-
str[0,left.size] = left
|
93
|
-
str[width-right.size,right.size] = right
|
94
|
-
|
95
|
-
print str
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
|
data/lib/more/facets/crypt.rb
DELETED
@@ -1,166 +0,0 @@
|
|
1
|
-
# = Crypt
|
2
|
-
#
|
3
|
-
# A pure ruby version of crypt(3), a salted one-way hashing of a password.
|
4
|
-
#
|
5
|
-
# == History
|
6
|
-
#
|
7
|
-
# Adapted by guillaume__dot__pierronnet_at__laposte__dot_net based on
|
8
|
-
# * http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/325204/index_txt
|
9
|
-
# which is based on FreeBSD src/lib/libcrypt/crypt.c 1.2
|
10
|
-
# * http://www.freebsd.org/cgi/cvsweb.cgi/~checkout~/src/lib/libcrypt/crypt.c?rev=1.2&content-type=text/plain
|
11
|
-
#
|
12
|
-
# [Original License]
|
13
|
-
#
|
14
|
-
# "THE BEER-WARE LICENSE" (Revision 42):
|
15
|
-
# <phk@login.dknet.dk> wrote this file. As long as you retain this notice you
|
16
|
-
# can do whatever you want with this stuff. If we meet some day, and you think
|
17
|
-
# this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
18
|
-
#
|
19
|
-
# == Authors
|
20
|
-
#
|
21
|
-
# * Poul-Henning Kamp
|
22
|
-
#
|
23
|
-
# == Copying
|
24
|
-
#
|
25
|
-
# Copyright (c) 2002 Poul-Henning Kamp
|
26
|
-
#
|
27
|
-
# Ruby License
|
28
|
-
#
|
29
|
-
# This module is free software. You may use, modify, and/or redistribute this
|
30
|
-
# software under the same terms as Ruby.
|
31
|
-
#
|
32
|
-
# This program is distributed in the hope that it will be useful, but WITHOUT
|
33
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
34
|
-
# FOR A PARTICULAR PURPOSE.
|
35
|
-
|
36
|
-
require 'facets/string/xor.rb'
|
37
|
-
|
38
|
-
# = Crypt
|
39
|
-
#
|
40
|
-
# A pure ruby version of crypt(3), a salted one-way hashing of a password.
|
41
|
-
#
|
42
|
-
module Crypt
|
43
|
-
|
44
|
-
ITOA64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
45
|
-
|
46
|
-
# A pure ruby version of crypt(3), a salted one-way hashing of a password.
|
47
|
-
#
|
48
|
-
# Supported hashing algorithms are: md5, sha1, sha256, sha384, sha512, rmd160.
|
49
|
-
#
|
50
|
-
# Only the md5 hashing algorithm is standard and compatible with crypt(3), the others
|
51
|
-
# are not standard.
|
52
|
-
#
|
53
|
-
# Automatically generate a 8-bytes salt if nil.
|
54
|
-
#
|
55
|
-
# Output a length hashed and salted string with size of
|
56
|
-
# magic.size + salt.size + 23.
|
57
|
-
|
58
|
-
def self.crypt(password, algo = :md5, salt = nil, magic='$1$')
|
59
|
-
|
60
|
-
salt ||= generate_salt(8)
|
61
|
-
|
62
|
-
case algo
|
63
|
-
when :md5
|
64
|
-
require "digest/md5"
|
65
|
-
when :sha1
|
66
|
-
require "digest/sha1"
|
67
|
-
when :rmd160
|
68
|
-
require "digest/rmd160"
|
69
|
-
when :sha256, :sha384, :sha512
|
70
|
-
require "digest/sha2"
|
71
|
-
else
|
72
|
-
raise(ArgumentError, "unknown algorithm")
|
73
|
-
end
|
74
|
-
digest_class = Digest.const_get(algo.to_s.upcase)
|
75
|
-
|
76
|
-
# The password first, since that is what is most unknown. Then our magic string. Then the raw salt.
|
77
|
-
m = digest_class.new
|
78
|
-
m.update(password + magic + salt)
|
79
|
-
|
80
|
-
# Then just as many characters of the MD5(pw,salt,pw)
|
81
|
-
mixin = digest_class.new.update(password + salt + password).digest
|
82
|
-
password.length.times do |i|
|
83
|
-
m.update(mixin[i % 16].chr)
|
84
|
-
end
|
85
|
-
|
86
|
-
# Then something really weird...
|
87
|
-
# Also really broken, as far as I can tell. -m
|
88
|
-
i = password.length
|
89
|
-
while i != 0
|
90
|
-
if (i & 1) != 0
|
91
|
-
m.update("\x00")
|
92
|
-
else
|
93
|
-
m.update(password[0].chr)
|
94
|
-
end
|
95
|
-
i >>= 1
|
96
|
-
end
|
97
|
-
|
98
|
-
final = m.digest
|
99
|
-
|
100
|
-
# and now, just to make sure things don't run too fast
|
101
|
-
1000.times do |i|
|
102
|
-
m2 = digest_class.new
|
103
|
-
|
104
|
-
if (i & 1) != 0
|
105
|
-
m2.update(password)
|
106
|
-
else
|
107
|
-
m2.update(final)
|
108
|
-
end
|
109
|
-
|
110
|
-
if (i % 3) != 0
|
111
|
-
m2.update(salt)
|
112
|
-
end
|
113
|
-
if (i % 7) != 0
|
114
|
-
m2.update(password)
|
115
|
-
end
|
116
|
-
|
117
|
-
if (i & 1) != 0
|
118
|
-
m2.update(final)
|
119
|
-
else
|
120
|
-
m2.update(password)
|
121
|
-
end
|
122
|
-
|
123
|
-
final = m2.digest
|
124
|
-
end
|
125
|
-
|
126
|
-
# This is the bit that uses to64() in the original code.
|
127
|
-
|
128
|
-
rearranged = ""
|
129
|
-
|
130
|
-
[ [0, 6, 12], [1, 7, 13], [2, 8, 14], [3, 9, 15], [4, 10, 5] ].each do |a, b, c|
|
131
|
-
|
132
|
-
v = final[a] << 16 | final[b] << 8 | final[c]
|
133
|
-
|
134
|
-
4.times do
|
135
|
-
rearranged += ITOA64[v & 0x3f].chr
|
136
|
-
v >>= 6
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
v = final[11]
|
141
|
-
|
142
|
-
2.times do
|
143
|
-
rearranged += ITOA64[v & 0x3f].chr
|
144
|
-
v >>= 6
|
145
|
-
end
|
146
|
-
|
147
|
-
magic + salt + '$' + rearranged
|
148
|
-
end
|
149
|
-
|
150
|
-
|
151
|
-
# check the validity of a password against an hashed string
|
152
|
-
|
153
|
-
def self.check(password, hash, algo = :md5)
|
154
|
-
magic, salt = hash.split('$')[1,2]
|
155
|
-
magic = '$' + magic + '$'
|
156
|
-
self.crypt(password, algo, salt, magic) == hash
|
157
|
-
end
|
158
|
-
|
159
|
-
|
160
|
-
# generate a +size+ length random salt
|
161
|
-
|
162
|
-
def self.generate_salt(size)
|
163
|
-
(1..size).collect { ITOA64[rand(ITOA64.size)].chr }.join("")
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|