facets 2.9.0 → 2.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY.rdoc +34 -0
- data/{meta/profile → PROFILE} +15 -1
- data/README.rdoc +11 -17
- data/Rakefile +74 -31
- data/VERSION +1 -0
- data/lib/core-uncommon/facets/array/median.rb +17 -0
- data/lib/core-uncommon/facets/array/op_pow.rb +9 -0
- data/lib/{tour → core-uncommon}/facets/array/percentile.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/class/preallocate.rb +3 -0
- data/lib/core-uncommon/facets/enumerable/has.rb +22 -0
- data/lib/core-uncommon/facets/enumerable/have.rb +1 -0
- data/lib/{tour → core-uncommon}/facets/integer/roman.rb +9 -0
- data/lib/{tour → core-uncommon}/facets/kernel/demo.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/kernel/eigenclass.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/kernel/instance_exec.rb +6 -0
- data/lib/{tour → core-uncommon}/facets/kernel/memo.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/kernel/trap_chain.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/kernel/y.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/method/memoize.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/module/attr_class_accessor.rb +6 -0
- data/lib/{tour → core-uncommon}/facets/module/attr_inheritor.rb +2 -0
- data/lib/{tour → core-uncommon}/facets/module/attr_tester.rb +8 -0
- data/lib/{tour → core-uncommon}/facets/module/attr_validator.rb +6 -0
- data/lib/{tour → core-uncommon}/facets/module/cattr.rb +24 -0
- data/lib/core-uncommon/facets/module/class_accessor.rb +33 -0
- data/lib/{tour → core-uncommon}/facets/module/class_extend.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/module/class_inheritor.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/module/copy_inheritor.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/module/enclosure.rb +6 -0
- data/lib/{tour → core-uncommon}/facets/module/enclosures.rb +0 -0
- data/lib/{tour → core-uncommon}/facets/module/include_as.rb +0 -0
- data/lib/{tour → core-uncommon}/facets/module/instance_function.rb +2 -0
- data/lib/{tour → core-uncommon}/facets/module/memoize.rb +0 -0
- data/lib/{tour → core-uncommon}/facets/module/method_space.rb +5 -0
- data/lib/{tour → core-uncommon}/facets/module/module_load.rb +6 -0
- data/lib/{tour → core-uncommon}/facets/module/preextend.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/module/prepend.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/regexp/op_or.rb +2 -0
- data/lib/{tour → core-uncommon}/facets/string/crypt.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/string/roman.rb +0 -0
- data/lib/core/facets.rb +19 -0
- data/lib/core/facets.yml +1144 -0
- data/lib/core/facets/applique/file_helpers.rb +4 -4
- data/lib/core/facets/array.rb +0 -1
- data/lib/core/facets/binding.rb +1 -1
- data/lib/core/facets/class.rb +1 -1
- data/lib/core/facets/comparable.rb +1 -1
- data/lib/core/facets/dir.rb +1 -1
- data/lib/core/facets/dir/recurse.rb +1 -1
- data/lib/core/facets/enumerable.rb +1 -1
- data/lib/core/facets/exception.rb +1 -1
- data/lib/core/facets/file.rb +1 -1
- data/lib/core/facets/file/create.rb +1 -1
- data/lib/core/facets/file/read_binary.rb +2 -2
- data/lib/core/facets/file/rewrite.rb +4 -4
- data/lib/core/facets/file/write.rb +1 -1
- data/lib/core/facets/file/writelines.rb +1 -1
- data/lib/core/facets/filetest.rb +1 -1
- data/lib/core/facets/filetest/absolute.rb +1 -0
- data/lib/core/facets/filetest/contains.rb +12 -0
- data/lib/core/facets/filetest/relative.rb +38 -0
- data/lib/core/facets/filetest/safe.rb +20 -0
- data/lib/core/facets/filetest/separator_pattern.rb +19 -0
- data/lib/core/facets/float.rb +1 -1
- data/lib/core/facets/hash.rb +1 -1
- data/lib/core/facets/integer.rb +1 -1
- data/lib/core/facets/kernel.rb +1 -1
- data/lib/core/facets/kernel/no.rb +1 -0
- data/lib/core/facets/kernel/object_hexid.rb +3 -1
- data/lib/core/facets/kernel/yes.rb +25 -0
- data/lib/core/facets/matchdata.rb +1 -1
- data/lib/core/facets/method.rb +1 -1
- data/lib/core/facets/module.rb +1 -1
- data/lib/core/facets/module/redefine_method.rb +4 -4
- data/lib/core/facets/nilclass.rb +1 -1
- data/lib/core/facets/numeric.rb +1 -1
- data/lib/core/facets/object.rb +1 -1
- data/lib/core/facets/object/replace.rb +2 -2
- data/lib/core/facets/objectspace.rb +1 -1
- data/lib/core/facets/proc.rb +1 -1
- data/lib/core/facets/process.rb +1 -1
- data/lib/core/facets/range.rb +1 -1
- data/lib/core/facets/regexp.rb +1 -1
- data/lib/core/facets/string.rb +1 -1
- data/lib/core/facets/string/file.rb +4 -2
- data/lib/core/facets/string/random_binary.rb +10 -0
- data/lib/core/facets/string/unquote.rb +1 -1
- data/lib/core/facets/struct.rb +1 -1
- data/lib/core/facets/symbol.rb +1 -1
- data/lib/core/facets/time.rb +1 -1
- data/lib/core/facets/unboundmethod.rb +1 -1
- data/lib/{more → standard}/facets/basicobject.rb +0 -0
- data/lib/{more → standard}/facets/cgi.rb +0 -0
- data/lib/{more → standard}/facets/continuation.rb +0 -0
- data/lib/{more → standard}/facets/date.rb +0 -0
- data/lib/standard/facets/digest.rb +2 -0
- data/lib/standard/facets/digest/base64digest.rb +45 -0
- data/lib/standard/facets/digest/salted_digest.rb +44 -0
- data/lib/{more → standard}/facets/erb.rb +0 -0
- data/lib/{more → standard}/facets/fileutils.rb +5 -0
- data/lib/standard/facets/fileutils/amass.rb +33 -0
- data/lib/{more → standard}/facets/fileutils/cp_rx.rb +3 -1
- data/lib/{more → standard}/facets/fileutils/head.rb +0 -0
- data/lib/standard/facets/fileutils/ln_r.rb +92 -0
- data/lib/standard/facets/fileutils/outofdate.rb +38 -0
- data/lib/{more → standard}/facets/fileutils/safe_ln.rb +0 -0
- data/lib/{more → standard}/facets/fileutils/slice.rb +14 -12
- data/lib/standard/facets/fileutils/stage.rb +66 -0
- data/lib/{more → standard}/facets/fileutils/tail.rb +0 -0
- data/lib/{more → standard}/facets/fileutils/wc.rb +0 -0
- data/lib/{more → standard}/facets/fileutils/whereis.rb +0 -0
- data/lib/{more → standard}/facets/fileutils/which.rb +2 -0
- data/lib/{more → standard}/facets/find.rb +0 -0
- data/lib/{more → standard}/facets/getoptlong.rb +0 -0
- data/lib/{more → standard}/facets/math.rb +1 -1
- data/lib/{more → standard}/facets/math/abs.rb +0 -0
- data/lib/{more → standard}/facets/math/acot.rb +0 -0
- data/lib/{more → standard}/facets/math/acoth.rb +0 -0
- data/lib/{more → standard}/facets/math/acsc.rb +0 -0
- data/lib/{more → standard}/facets/math/acsch.rb +0 -0
- data/lib/{more → standard}/facets/math/amd.rb +0 -0
- data/lib/{more → standard}/facets/math/approx_equal.rb +1 -1
- data/lib/{more → standard}/facets/math/asec.rb +0 -0
- data/lib/{more → standard}/facets/math/asech.rb +0 -0
- data/lib/{more → standard}/facets/math/atkinson_index.rb +0 -0
- data/lib/{more → standard}/facets/math/beta.rb +0 -0
- data/lib/{more → standard}/facets/math/cdf.rb +0 -0
- data/lib/{more → standard}/facets/math/ceil.rb +0 -0
- data/lib/{more → standard}/facets/math/cot.rb +0 -0
- data/lib/{more → standard}/facets/math/coth.rb +0 -0
- data/lib/{more → standard}/facets/math/csc.rb +0 -0
- data/lib/{more → standard}/facets/math/csch.rb +0 -0
- data/lib/{more → standard}/facets/math/delta.rb +2 -1
- data/lib/{more → standard}/facets/math/epsilon.rb +0 -0
- data/lib/{more → standard}/facets/math/exp10.rb +0 -0
- data/lib/{more → standard}/facets/math/exp2.rb +0 -0
- data/lib/{more → standard}/facets/math/factorial.rb +0 -0
- data/lib/{more → standard}/facets/math/floor.rb +0 -0
- data/lib/{more → standard}/facets/math/gamma.rb +0 -0
- data/lib/{more → standard}/facets/math/gcd.rb +0 -0
- data/lib/{more → standard}/facets/math/gini_coefficient.rb +0 -0
- data/lib/{more → standard}/facets/math/kldivergence.rb +0 -0
- data/lib/{more → standard}/facets/math/lcm.rb +0 -0
- data/lib/{more → standard}/facets/math/lgamma.rb +0 -0
- data/lib/{more → standard}/facets/math/linsolve.rb +0 -0
- data/lib/{more → standard}/facets/math/log2.rb +0 -0
- data/lib/{more → standard}/facets/math/max.rb +0 -0
- data/lib/{more → standard}/facets/math/mean.rb +0 -0
- data/lib/{more → standard}/facets/math/median.rb +0 -0
- data/lib/{more → standard}/facets/math/min.rb +0 -0
- data/lib/{more → standard}/facets/math/pow.rb +0 -0
- data/lib/{more → standard}/facets/math/pstd.rb +0 -0
- data/lib/{more → standard}/facets/math/pvariance.rb +0 -0
- data/lib/{more → standard}/facets/math/rmd.rb +0 -0
- data/lib/{more → standard}/facets/math/root.rb +0 -0
- data/lib/{more → standard}/facets/math/sec.rb +0 -0
- data/lib/{more → standard}/facets/math/sech.rb +0 -0
- data/lib/{more → standard}/facets/math/sign.rb +0 -0
- data/lib/{more → standard}/facets/math/sinc.rb +0 -0
- data/lib/{more → standard}/facets/math/sqr.rb +0 -0
- data/lib/{more → standard}/facets/math/sqsolve.rb +0 -0
- data/lib/{more → standard}/facets/math/std.rb +0 -0
- data/lib/{more → standard}/facets/math/stderr.rb +0 -0
- data/lib/{more → standard}/facets/math/sum.rb +0 -0
- data/lib/{more → standard}/facets/math/summed_sqdevs.rb +0 -0
- data/lib/{more → standard}/facets/math/theil_index.rb +0 -0
- data/lib/{more → standard}/facets/math/variance.rb +0 -0
- data/lib/standard/facets/net/http.rb +32 -0
- data/lib/{more → standard}/facets/ostruct.rb +0 -0
- data/lib/{more → standard}/facets/pathname.rb +1 -0
- data/lib/{more → standard}/facets/random.rb +2 -2
- data/lib/standard/facets/rbconfig.rb +78 -0
- data/lib/{more → standard}/facets/set.rb +0 -0
- data/lib/{more → standard}/facets/shellwords.rb +2 -0
- data/lib/standard/facets/strscan.rb +16 -0
- data/lib/{more → standard}/facets/thread.rb +0 -0
- data/lib/{more → standard}/facets/uri.rb +0 -0
- data/lib/{more → standard}/facets/yaml.rb +0 -0
- data/lib/{more → standard}/facets/zlib.rb +0 -0
- data/lib/{more → supplemental}/facets/argvector.rb +0 -0
- data/lib/{more → supplemental}/facets/atomicfile.rb +0 -0
- data/lib/{more → supplemental}/facets/interval.rb +0 -0
- data/lib/{more → supplemental}/facets/main.rb +0 -0
- data/lib/{more → supplemental}/facets/memoizable.rb +0 -0
- data/lib/{more → supplemental}/facets/metaid.rb +0 -0
- data/lib/{more → supplemental}/facets/multipliers.rb +0 -0
- data/lib/{more → supplemental}/facets/multiton.rb +0 -0
- data/lib/{more → supplemental}/facets/nullclass.rb +0 -0
- data/lib/{more → supplemental}/facets/opesc.rb +0 -0
- data/lib/{more → supplemental}/facets/platform.rb +156 -5
- data/lib/{more → supplemental}/facets/reference.rb +0 -0
- data/lib/{more → supplemental}/facets/timer.rb +0 -0
- data/lib/{more → supplemental}/facets/tuple.rb +0 -0
- data/qed/applique/file_helpers.rb +10 -0
- data/qed/{tour → core-uncommon}/module/cattr.rdoc +0 -0
- data/qed/{tour → core-uncommon}/module/class_extend.rdoc +0 -0
- data/qed/{tour → core-uncommon}/module/class_inheritor.rdoc +0 -0
- data/qed/{tour → core-uncommon}/module/copy_inheritor.rdoc +0 -0
- data/qed/{tour → core-uncommon}/module/method_space.rdoc +0 -0
- data/qed/{more → standard}/basic_object.rdoc +0 -0
- data/qed/{more → supplemental}/memoizable.rdoc +0 -0
- data/qed/{more → supplemental}/mulititon.rdoc +0 -0
- data/test/{tour → core-uncommon}/array/test_median.rb +0 -0
- data/test/{tour → core-uncommon}/array/test_percentile.rb +0 -0
- data/test/{tour → core-uncommon}/class/test_preallocate.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_cattr.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_class_extend.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_class_inheritor.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_copy_inheritor.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_enclosure.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_instance_function.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_memoize.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_method_space.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_module_load.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_preextend.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_prepend.rb +0 -0
- data/test/core/dir/test_each_child.rb +1 -1
- data/test/core/dir/test_multiglob.rb +2 -2
- data/test/core/hash/test_zip.rb +12 -0
- data/test/core/{kernel → object}/test_dup.rb +51 -1
- data/test/core/{kernel → object}/test_object_state.rb +1 -1
- data/test/core/{kernel → object}/test_replace.rb +12 -12
- data/test/core/{kernel → object}/test_try_dup.rb +2 -2
- data/test/{more → standard}/test_date.rb +0 -0
- data/test/{more → standard}/test_ostruct.rb +0 -0
- data/test/{more → standard}/test_random.rb +0 -0
- data/test/{more → standard}/test_shellwords.rb +0 -0
- data/test/{more → standard}/test_thread.rb +0 -0
- data/test/{more → standard}/test_timer.rb +0 -0
- data/test/{more → standard}/test_uri.rb +0 -0
- data/test/{more → supplemental}/test_argvector.rb +0 -0
- data/test/{more → supplemental}/test_memoizable.rb +0 -0
- data/test/{more → supplemental}/test_multipliers.rb +0 -0
- data/test/{more → supplemental}/test_tuple.rb +0 -0
- metadata +224 -204
- data/lib/more/facets/rbconfig.rb +0 -150
- data/lib/tour/facets/array/median.rb +0 -14
- data/lib/tour/facets/array/op_pow.rb +0 -5
- data/lib/tour/facets/module/class_accessor.rb +0 -27
- data/meta/data.rb +0 -29
- data/meta/package +0 -10
- data/test/core/hash/test_zipnew.rb +0 -12
data/lib/core/facets/process.rb
CHANGED
data/lib/core/facets/range.rb
CHANGED
data/lib/core/facets/regexp.rb
CHANGED
data/lib/core/facets/string.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require 'facets/string/
|
1
|
+
require 'facets/string/quote'
|
data/lib/core/facets/struct.rb
CHANGED
data/lib/core/facets/symbol.rb
CHANGED
data/lib/core/facets/time.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
3
|
+
module Digest
|
4
|
+
|
5
|
+
module Instance
|
6
|
+
|
7
|
+
# For Ruby < 1.9.2
|
8
|
+
|
9
|
+
unless instance_methods.include? :base64digest
|
10
|
+
|
11
|
+
# From Ruby 1.9.2 source
|
12
|
+
def base64digest(str = nil)
|
13
|
+
[str ? digest(str) : digest].pack('m0')
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
unless instance_methods.include? :base64digest!
|
19
|
+
|
20
|
+
# From Ruby 1.9.2 source
|
21
|
+
def base64digest!
|
22
|
+
[digest!].pack('m0')
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
class Class
|
30
|
+
|
31
|
+
# For Ruby < 1.9.2
|
32
|
+
|
33
|
+
unless methods.include? :base64digest
|
34
|
+
|
35
|
+
# From Ruby 1.9.2 source
|
36
|
+
def self.base64digest(str, *args)
|
37
|
+
[self.digest(str, *args)].pack('m0')
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'digest'
|
2
|
+
require 'facets/string/random_binary'
|
3
|
+
|
4
|
+
module Digest
|
5
|
+
|
6
|
+
module Instance
|
7
|
+
# CREDIT: Guido De Rosa
|
8
|
+
def salted_digest(str='', salt=:auto)
|
9
|
+
if salt == :auto
|
10
|
+
salt = String.random_binary(digest_length)
|
11
|
+
end
|
12
|
+
digest(str + salt) + salt
|
13
|
+
end
|
14
|
+
|
15
|
+
# CREDIT: Guido De Rosa
|
16
|
+
def salted_hexdigest(str, salt)
|
17
|
+
Digest.hexencode(salted_digest(str, salt))
|
18
|
+
end
|
19
|
+
|
20
|
+
# CREDIT: Guido De Rosa
|
21
|
+
def salted_base64digest(str, salt)
|
22
|
+
[salted_digest(str, salt)].pack('m0')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Class
|
27
|
+
# CREDIT: Guido De Rosa
|
28
|
+
def self.salted_digest(str, salt=:auto, *args)
|
29
|
+
new(*args).salted_digest(str, salt)
|
30
|
+
end
|
31
|
+
|
32
|
+
# CREDIT: Guido De Rosa
|
33
|
+
def self.salted_hexdigest(str, salt=:auto, *args)
|
34
|
+
new(*args).salted_hexdigest(str, salt)
|
35
|
+
end
|
36
|
+
|
37
|
+
# CREDIT: Guido De Rosa
|
38
|
+
def self.salted_base64digest(str, salt=:auto, *args)
|
39
|
+
new(*args).salted_base64digest(str, salt)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
File without changes
|
@@ -1,8 +1,13 @@
|
|
1
1
|
# TODO: Deprecate #safe_ln, if #ln has been fixed to do this.
|
2
2
|
|
3
3
|
require 'fileutils'
|
4
|
+
require 'facets/fileutils/amass'
|
5
|
+
require 'facets/fileutils/cp_rx'
|
6
|
+
require 'facets/fileutils/ln_r'
|
7
|
+
require 'facets/fileutils/outofdate'
|
4
8
|
require 'facets/fileutils/safe_ln'
|
5
9
|
require 'facets/fileutils/slice' # includes head and tail
|
10
|
+
require 'facets/fileutils/stage'
|
6
11
|
require 'facets/fileutils/wc'
|
7
12
|
require 'facets/fileutils/whereis'
|
8
13
|
require 'facets/fileutils/which'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module FileUtils
|
2
|
+
|
3
|
+
module_function
|
4
|
+
|
5
|
+
# An intergrated glob like method that take a set of include globs,
|
6
|
+
# exclude globs and ignore globs to produce a collection of paths.
|
7
|
+
#
|
8
|
+
# The ignore_globs differ from exclude_globs in that they match by
|
9
|
+
# the basename of the path rather than the whole pathname.
|
10
|
+
#
|
11
|
+
# TODO: Should ignore be based on any portion of the path, not just the basename?
|
12
|
+
#
|
13
|
+
def amass(include_globs, exclude_globs=[], ignore=[])
|
14
|
+
include_files = include_globs.flatten.map{ |g| Dir.glob(g) }.flatten.uniq
|
15
|
+
exclude_files = exclude_globs.flatten.map{ |g| Dir.glob(g) }.flatten.uniq
|
16
|
+
|
17
|
+
include_globs = include_globs.map{ |f| File.directory?(f) ? File.join(f, '**/*') : f } # Recursive!
|
18
|
+
exclude_globs = exclude_globs.map{ |f| File.directory?(f) ? File.join(f, '**/*') : f } # Recursive!
|
19
|
+
|
20
|
+
include_files = include_globs.flatten.map{ |g| Dir.glob(g) }.flatten.uniq
|
21
|
+
exclude_files = exclude_globs.flatten.map{ |g| Dir.glob(g) }.flatten.uniq
|
22
|
+
|
23
|
+
files = include_files - exclude_files
|
24
|
+
|
25
|
+
files = files.reject{ |f| ignore.any?{ |x| File.fnmatch?(x, File.basename(f)) } }
|
26
|
+
|
27
|
+
files
|
28
|
+
end
|
29
|
+
|
30
|
+
# Make public (for all submodules too).
|
31
|
+
public :amass
|
32
|
+
|
33
|
+
end
|
@@ -1,11 +1,13 @@
|
|
1
1
|
module FileUtils
|
2
2
|
|
3
|
+
module_function
|
4
|
+
|
3
5
|
# Both of these are modified from the implementations in fileutils.rb from Ruby 1.9.1p378.
|
4
6
|
|
5
7
|
# Like FileUtils.cp_r, but takes a filter proc that can return false to skip a file:
|
6
8
|
#
|
7
9
|
# cp_rx "bigDirectoryTree", "dest", {:noop => true} do |name|
|
8
|
-
|
10
|
+
# /dontCopyThis$/.match(name)
|
9
11
|
# end
|
10
12
|
#
|
11
13
|
# Note that if the filter rejects a subdirectory then everything within that
|
File without changes
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module FileUtils
|
2
|
+
#
|
3
|
+
# Options: noop verbose dereference_root remove_destination
|
4
|
+
#
|
5
|
+
# Hard link +src+ to +dest+. If +src+ is a directory, this method links
|
6
|
+
# all its contents recursively. If +dest+ is a directory, links
|
7
|
+
# +src+ to +dest/src+.
|
8
|
+
#
|
9
|
+
# +src+ can be a list of files.
|
10
|
+
#
|
11
|
+
# # Installing ruby library "mylib" under the site_ruby
|
12
|
+
# FileUtils.rm_r site_ruby + '/mylib', :force
|
13
|
+
# FileUtils.ln_r 'lib/', site_ruby + '/mylib'
|
14
|
+
#
|
15
|
+
# # Examples of copying several files to target directory.
|
16
|
+
# FileUtils.ln_r %w(mail.rb field.rb debug/), site_ruby + '/tmail'
|
17
|
+
# FileUtils.ln_r Dir.glob('*.rb'), '/home/aamine/lib/ruby', :noop => true, :verbose => true
|
18
|
+
#
|
19
|
+
# # If you want to copy all contents of a directory instead of the
|
20
|
+
# # directory itself, c.f. src/x -> dest/x, src/y -> dest/y,
|
21
|
+
# # use following code.
|
22
|
+
# FileUtils.ln_r 'src/.', 'dest' # cp_r('src', 'dest') makes src/dest,
|
23
|
+
# # but this doesn't.
|
24
|
+
#
|
25
|
+
# TODO: Why --remove-destination and not just --force?
|
26
|
+
def ln_r(src, dest, options = {})
|
27
|
+
fu_check_options options, OPT_TABLE['ln_r']
|
28
|
+
fu_output_message "ln -r#{options[:remove_destination] ? ' --remove-destination' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
29
|
+
return if options[:noop]
|
30
|
+
options = options.dup
|
31
|
+
options[:dereference_root] = true unless options.key?(:dereference_root)
|
32
|
+
fu_each_src_dest(src, dest) do |s, d|
|
33
|
+
link_entry s, d, options[:dereference_root], options[:remove_destination]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
module_function :ln_r
|
37
|
+
|
38
|
+
OPT_TABLE = {} unless const_defined?(:OPT_TABLE)
|
39
|
+
OPT_TABLE['ln_r'] = [:noop, :verbose, :dereference_root, :remove_destination]
|
40
|
+
|
41
|
+
#
|
42
|
+
# Hard links a file system entry +src+ to +dest+.
|
43
|
+
# If +src+ is a directory, this method links its contents recursively.
|
44
|
+
#
|
45
|
+
# Both of +src+ and +dest+ must be a path name.
|
46
|
+
# +src+ must exist, +dest+ must not exist.
|
47
|
+
#
|
48
|
+
# If +dereference_root+ is true, this method dereference tree root.
|
49
|
+
#
|
50
|
+
# If +remove_destination+ is true, this method removes each destination file before copy.
|
51
|
+
#
|
52
|
+
def link_entry(src, dest, dereference_root = false, remove_destination = false)
|
53
|
+
Entry_.new(src, nil, dereference_root).traverse do |ent|
|
54
|
+
destent = Entry_.new(dest, ent.rel, false)
|
55
|
+
File.unlink destent.path if remove_destination && File.file?(destent.path)
|
56
|
+
ent.link destent.path
|
57
|
+
end
|
58
|
+
end
|
59
|
+
module_function :link_entry
|
60
|
+
|
61
|
+
class Entry_ #:nodoc:
|
62
|
+
def link(dest)
|
63
|
+
case
|
64
|
+
when directory?
|
65
|
+
if !File.exist?(dest) and descendant_diretory?(dest, path)
|
66
|
+
raise ArgumentError, "cannot link directory %s to itself %s" % [path, dest]
|
67
|
+
end
|
68
|
+
begin
|
69
|
+
Dir.mkdir dest
|
70
|
+
rescue
|
71
|
+
raise unless File.directory?(dest)
|
72
|
+
end
|
73
|
+
else file?
|
74
|
+
File.link path(), dest
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
unless method_defined?(:descendant_diretory?)
|
79
|
+
if File::ALT_SEPARATOR
|
80
|
+
DIRECTORY_TERM = "(?=[/#{Regexp.quote(File::ALT_SEPARATOR)}]|\\z)".freeze
|
81
|
+
else
|
82
|
+
DIRECTORY_TERM = "(?=/|\\z)".freeze
|
83
|
+
end
|
84
|
+
SYSCASE = File::FNM_SYSCASE.nonzero? ? "-i" : ""
|
85
|
+
|
86
|
+
def descendant_diretory?(descendant, ascendant)
|
87
|
+
/\A(?#{SYSCASE}:#{Regexp.quote(ascendant)})#{DIRECTORY_TERM}/ =~ File.dirname(descendant)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module FileUtils
|
4
|
+
module_function
|
5
|
+
|
6
|
+
# The opposite of #uptodate?
|
7
|
+
def outofdate?(path, *sources)
|
8
|
+
#return true unless File.exist?(path)
|
9
|
+
! uptodate?(path, sources.flatten)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Alias for #outofdate?
|
13
|
+
alias_method :out_of_date?, :outofdate?
|
14
|
+
|
15
|
+
# Alias for #uptodate?
|
16
|
+
alias_method :up_to_date?, :uptodate?
|
17
|
+
|
18
|
+
# # TODO: Does a path need updating, based on given +sources+?
|
19
|
+
# # This compares mtimes of give paths. Returns false
|
20
|
+
# # if the path needs to be updated.
|
21
|
+
# #
|
22
|
+
# # DEPRECATE: Is this in any way better than `! uptodate?` ?
|
23
|
+
# def out_of_date?(path, *sources)
|
24
|
+
# return true unless File.exist?(path)
|
25
|
+
#
|
26
|
+
# sources = sources.collect{ |source| Dir.glob(source) }.flatten
|
27
|
+
# mtimes = sources.collect{ |file| File.mtime(file) }
|
28
|
+
#
|
29
|
+
# return true if mtimes.empty? # TODO: This the way to go here?
|
30
|
+
#
|
31
|
+
# File.mtime(path) < mtimes.max
|
32
|
+
# end
|
33
|
+
|
34
|
+
# Make public (for all submodules too).
|
35
|
+
public :outofdate?
|
36
|
+
public :out_of_date?
|
37
|
+
public :up_to_date?
|
38
|
+
end
|
File without changes
|
@@ -2,6 +2,20 @@ require 'fileutils'
|
|
2
2
|
|
3
3
|
module FileUtils
|
4
4
|
|
5
|
+
module_function
|
6
|
+
|
7
|
+
# In block form, yields lines +from+-+to+. In non-block form, returns
|
8
|
+
# an array of lines +from+-+to+:
|
9
|
+
#
|
10
|
+
# # Returns lines 8-12 of 'myfile'
|
11
|
+
# FileUtils.body("myfile",8,12)
|
12
|
+
#
|
13
|
+
# CREDIT Shashank Date, via Daniel Berger.
|
14
|
+
|
15
|
+
def slice(filename,from,to) #:yield:
|
16
|
+
IO.readlines(filename)[from-1..to-1]
|
17
|
+
end
|
18
|
+
|
5
19
|
# In block form, yields the first number of +lines+ of file +filename+.
|
6
20
|
# In non-block form, it returns an array of the first number of +lines+:
|
7
21
|
#
|
@@ -37,17 +51,5 @@ module FileUtils
|
|
37
51
|
IO.readlines(filename).reverse[0..lines-1].reverse
|
38
52
|
end
|
39
53
|
|
40
|
-
# In block form, yields lines +from+-+to+. In non-block form, returns
|
41
|
-
# an array of lines +from+-+to+:
|
42
|
-
#
|
43
|
-
# # Returns lines 8-12 of 'myfile'
|
44
|
-
# FileUtils.body("myfile",8,12)
|
45
|
-
#
|
46
|
-
# CREDIT Shashank Date, via Daniel Berger.
|
47
|
-
|
48
|
-
def slice(filename,from,to) #:yield:
|
49
|
-
IO.readlines(filename)[from-1..to-1]
|
50
|
-
end
|
51
|
-
|
52
54
|
end
|
53
55
|
|