mack-facets 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gems.rb +25 -0
- data/lib/gems/english-0.3.1/VERSION +1 -0
- data/lib/gems/english-0.3.1/lib/english/array.rb +48 -0
- data/lib/gems/english-0.3.1/lib/english/censor.rb +76 -0
- data/lib/gems/english-0.3.1/lib/english/double_metaphone.rb +353 -0
- data/lib/gems/english-0.3.1/lib/english/dresner.rb +47 -0
- data/lib/gems/english-0.3.1/lib/english/inflect.rb +299 -0
- data/lib/gems/english-0.3.1/lib/english/jumble.rb +37 -0
- data/lib/gems/english-0.3.1/lib/english/levenshtein.rb +78 -0
- data/lib/gems/english-0.3.1/lib/english/metaphone.rb +110 -0
- data/lib/gems/english-0.3.1/lib/english/numerals.rb +71 -0
- data/lib/gems/english-0.3.1/lib/english/patterns.rb +49 -0
- data/lib/gems/english-0.3.1/lib/english/porter_stemming.rb +188 -0
- data/lib/gems/english-0.3.1/lib/english/roman.rb +174 -0
- data/lib/gems/english-0.3.1/lib/english/similarity.rb +103 -0
- data/lib/gems/english-0.3.1/lib/english/soundex.rb +70 -0
- data/lib/gems/english-0.3.1/lib/english/string.rb +210 -0
- data/lib/gems/english-0.3.1/lib/english/style.rb +294 -0
- data/lib/gems/english-0.3.1/lib/english/style_orm.rb +143 -0
- data/lib/gems/english-0.3.1/lib/english/textfilter.rb +91 -0
- data/lib/gems/extlib-0.9.8/lib/extlib.rb +56 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/assertions.rb +8 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/blank.rb +59 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/boolean.rb +11 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/class.rb +175 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/datetime.rb +9 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/dictionary.rb +433 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/hash.rb +419 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/hook.rb +366 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/inflection.rb +435 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/lazy_array.rb +106 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/logger.rb +202 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/mash.rb +148 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/module.rb +41 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/nil.rb +5 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/numeric.rb +5 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/object.rb +175 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/object_space.rb +13 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/pathname.rb +5 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/pooling.rb +239 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/rubygems.rb +38 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/simple_set.rb +39 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/string.rb +132 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/struct.rb +8 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/symbol.rb +17 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/tasks/release.rb +15 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/time.rb +19 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/version.rb +3 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/virtual_file.rb +10 -0
- data/lib/gems/facets-2.4.5/VERSION +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets-live.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets-load.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets.rb +11 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/combination.rb +59 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/conjoin.rb +58 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/delete.rb +61 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/index.rb +48 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/indexable.rb +73 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/merge.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/not_empty.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/only.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/pad.rb +41 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/permutation.rb +30 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/product.rb +57 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/recursively.rb +30 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/rotate.rb +42 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/select.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/splice.rb +30 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/stackable.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/traverse.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/binding.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/binding/caller.rb +54 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/binding/defined.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/binding/eval.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/binding/local_variables.rb +15 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/binding/self.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/bitmask.rb +104 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/blank.rb +60 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/boolean.rb +156 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/callstack.rb +52 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/cattr.rb +2 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/cattr.rb +115 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/cattr_accessor.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/cattr_reader.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/cattr_writer.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/descendents.rb +36 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/methodize.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/pathize.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/prepend.rb +50 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/subclasses.rb +2 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/to_proc.rb +42 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/comparable.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/comparable/bound.rb +65 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/comparable/cmp.rb +38 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/comparable/comparable.rb +42 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/dir.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/dir/ascend.rb +59 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/dir/descend.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/dir/multiglob.rb +92 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/dir/parent.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/dir/recurse.rb +29 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/accumulate.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/cluster_by.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/collect.rb +54 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/commonality.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/count.rb +26 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/divide.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/duplicates.rb +38 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/each_by.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/entropy.rb +37 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/frequency.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/group_by.rb +27 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/inject.rb +31 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/map_send.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/mash.rb +32 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/mode.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/modulate.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/none.rb +31 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/occur.rb +38 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/one.rb +38 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/probability.rb +36 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/split.rb +27 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/sum.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/uniq_by.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/exception.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/exception/detail.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/exception/suppress.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/append.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/create.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/null.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/read.rb +41 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/rewrite.rb +88 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/rootname.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/split_root.rb +10 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/write.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/writelines.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/filetest.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/filetest/root.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/float.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/float/round.rb +2 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/functor.rb +77 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/alias.rb +31 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/argumentize.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/at.rb +8 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/autonew.rb +42 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/collate.rb +45 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/delete.rb +47 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/diff.rb +11 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/except.rb +27 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/insert.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/inverse.rb +27 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/join.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/keys.rb +45 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/mash.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/merge.rb +30 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/op.rb +7 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/op_add.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/op_and.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/op_mul.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/op_or.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/op_push.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/op_sub.rb +26 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/recursive_merge.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/recursively.rb +29 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/rekey.rb +59 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/select.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/slice.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/swap.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/to_h.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/to_proc.rb +41 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/to_struct.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/traverse.rb +41 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/update.rb +81 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/weave.rb +81 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/zipnew.rb +2 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/indexable.rb +251 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/integer.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/integer/even.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/integer/factorial.rb +30 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/integer/multiple.rb +15 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/integer/odd.rb +35 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/integer/of.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/integer/ordinal.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/__callee__.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/__class__.rb +9 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/__dir__.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/__get__.rb +10 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/__method__.rb +36 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/__set__.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/as.rb +100 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/ask.rb +27 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/attr_singleton.rb +62 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/complete.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/constant.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/d.rb +26 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/deep_copy.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/demo.rb +23 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/ergo.rb +42 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/here.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/in.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/instance.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/instance_assign.rb +41 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/instance_class.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/instance_exec.rb +40 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/instance_send.rb +7 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/instance_variables.rb +99 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/maybe.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/not_nil.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/object_class.rb +10 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/object_hexid.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/object_send.rb +32 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/p.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/populate.rb +73 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/qua_class.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/require_all.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/require_local.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/resc.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/respond.rb +23 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/returning.rb +23 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/silence.rb +75 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/singleton_class.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/tap.rb +32 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/try.rb +23 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/val.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/with.rb +20 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/lazy.rb +238 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/matchdata.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/matchdata/match.rb +15 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/matchdata/matchset.rb +44 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/metaid.rb +94 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/abstract.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/alias_accessor.rb +45 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/alias_method_chain.rb +50 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/alias_module_function.rb +30 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/ancestor.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/basename.rb +31 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/can.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/class.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/conflict.rb +63 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/include_function_module.rb +25 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/instance_methods.rb +40 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/integrate.rb +2 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/is.rb +57 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/methodize.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/modspace.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/module_load.rb +56 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/nesting.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/op.rb +95 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/pathize.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/prepend.rb +26 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/redefine_method.rb +35 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/redirect_method.rb +45 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/rename_method.rb +20 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/revise.rb +62 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/spacename.rb +25 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/wrap_method.rb +28 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/nilclass.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/nilclass/ergo.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/nilclass/to_f.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/numeric.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/numeric/approx.rb +15 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/numeric/distance.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/numeric/round.rb +72 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/proc.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/proc/bind.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/proc/compose.rb +42 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/proc/curry.rb +31 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/proc/to_method.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/proc/update.rb +9 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/range.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/range/combine.rb +47 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/range/overlap.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/range/to_r.rb +26 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/range/umbrella.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/range/within.rb +66 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/regexp.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/regexp/arity.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/regexp/to_re.rb +28 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/stackable.rb +86 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/align.rb +106 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/bracket.rb +105 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/bytes.rb +15 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/camelcase.rb +26 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/capitalized.rb +46 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/chars.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/chomp.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/cleave.rb +36 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/divide.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/each_char.rb +29 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/each_word.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/end_with.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/fold.rb +39 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/interpolate.rb +20 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/line_wrap.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/lines.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/methodize.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/modulize.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/mscan.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/natcmp.rb +88 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/nchar.rb +28 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/op_sub.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/pathize.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/range.rb +77 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/rewrite.rb +28 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/shatter.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/snakecase.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/splice.rb +37 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/start_with.rb +32 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/subtract.rb +4 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/tab.rb +103 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/titlecase.rb +15 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/to_re.rb +26 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/variablize.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/word_wrap.rb +34 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/words.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/xor.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/chomp.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/generate.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/not.rb +29 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/plain.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/query.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/re_s.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/setter.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/succ.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/to_proc.rb +38 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/variablize.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/advance.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/ago.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/change.rb +41 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/elapse.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/hence.rb +94 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/round.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/set.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/stamp.rb +44 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/to_time.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/trunc.rb +15 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/to_hash.rb +87 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/unboundmethod.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/unboundmethod/arguments.rb +44 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/unboundmethod/name.rb +25 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/basicobject.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/cgi.rb +50 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/continuation.rb +57 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/date.rb +396 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils.rb +27 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils/head.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils/safe_ln.rb +28 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils/slice.rb +141 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils/tail.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils/wc.rb +114 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils/whereis.rb +64 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils/which.rb +101 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/getoptlong.rb +71 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/logger.rb +291 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/ostruct.rb +238 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/pathname.rb +172 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/rbconfig.rb +45 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/set.rb +27 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/shellwords.rb +89 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/uri.rb +249 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/yaml.rb +75 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/zlib.rb +38 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/1stclassmethod.rb +140 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/advisable.rb +162 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/annotations.rb +302 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/ansicode.rb +315 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/arguments.rb +365 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/argvector.rb +353 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/association.rb +194 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/attr.rb +208 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/autoarray.rb +62 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/autoreload.rb +150 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/basex.rb +37 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/bbcode.rb +397 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/bicrypt.rb +265 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/binding/opvars.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/binreadable.rb +221 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/blankslate.rb +66 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/buildable.rb +344 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/bytes.rb +175 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/cachedecorator.rb +117 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/capsule.rb +258 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/chain.rb +58 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/class_extension.rb +114 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/classmethods.rb +199 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/cloneable.rb +76 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/command.rb +439 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/consoleutils.rb +113 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/coroutine.rb +159 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/crypt.rb +166 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/cssfilter.rb +254 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/daemonize.rb +44 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/dependency.rb +151 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/dictionary.rb +478 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/dictionarymatcher.rb +136 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/downloader.rb +281 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/duplicable.rb +43 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/duration.rb +540 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/elementor.rb +133 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/elementwise.rb +61 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/enumerablepass.rb +217 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/equatable.rb +120 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/eventhook.rb +132 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/expirable.rb +82 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/fileable.rb +162 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/filelist.rb +497 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb +202 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/hash/stringify_keys.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/hash/symbolize_keys.rb +94 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/heap.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/htmlfilter.rb +595 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/infinity.rb +193 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/inheritor.rb +130 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/ini.rb +264 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/instantiable.rb +47 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/instantise.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/instantize.rb +95 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/interval.rb +282 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/ioredirect.rb +130 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/iteration.rb +65 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/kernel/meta.rb +32 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/linkedlist.rb +222 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/lrucache.rb +157 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/main.rb +70 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/memoize.rb +116 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/methodspace.rb +141 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/minitar.rb +1063 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/multipliers.rb +109 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/multiton.rb +386 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/nackclass.rb +41 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/net/smtp_tls.rb +131 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/nilstatus.rb +47 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/nullclass.rb +74 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/opencascade.rb +94 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/opencollection.rb +43 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/openhash.rb +39 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/openobject.rb +267 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/opesc.rb +60 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/orderedhash.rb +37 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/overload.rb +94 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/paramix.rb +202 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/partial.rb +37 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/pathlist.rb +112 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/platform.rb +192 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/pool.rb +91 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/pqueue.rb +449 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/progressbar.rb +253 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/prototype.rb +88 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/random.rb +451 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/rbsystem.rb +222 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/recorder.rb +109 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/reference.rb +99 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/reflection.rb +145 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/registerable.rb +35 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/rwdelegator.rb +74 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/semaphore.rb +92 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/settings.rb +248 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/snapshot.rb +209 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/string/mask.rb +278 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/string/words.rb +173 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/succ.rb +44 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/syncarray.rb +114 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/synchash.rb +157 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/tagiter.rb +366 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/thread.rb +51 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/timer.rb +274 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/times.rb +431 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/tracepoint.rb +209 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/tuple.rb +325 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/typecast.rb +261 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/uninheritable.rb +50 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/uploadutils.rb +464 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/version.rb +136 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/xmlhash.rb +112 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/xoxo.rb +259 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/ziputils.rb +349 -0
- data/lib/mack-facets.rb +4 -2
- data/lib/mack-facets/english_extensions/inflect.rb +50 -50
- data/lib/mack-facets/extensions/string.rb +10 -1
- data/lib/mack-facets/utils/inflections.rb +50 -47
- data/lib/mack-facets/utils/inflector.rb +19 -19
- metadata +547 -36
@@ -0,0 +1,366 @@
|
|
1
|
+
module Extlib
|
2
|
+
#
|
3
|
+
# TODO: Write more documentation!
|
4
|
+
#
|
5
|
+
# Overview
|
6
|
+
# ========
|
7
|
+
#
|
8
|
+
# The Hook module is a very simple set of AOP helpers. Basically, it
|
9
|
+
# allows the developer to specify a method or block that should run
|
10
|
+
# before or after another method.
|
11
|
+
#
|
12
|
+
# Usage
|
13
|
+
# =====
|
14
|
+
#
|
15
|
+
# Halting The Hook Stack
|
16
|
+
#
|
17
|
+
# Inheritance
|
18
|
+
#
|
19
|
+
# Other Goodies
|
20
|
+
#
|
21
|
+
# Please bring up any issues regarding Hooks with carllerche on IRC
|
22
|
+
#
|
23
|
+
module Hook
|
24
|
+
|
25
|
+
def self.included(base)
|
26
|
+
base.extend(ClassMethods)
|
27
|
+
base.const_set("CLASS_HOOKS", {}) unless base.const_defined?("CLASS_HOOKS")
|
28
|
+
base.const_set("INSTANCE_HOOKS", {}) unless base.const_defined?("INSTANCE_HOOKS")
|
29
|
+
base.class_eval do
|
30
|
+
class << self
|
31
|
+
def method_added(name)
|
32
|
+
process_method_added(name, :instance)
|
33
|
+
end
|
34
|
+
|
35
|
+
def singleton_method_added(name)
|
36
|
+
process_method_added(name, :class)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module ClassMethods
|
43
|
+
include Extlib::Assertions
|
44
|
+
# Inject code that executes before the target class method.
|
45
|
+
#
|
46
|
+
# @param target_method<Symbol> the name of the class method to inject before
|
47
|
+
# @param method_sym<Symbol> the name of the method to run before the
|
48
|
+
# target_method
|
49
|
+
# @param block<Block> the code to run before the target_method
|
50
|
+
#
|
51
|
+
# @note
|
52
|
+
# Either method_sym or block is required.
|
53
|
+
# -
|
54
|
+
# @api public
|
55
|
+
def before_class_method(target_method, method_sym = nil, &block)
|
56
|
+
install_hook :before, target_method, method_sym, :class, &block
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# Inject code that executes after the target class method.
|
61
|
+
#
|
62
|
+
# @param target_method<Symbol> the name of the class method to inject after
|
63
|
+
# @param method_sym<Symbol> the name of the method to run after the target_method
|
64
|
+
# @param block<Block> the code to run after the target_method
|
65
|
+
#
|
66
|
+
# @note
|
67
|
+
# Either method_sym or block is required.
|
68
|
+
# -
|
69
|
+
# @api public
|
70
|
+
def after_class_method(target_method, method_sym = nil, &block)
|
71
|
+
install_hook :after, target_method, method_sym, :class, &block
|
72
|
+
end
|
73
|
+
|
74
|
+
#
|
75
|
+
# Inject code that executes before the target instance method.
|
76
|
+
#
|
77
|
+
# @param target_method<Symbol> the name of the instance method to inject before
|
78
|
+
# @param method_sym<Symbol> the name of the method to run before the
|
79
|
+
# target_method
|
80
|
+
# @param block<Block> the code to run before the target_method
|
81
|
+
#
|
82
|
+
# @note
|
83
|
+
# Either method_sym or block is required.
|
84
|
+
# -
|
85
|
+
# @api public
|
86
|
+
def before(target_method, method_sym = nil, &block)
|
87
|
+
install_hook :before, target_method, method_sym, :instance, &block
|
88
|
+
end
|
89
|
+
|
90
|
+
#
|
91
|
+
# Inject code that executes after the target instance method.
|
92
|
+
#
|
93
|
+
# @param target_method<Symbol> the name of the instance method to inject after
|
94
|
+
# @param method_sym<Symbol> the name of the method to run after the
|
95
|
+
# target_method
|
96
|
+
# @param block<Block> the code to run after the target_method
|
97
|
+
#
|
98
|
+
# @note
|
99
|
+
# Either method_sym or block is required.
|
100
|
+
# -
|
101
|
+
# @api public
|
102
|
+
def after(target_method, method_sym = nil, &block)
|
103
|
+
install_hook :after, target_method, method_sym, :instance, &block
|
104
|
+
end
|
105
|
+
|
106
|
+
# Register a class method as hookable. Registering a method means that
|
107
|
+
# before hooks will be run immediately before the method is invoked and
|
108
|
+
# after hooks will be called immediately after the method is invoked.
|
109
|
+
#
|
110
|
+
# @param hookable_method<Symbol> The name of the class method that should
|
111
|
+
# be hookable
|
112
|
+
# -
|
113
|
+
# @api public
|
114
|
+
def register_class_hooks(*hooks)
|
115
|
+
hooks.each { |hook| register_hook(hook, :class) }
|
116
|
+
end
|
117
|
+
|
118
|
+
# Register aninstance method as hookable. Registering a method means that
|
119
|
+
# before hooks will be run immediately before the method is invoked and
|
120
|
+
# after hooks will be called immediately after the method is invoked.
|
121
|
+
#
|
122
|
+
# @param hookable_method<Symbol> The name of the instance method that should
|
123
|
+
# be hookable
|
124
|
+
# -
|
125
|
+
# @api public
|
126
|
+
def register_instance_hooks(*hooks)
|
127
|
+
hooks.each { |hook| register_hook(hook, :instance) }
|
128
|
+
end
|
129
|
+
|
130
|
+
# Not yet implemented
|
131
|
+
def reset_hook!(target_method, scope)
|
132
|
+
raise NotImplementedError
|
133
|
+
end
|
134
|
+
|
135
|
+
# --- Alright kids... the rest is internal stuff ---
|
136
|
+
|
137
|
+
# Returns the correct HOOKS Hash depending on whether we are
|
138
|
+
# working with class methods or instance methods
|
139
|
+
def hooks_with_scope(scope)
|
140
|
+
case scope
|
141
|
+
when :class then class_hooks
|
142
|
+
when :instance then instance_hooks
|
143
|
+
else raise ArgumentError, 'You need to pass :class or :instance as scope'
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def class_hooks
|
148
|
+
self.const_get("CLASS_HOOKS")
|
149
|
+
end
|
150
|
+
|
151
|
+
def instance_hooks
|
152
|
+
self.const_get("INSTANCE_HOOKS")
|
153
|
+
end
|
154
|
+
|
155
|
+
# Registers a method as hookable. Registering hooks involves the following
|
156
|
+
# process
|
157
|
+
#
|
158
|
+
# * Create a blank entry in the HOOK Hash for the method.
|
159
|
+
# * Define the methods that execute the before and after hook stack.
|
160
|
+
# These methods will be no-ops at first, but everytime a new hook is
|
161
|
+
# defined, the methods will be redefined to incorporate the new hook.
|
162
|
+
# * Redefine the method that is to be hookable so that the hook stacks
|
163
|
+
# are invoked approprietly.
|
164
|
+
def register_hook(target_method, scope)
|
165
|
+
if scope == :instance && !method_defined?(target_method)
|
166
|
+
raise ArgumentError, "#{target_method} instance method does not exist"
|
167
|
+
elsif scope == :class && !respond_to?(target_method)
|
168
|
+
raise ArgumentError, "#{target_method} class method does not exist"
|
169
|
+
end
|
170
|
+
|
171
|
+
hooks = hooks_with_scope(scope)
|
172
|
+
|
173
|
+
if hooks[target_method].nil?
|
174
|
+
hooks[target_method] = {
|
175
|
+
# We need to keep track of which class in the Inheritance chain the
|
176
|
+
# method was declared hookable in. Every time a child declares a new
|
177
|
+
# hook for the method, the hook stack invocations need to be redefined
|
178
|
+
# in the original Class. See #define_hook_stack_execution_methods
|
179
|
+
:before => [], :after => [], :in => self
|
180
|
+
}
|
181
|
+
|
182
|
+
define_hook_stack_execution_methods(target_method, scope)
|
183
|
+
define_advised_method(target_method, scope)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
# Is the method registered as a hookable in the given scope.
|
188
|
+
def registered_as_hook?(target_method, scope)
|
189
|
+
! hooks_with_scope(scope)[target_method].nil?
|
190
|
+
end
|
191
|
+
|
192
|
+
# Generates names for the various utility methods. We need to do this because
|
193
|
+
# the various utility methods should not end in = so, while we're at it, we
|
194
|
+
# might as well get rid of all punctuation.
|
195
|
+
def hook_method_name(target_method, prefix, suffix)
|
196
|
+
target_method = target_method.to_s
|
197
|
+
|
198
|
+
case target_method[-1,1]
|
199
|
+
when '?' then "#{prefix}_#{target_method[0..-2]}_ques_#{suffix}"
|
200
|
+
when '!' then "#{prefix}_#{target_method[0..-2]}_bang_#{suffix}"
|
201
|
+
when '=' then "#{prefix}_#{target_method[0..-2]}_eq_#{suffix}"
|
202
|
+
# I add a _nan_ suffix here so that we don't ever encounter
|
203
|
+
# any naming conflicts.
|
204
|
+
else "#{prefix}_#{target_method[0..-1]}_nan_#{suffix}"
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
# This will need to be refactored
|
209
|
+
def process_method_added(method_name, scope)
|
210
|
+
hooks_with_scope(scope).each do |target_method, hooks|
|
211
|
+
if hooks[:before].any? { |hook| hook[:name] == method_name }
|
212
|
+
define_hook_stack_execution_methods(target_method, scope)
|
213
|
+
end
|
214
|
+
|
215
|
+
if hooks[:after].any? { |hook| hook[:name] == method_name }
|
216
|
+
define_hook_stack_execution_methods(target_method, scope)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
# Defines two methods. One method executes the before hook stack. The other executes
|
222
|
+
# the after hook stack. This method will be called many times during the Class definition
|
223
|
+
# process. It should be called for each hook that is defined. It will also be called
|
224
|
+
# when a hook is redefined (to make sure that the arity hasn't changed).
|
225
|
+
def define_hook_stack_execution_methods(target_method, scope)
|
226
|
+
unless registered_as_hook?(target_method, scope)
|
227
|
+
raise ArgumentError, "#{target_method} has not be registered as a hookable #{scope} method"
|
228
|
+
end
|
229
|
+
|
230
|
+
hooks = hooks_with_scope(scope)
|
231
|
+
|
232
|
+
before_hooks = hooks[target_method][:before]
|
233
|
+
before_hooks = before_hooks.map{ |info| inline_call(info, scope) }.join("\n")
|
234
|
+
|
235
|
+
after_hooks = hooks[target_method][:after]
|
236
|
+
after_hooks = after_hooks.map{ |info| inline_call(info, scope) }.join("\n")
|
237
|
+
|
238
|
+
source = %{
|
239
|
+
private
|
240
|
+
|
241
|
+
def #{hook_method_name(target_method, 'execute_before', 'hook_stack')}(*args)
|
242
|
+
#{before_hooks}
|
243
|
+
end
|
244
|
+
|
245
|
+
def #{hook_method_name(target_method, 'execute_after', 'hook_stack')}(*args)
|
246
|
+
#{after_hooks}
|
247
|
+
end
|
248
|
+
}
|
249
|
+
|
250
|
+
source = %{class << self\n#{source}\nend} if scope == :class
|
251
|
+
|
252
|
+
hooks[target_method][:in].class_eval(source, __FILE__, __LINE__)
|
253
|
+
end
|
254
|
+
|
255
|
+
# Returns ruby code that will invoke the hook. It checks the arity of the hook method
|
256
|
+
# and passes arguments accordingly.
|
257
|
+
def inline_call(method_info, scope)
|
258
|
+
name = method_info[:name]
|
259
|
+
|
260
|
+
if scope == :instance
|
261
|
+
args = method_defined?(name) && instance_method(name).arity != 0 ? '*args' : ''
|
262
|
+
%(#{name}(#{args}) if self.class <= ObjectSpace._id2ref(#{method_info[:from].object_id}))
|
263
|
+
else
|
264
|
+
args = respond_to?(name) && method(name).arity != 0 ? '*args' : ''
|
265
|
+
%(#{name}(#{args}) if self <= ObjectSpace._id2ref(#{method_info[:from].object_id}))
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
def define_advised_method(target_method, scope)
|
270
|
+
args = args_for(method_with_scope(target_method, scope))
|
271
|
+
|
272
|
+
renamed_target = hook_method_name(target_method, 'hookable_', 'before_advised')
|
273
|
+
|
274
|
+
source = <<-EOD
|
275
|
+
def #{target_method}(#{args})
|
276
|
+
retval = nil
|
277
|
+
catch(:halt) do
|
278
|
+
#{hook_method_name(target_method, 'execute_before', 'hook_stack')}(#{args})
|
279
|
+
retval = #{renamed_target}(#{args})
|
280
|
+
#{hook_method_name(target_method, 'execute_after', 'hook_stack')}(retval, #{args})
|
281
|
+
retval
|
282
|
+
end
|
283
|
+
end
|
284
|
+
EOD
|
285
|
+
|
286
|
+
if scope == :instance && !instance_methods(false).include?(target_method.to_s)
|
287
|
+
send(:alias_method, renamed_target, target_method)
|
288
|
+
|
289
|
+
proxy_module = Module.new
|
290
|
+
proxy_module.class_eval(source, __FILE__, __LINE__)
|
291
|
+
self.send(:include, proxy_module)
|
292
|
+
else
|
293
|
+
source = %{alias_method :#{renamed_target}, :#{target_method}\n#{source}}
|
294
|
+
source = %{class << self\n#{source}\nend} if scope == :class
|
295
|
+
class_eval(source, __FILE__, __LINE__)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
# --- Add a hook ---
|
300
|
+
|
301
|
+
def install_hook(type, target_method, method_sym, scope, &block)
|
302
|
+
assert_kind_of 'target_method', target_method, Symbol
|
303
|
+
assert_kind_of 'method_sym', method_sym, Symbol unless method_sym.nil?
|
304
|
+
assert_kind_of 'scope', scope, Symbol
|
305
|
+
|
306
|
+
if !block_given? and method_sym.nil?
|
307
|
+
raise ArgumentError, "You need to pass 2 arguments to \"#{type}\"."
|
308
|
+
end
|
309
|
+
|
310
|
+
if method_sym.to_s[-1,1] == '='
|
311
|
+
raise ArgumentError, "Methods ending in = cannot be hooks"
|
312
|
+
end
|
313
|
+
|
314
|
+
unless [ :class, :instance ].include?(scope)
|
315
|
+
raise ArgumentError, 'You need to pass :class or :instance as scope'
|
316
|
+
end
|
317
|
+
|
318
|
+
register_hook(target_method, scope) unless registered_as_hook?(target_method, scope)
|
319
|
+
|
320
|
+
hooks = hooks_with_scope(scope)
|
321
|
+
|
322
|
+
if block
|
323
|
+
method_sym = "__hooks_#{type}_#{quote_method(target_method)}_#{hooks[target_method][type].length}".to_sym
|
324
|
+
if scope == :class
|
325
|
+
(class << self; self; end;).instance_eval do
|
326
|
+
define_method(method_sym, &block)
|
327
|
+
end
|
328
|
+
else
|
329
|
+
define_method(method_sym, &block)
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
# Adds method to the stack an redefines the hook invocation method
|
334
|
+
hooks[target_method][type] << { :name => method_sym, :from => self }
|
335
|
+
define_hook_stack_execution_methods(target_method, scope)
|
336
|
+
end
|
337
|
+
|
338
|
+
# --- Helpers ---
|
339
|
+
|
340
|
+
def args_for(method)
|
341
|
+
if method.arity == 0
|
342
|
+
"&block"
|
343
|
+
elsif method.arity > 0
|
344
|
+
"_" << (1 .. method.arity).to_a.join(", _") << ", &block"
|
345
|
+
elsif (method.arity + 1) < 0
|
346
|
+
"_" << (1 .. (method.arity).abs - 1).to_a.join(", _") << ", *args, &block"
|
347
|
+
else
|
348
|
+
"*args, &block"
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
def method_with_scope(name, scope)
|
353
|
+
case scope
|
354
|
+
when :class then method(name)
|
355
|
+
when :instance then instance_method(name)
|
356
|
+
else raise ArgumentError, 'You need to pass :class or :instance as scope'
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
def quote_method(name)
|
361
|
+
name.to_s.gsub(/\?$/, '_q_').gsub(/!$/, '_b_').gsub(/=$/, '_eq_')
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
end
|
366
|
+
end
|
@@ -0,0 +1,435 @@
|
|
1
|
+
module Extlib
|
2
|
+
|
3
|
+
# = English Nouns Number Inflection.
|
4
|
+
#
|
5
|
+
# This module provides english singular <-> plural noun inflections.
|
6
|
+
module Inflection
|
7
|
+
|
8
|
+
class << self
|
9
|
+
# Take an underscored name and make it into a camelized name
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# "egg_and_hams".classify #=> "EggAndHam"
|
13
|
+
# "post".classify #=> "Post"
|
14
|
+
#
|
15
|
+
def classify(name)
|
16
|
+
camelize(singularize(name.to_s.sub(/.*\./, '')))
|
17
|
+
end
|
18
|
+
|
19
|
+
# By default, camelize converts strings to UpperCamelCase.
|
20
|
+
#
|
21
|
+
# camelize will also convert '/' to '::' which is useful for converting paths to namespaces
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
# "active_record".camelize #=> "ActiveRecord"
|
25
|
+
# "active_record/errors".camelize #=> "ActiveRecord::Errors"
|
26
|
+
#
|
27
|
+
def camelize(lower_case_and_underscored_word, *args)
|
28
|
+
lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
# The reverse of +camelize+. Makes an underscored form from the expression in the string.
|
33
|
+
#
|
34
|
+
# Changes '::' to '/' to convert namespaces to paths.
|
35
|
+
#
|
36
|
+
# @example
|
37
|
+
# "ActiveRecord".underscore #=> "active_record"
|
38
|
+
# "ActiveRecord::Errors".underscore #=> active_record/errors
|
39
|
+
#
|
40
|
+
def underscore(camel_cased_word)
|
41
|
+
camel_cased_word.to_const_path
|
42
|
+
end
|
43
|
+
|
44
|
+
# Capitalizes the first word and turns underscores into spaces and strips _id.
|
45
|
+
# Like titleize, this is meant for creating pretty output.
|
46
|
+
#
|
47
|
+
# @example
|
48
|
+
# "employee_salary" #=> "Employee salary"
|
49
|
+
# "author_id" #=> "Author"
|
50
|
+
def humanize(lower_case_and_underscored_word)
|
51
|
+
lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize
|
52
|
+
end
|
53
|
+
|
54
|
+
# Removes the module part from the expression in the string
|
55
|
+
#
|
56
|
+
# @example
|
57
|
+
# "ActiveRecord::CoreExtensions::String::Inflections".demodulize #=> "Inflections"
|
58
|
+
# "Inflections".demodulize #=> "Inflections"
|
59
|
+
def demodulize(class_name_in_module)
|
60
|
+
class_name_in_module.to_s.gsub(/^.*::/, '')
|
61
|
+
end
|
62
|
+
|
63
|
+
# Create the name of a table like Rails does for models to table names. This method
|
64
|
+
# uses the pluralize method on the last word in the string.
|
65
|
+
#
|
66
|
+
# @example
|
67
|
+
# "RawScaledScorer".tableize #=> "raw_scaled_scorers"
|
68
|
+
# "egg_and_ham".tableize #=> "egg_and_hams"
|
69
|
+
# "fancyCategory".tableize #=> "fancy_categories"
|
70
|
+
def tableize(class_name)
|
71
|
+
pluralize(class_name.to_const_path.gsub(/\//, '_'))
|
72
|
+
end
|
73
|
+
|
74
|
+
# Creates a foreign key name from a class name.
|
75
|
+
#
|
76
|
+
# @example
|
77
|
+
# "Message".foreign_key #=> "message_id"
|
78
|
+
# "Admin::Post".foreign_key #=> "post_id"
|
79
|
+
def foreign_key(class_name, key = "id")
|
80
|
+
underscore(demodulize(class_name.to_s)) << "_" << key.to_s
|
81
|
+
end
|
82
|
+
|
83
|
+
# Constantize tries to find a declared constant with the name specified
|
84
|
+
# in the string. It raises a NameError when the name is not in CamelCase
|
85
|
+
# or is not initialized.
|
86
|
+
#
|
87
|
+
# @example
|
88
|
+
# "Module".constantize #=> Module
|
89
|
+
# "Class".constantize #=> Class
|
90
|
+
def constantize(camel_cased_word)
|
91
|
+
unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ camel_cased_word
|
92
|
+
raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!"
|
93
|
+
end
|
94
|
+
|
95
|
+
Object.module_eval("::#{$1}", __FILE__, __LINE__)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
@singular_of = {}
|
100
|
+
@plural_of = {}
|
101
|
+
|
102
|
+
@singular_rules = []
|
103
|
+
@plural_rules = []
|
104
|
+
|
105
|
+
class << self
|
106
|
+
# Defines a general inflection exception case.
|
107
|
+
#
|
108
|
+
# ==== Parameters
|
109
|
+
# singular<String>::
|
110
|
+
# singular form of the word
|
111
|
+
# plural<String>::
|
112
|
+
# plural form of the word
|
113
|
+
#
|
114
|
+
# ==== Examples
|
115
|
+
#
|
116
|
+
# Here we define erratum/errata exception case:
|
117
|
+
#
|
118
|
+
# English::Inflect.word "erratum", "errata"
|
119
|
+
#
|
120
|
+
# In case singular and plural forms are the same omit
|
121
|
+
# second argument on call:
|
122
|
+
#
|
123
|
+
# English::Inflect.word 'information'
|
124
|
+
def word(singular, plural=nil)
|
125
|
+
plural = singular unless plural
|
126
|
+
singular_word(singular, plural)
|
127
|
+
plural_word(singular, plural)
|
128
|
+
end
|
129
|
+
|
130
|
+
def clear(type = :all)
|
131
|
+
if type == :singular || type == :all
|
132
|
+
@singular_of = {}
|
133
|
+
@singular_rules = []
|
134
|
+
@singularization_rules, @singularization_regex = nil, nil
|
135
|
+
end
|
136
|
+
if type == :plural || type == :all
|
137
|
+
@singular_of = {}
|
138
|
+
@singular_rules = []
|
139
|
+
@singularization_rules, @singularization_regex = nil, nil
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
# Define a singularization exception.
|
145
|
+
#
|
146
|
+
# ==== Parameters
|
147
|
+
# singular<String>::
|
148
|
+
# singular form of the word
|
149
|
+
# plural<String>::
|
150
|
+
# plural form of the word
|
151
|
+
def singular_word(singular, plural)
|
152
|
+
@singular_of[plural] = singular
|
153
|
+
@singular_of[plural.capitalize] = singular.capitalize
|
154
|
+
end
|
155
|
+
|
156
|
+
# Define a pluralization exception.
|
157
|
+
#
|
158
|
+
# ==== Parameters
|
159
|
+
# singular<String>::
|
160
|
+
# singular form of the word
|
161
|
+
# plural<String>::
|
162
|
+
# plural form of the word
|
163
|
+
def plural_word(singular, plural)
|
164
|
+
@plural_of[singular] = plural
|
165
|
+
@plural_of[singular.capitalize] = plural.capitalize
|
166
|
+
end
|
167
|
+
|
168
|
+
# Define a general rule.
|
169
|
+
#
|
170
|
+
# ==== Parameters
|
171
|
+
# singular<String>::
|
172
|
+
# ending of the word in singular form
|
173
|
+
# plural<String>::
|
174
|
+
# ending of the word in plural form
|
175
|
+
# whole_word<Boolean>::
|
176
|
+
# for capitalization, since words can be
|
177
|
+
# capitalized (Man => Men) #
|
178
|
+
# ==== Examples
|
179
|
+
# Once the following rule is defined:
|
180
|
+
# English::Inflect.rule 'y', 'ies'
|
181
|
+
#
|
182
|
+
# You can see the following results:
|
183
|
+
# irb> "fly".plural
|
184
|
+
# => flies
|
185
|
+
# irb> "cry".plural
|
186
|
+
# => cries
|
187
|
+
# Define a general rule.
|
188
|
+
|
189
|
+
def rule(singular, plural, whole_word = false)
|
190
|
+
singular_rule(singular, plural)
|
191
|
+
plural_rule(singular, plural)
|
192
|
+
word(singular, plural) if whole_word
|
193
|
+
end
|
194
|
+
|
195
|
+
# Define a singularization rule.
|
196
|
+
#
|
197
|
+
# ==== Parameters
|
198
|
+
# singular<String>::
|
199
|
+
# ending of the word in singular form
|
200
|
+
# plural<String>::
|
201
|
+
# ending of the word in plural form
|
202
|
+
#
|
203
|
+
# ==== Examples
|
204
|
+
# Once the following rule is defined:
|
205
|
+
# English::Inflect.singular_rule 'o', 'oes'
|
206
|
+
#
|
207
|
+
# You can see the following results:
|
208
|
+
# irb> "heroes".singular
|
209
|
+
# => hero
|
210
|
+
def singular_rule(singular, plural)
|
211
|
+
@singular_rules << [singular, plural]
|
212
|
+
end
|
213
|
+
|
214
|
+
# Define a plurualization rule.
|
215
|
+
#
|
216
|
+
# ==== Parameters
|
217
|
+
# singular<String>::
|
218
|
+
# ending of the word in singular form
|
219
|
+
# plural<String>::
|
220
|
+
# ending of the word in plural form
|
221
|
+
#
|
222
|
+
# ==== Examples
|
223
|
+
# Once the following rule is defined:
|
224
|
+
# English::Inflect.singular_rule 'fe', 'ves'
|
225
|
+
#
|
226
|
+
# You can see the following results:
|
227
|
+
# irb> "wife".plural
|
228
|
+
# => wives
|
229
|
+
def plural_rule(singular, plural)
|
230
|
+
@plural_rules << [singular, plural]
|
231
|
+
end
|
232
|
+
|
233
|
+
# Read prepared singularization rules.
|
234
|
+
def singularization_rules
|
235
|
+
if defined?(@singularization_regex) && @singularization_regex
|
236
|
+
return [@singularization_regex, @singularization_hash]
|
237
|
+
end
|
238
|
+
# No sorting needed: Regexen match on longest string
|
239
|
+
@singularization_regex = Regexp.new("(" + @singular_rules.map {|s,p| p}.join("|") + ")$", "i")
|
240
|
+
@singularization_hash = Hash[*@singular_rules.flatten].invert
|
241
|
+
[@singularization_regex, @singularization_hash]
|
242
|
+
end
|
243
|
+
|
244
|
+
# Read prepared pluralization rules.
|
245
|
+
def pluralization_rules
|
246
|
+
if defined?(@pluralization_regex) && @pluralization_regex
|
247
|
+
return [@pluralization_regex, @pluralization_hash]
|
248
|
+
end
|
249
|
+
@pluralization_regex = Regexp.new("(" + @plural_rules.map {|s,p| s}.join("|") + ")$", "i")
|
250
|
+
@pluralization_hash = Hash[*@plural_rules.flatten]
|
251
|
+
[@pluralization_regex, @pluralization_hash]
|
252
|
+
end
|
253
|
+
|
254
|
+
attr_reader :singular_of, :plural_of
|
255
|
+
|
256
|
+
# Convert an English word from plurel to singular.
|
257
|
+
#
|
258
|
+
# "boys".singular #=> boy
|
259
|
+
# "tomatoes".singular #=> tomato
|
260
|
+
#
|
261
|
+
# ==== Parameters
|
262
|
+
# word<String>:: word to singularize
|
263
|
+
#
|
264
|
+
# ==== Returns
|
265
|
+
# <String>:: singularized form of word
|
266
|
+
#
|
267
|
+
# ==== Notes
|
268
|
+
# Aliased as singularize (a Railism)
|
269
|
+
def singular(word)
|
270
|
+
if result = singular_of[word]
|
271
|
+
return result.dup
|
272
|
+
end
|
273
|
+
result = word.dup
|
274
|
+
regex, hash = singularization_rules
|
275
|
+
result.sub!(regex) {|m| hash[m]}
|
276
|
+
singular_of[word] = result
|
277
|
+
return result
|
278
|
+
end
|
279
|
+
|
280
|
+
# Alias for #singular (a Railism).
|
281
|
+
#
|
282
|
+
alias_method(:singularize, :singular)
|
283
|
+
|
284
|
+
# Convert an English word from singular to plurel.
|
285
|
+
#
|
286
|
+
# "boy".plural #=> boys
|
287
|
+
# "tomato".plural #=> tomatoes
|
288
|
+
#
|
289
|
+
# ==== Parameters
|
290
|
+
# word<String>:: word to pluralize
|
291
|
+
#
|
292
|
+
# ==== Returns
|
293
|
+
# <String>:: pluralized form of word
|
294
|
+
#
|
295
|
+
# ==== Notes
|
296
|
+
# Aliased as pluralize (a Railism)
|
297
|
+
def plural(word)
|
298
|
+
# special exceptions
|
299
|
+
return "" if word == ""
|
300
|
+
if result = plural_of[word]
|
301
|
+
return result.dup
|
302
|
+
end
|
303
|
+
result = word.dup
|
304
|
+
regex, hash = pluralization_rules
|
305
|
+
result.sub!(regex) {|m| hash[m]}
|
306
|
+
plural_of[word] = result
|
307
|
+
return result
|
308
|
+
end
|
309
|
+
|
310
|
+
# Alias for #plural (a Railism).
|
311
|
+
alias_method(:pluralize, :plural)
|
312
|
+
end
|
313
|
+
|
314
|
+
# One argument means singular and plural are the same.
|
315
|
+
|
316
|
+
word 'equipment'
|
317
|
+
word 'information'
|
318
|
+
word 'money'
|
319
|
+
word 'species'
|
320
|
+
word 'series'
|
321
|
+
word 'fish'
|
322
|
+
word 'sheep'
|
323
|
+
word 'moose'
|
324
|
+
word 'hovercraft'
|
325
|
+
word 'grass'
|
326
|
+
word 'rain'
|
327
|
+
word 'milk'
|
328
|
+
word 'rice'
|
329
|
+
word 'plurals'
|
330
|
+
word 'postgres'
|
331
|
+
word 'status'
|
332
|
+
|
333
|
+
# Two arguments defines a singular and plural exception.
|
334
|
+
word 'status' , 'status'
|
335
|
+
word 'Swiss' , 'Swiss'
|
336
|
+
word 'life' , 'lives'
|
337
|
+
word 'wife' , 'wives'
|
338
|
+
word 'goose' , 'geese'
|
339
|
+
word 'criterion' , 'criteria'
|
340
|
+
word 'alias' , 'aliases'
|
341
|
+
word 'status' , 'statuses'
|
342
|
+
word 'axis' , 'axes'
|
343
|
+
word 'crisis' , 'crises'
|
344
|
+
word 'testis' , 'testes'
|
345
|
+
word 'potato' , 'potatoes'
|
346
|
+
word 'tomato' , 'tomatoes'
|
347
|
+
word 'buffalo' , 'buffaloes'
|
348
|
+
word 'torpedo' , 'torpedoes'
|
349
|
+
word 'quiz' , 'quizzes'
|
350
|
+
word 'matrix' , 'matrices'
|
351
|
+
word 'vertex' , 'vertices'
|
352
|
+
word 'index' , 'indices'
|
353
|
+
word 'ox' , 'oxen'
|
354
|
+
word 'mouse' , 'mice'
|
355
|
+
word 'louse' , 'lice'
|
356
|
+
word 'thesis' , 'theses'
|
357
|
+
word 'thief' , 'thieves'
|
358
|
+
word 'analysis' , 'analyses'
|
359
|
+
word 'erratum' , 'errata'
|
360
|
+
word 'phenomenon', 'phenomena'
|
361
|
+
word 'octopus' , 'octopi'
|
362
|
+
word 'thesaurus' , 'thesauri'
|
363
|
+
word 'movie' , 'movies'
|
364
|
+
word 'cactus' , 'cacti'
|
365
|
+
word 'plus' , 'plusses'
|
366
|
+
word 'cross' , 'crosses'
|
367
|
+
word 'medium' , 'media'
|
368
|
+
word 'cow' , 'kine'
|
369
|
+
word 'datum' , 'data'
|
370
|
+
word 'basis' , 'bases'
|
371
|
+
word 'diagnosis' , 'diagnoses'
|
372
|
+
|
373
|
+
# One-way singularization exception (convert plural to singular).
|
374
|
+
|
375
|
+
# General rules.
|
376
|
+
rule 'person' , 'people', true
|
377
|
+
rule 'shoe' , 'shoes', true
|
378
|
+
rule 'hive' , 'hives', true
|
379
|
+
rule 'man' , 'men', true
|
380
|
+
rule 'child' , 'children', true
|
381
|
+
rule 'news' , 'news', true
|
382
|
+
rule 'rf' , 'rves'
|
383
|
+
rule 'af' , 'aves'
|
384
|
+
rule 'ero' , 'eroes'
|
385
|
+
rule 'man' , 'men'
|
386
|
+
rule 'ch' , 'ches'
|
387
|
+
rule 'sh' , 'shes'
|
388
|
+
rule 'ss' , 'sses'
|
389
|
+
rule 'ta' , 'tum'
|
390
|
+
rule 'ia' , 'ium'
|
391
|
+
rule 'ra' , 'rum'
|
392
|
+
rule 'ay' , 'ays'
|
393
|
+
rule 'ey' , 'eys'
|
394
|
+
rule 'oy' , 'oys'
|
395
|
+
rule 'uy' , 'uys'
|
396
|
+
rule 'y' , 'ies'
|
397
|
+
rule 'x' , 'xes'
|
398
|
+
rule 'lf' , 'lves'
|
399
|
+
rule 'ffe' , 'ffes'
|
400
|
+
rule 'afe' , 'aves'
|
401
|
+
rule 'ouse' , 'ouses'
|
402
|
+
# more cases of words ending in -oses not being singularized properly
|
403
|
+
# than cases of words ending in -osis
|
404
|
+
# rule 'osis' , 'oses'
|
405
|
+
rule 'ox' , 'oxes'
|
406
|
+
rule 'us' , 'uses'
|
407
|
+
rule '' , 's'
|
408
|
+
|
409
|
+
# One-way singular rules.
|
410
|
+
|
411
|
+
singular_rule 'of' , 'ofs' # proof
|
412
|
+
singular_rule 'o' , 'oes' # hero, heroes
|
413
|
+
singular_rule 'f' , 'ves'
|
414
|
+
|
415
|
+
# One-way plural rules.
|
416
|
+
|
417
|
+
#plural_rule 'fe' , 'ves' # safe, wife
|
418
|
+
plural_rule 's' , 'ses'
|
419
|
+
plural_rule 'ive' , 'ives' # don't want to snag wife
|
420
|
+
plural_rule 'fe' , 'ves' # don't want to snag perspectives
|
421
|
+
|
422
|
+
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
class String
|
427
|
+
def singular
|
428
|
+
Extlib::Inflection.singular(self)
|
429
|
+
end
|
430
|
+
alias_method(:singularize, :singular)
|
431
|
+
def plural
|
432
|
+
Extlib::Inflection.plural(self)
|
433
|
+
end
|
434
|
+
alias_method(:pluralize, :plural)
|
435
|
+
end
|