facets 2.9.0 → 2.9.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module FileUtils
|
4
|
+
module_function
|
5
|
+
|
6
|
+
# Stage by hard linking included files to a stage directory.
|
7
|
+
#
|
8
|
+
# stage_directory - Where to stage the files
|
9
|
+
# source_directory - Where to find files to stage
|
10
|
+
# files - Files to link in stage relative to source
|
11
|
+
#
|
12
|
+
# TODO: Rename to #link_stage or something less likely to name clash?
|
13
|
+
# TODO: Add options for :verbose, :noop and :dryrun ?
|
14
|
+
#
|
15
|
+
def stage(stage_directory, source_directory, files, options={})
|
16
|
+
return stage_directory if options[:noop] || options[:dryrun]
|
17
|
+
|
18
|
+
stage_directory, source_directory = stage_directory.to_s, source_directory.to_s
|
19
|
+
## ensure existance of staging area
|
20
|
+
rm_r(stage_directory) if File.directory?(stage_directory)
|
21
|
+
mkdir_p(stage_directory)
|
22
|
+
## link files into staging area
|
23
|
+
files.each do |f|
|
24
|
+
src = File.join(source_directory, f)
|
25
|
+
file = File.join(stage_directory, f)
|
26
|
+
if File.directory?(src)
|
27
|
+
mkdir_p(file) unless File.exist?(file)
|
28
|
+
else
|
29
|
+
fdir = File.dirname(file)
|
30
|
+
mkdir_p(fdir) unless File.exist?(fdir)
|
31
|
+
unless File.exist?(file) and File.mtime(file) >= File.mtime(src)
|
32
|
+
ln(src, file) #safe_ln ?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
return stage_directory
|
37
|
+
end
|
38
|
+
|
39
|
+
# Make public (for all submodules too).
|
40
|
+
public :stage
|
41
|
+
|
42
|
+
module NoWrite
|
43
|
+
module_function
|
44
|
+
def stage(stage_directory, files, options={})
|
45
|
+
options[:noop] = true
|
46
|
+
FileUtils.stage(stage_directory, files, options={})
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
module Verbose
|
51
|
+
module_function
|
52
|
+
def stage(stage_directory, files, options={})
|
53
|
+
options[:verbose] = true
|
54
|
+
FileUtils.stage(stage_directory, files, options={})
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
module DryRun
|
59
|
+
module_function
|
60
|
+
def stage(stage_directory, files, options={})
|
61
|
+
options[:dryrun] = true
|
62
|
+
FileUtils.stage(stage_directory, files, options={})
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module Net
|
4
|
+
|
5
|
+
# CREDIT: Daniel Huckstep
|
6
|
+
def self.download(url, limit=10)
|
7
|
+
raise ArgumentError, 'HTTP redirect too deep' if limit == 0
|
8
|
+
#url = URI.parse(url)
|
9
|
+
#req = Net::HTTP::Get.new(url.path)
|
10
|
+
#req['User-Agent'] = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.7) Gecko/2009030422 Ubuntu/8.10 (intrepid) Firefox/3.0.7"
|
11
|
+
#resp = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
|
12
|
+
resp = Net::HTTP.get_response(URI.parse(url))
|
13
|
+
case resp
|
14
|
+
when Net::HTTPSuccess then resp
|
15
|
+
when Net::HTTPRedirection then download(resp['location'], limit - 1)
|
16
|
+
else resp.error!
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# CREDIT: Daniel Huckstep
|
21
|
+
def self.download_and_save(url, path=nil)
|
22
|
+
if path.nil?
|
23
|
+
path = File.expand_path(url.split('/').last)
|
24
|
+
else
|
25
|
+
path = File.expand_path(path)
|
26
|
+
end
|
27
|
+
raise ArgumentError.new('Save path is a directory') if File.directory?(path)
|
28
|
+
resp = download(url)
|
29
|
+
open(path,'w') { |file| file.write(resp.body) } if resp.is_a?(Net::HTTPSuccess)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
File without changes
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'facets/hash/
|
1
|
+
require 'facets/hash/zip'
|
2
2
|
require 'facets/string/shatter'
|
3
3
|
require 'facets/kernel/maybe'
|
4
4
|
|
@@ -314,7 +314,7 @@ class Random
|
|
314
314
|
# h.shuffle #~> {:b=>2, :c=>1, :a>3}
|
315
315
|
#
|
316
316
|
def shuffle
|
317
|
-
::Hash.
|
317
|
+
::Hash.zip( keys.sort_by{Random.number}, values.sort_by{Random.number} )
|
318
318
|
end
|
319
319
|
|
320
320
|
# Destructive shuffle_hash. Arrange the values in
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# An extended rendition of the Ruby's standard RbConfig module.
|
2
|
+
module RbConfig
|
3
|
+
|
4
|
+
#
|
5
|
+
def self.inspect
|
6
|
+
CONFIG.inspect
|
7
|
+
end
|
8
|
+
|
9
|
+
# Methodized lookup of config.
|
10
|
+
def self.method_missing(s,*a,&b)
|
11
|
+
s = s.to_s
|
12
|
+
if CONFIG.key?(s)
|
13
|
+
CONFIG[s]
|
14
|
+
elsif CONFIG.key?(s.upcase)
|
15
|
+
CONFIG[s.upcase]
|
16
|
+
else
|
17
|
+
super(s,*a,&b)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# TODO: parse configure_args into methods too?
|
22
|
+
|
23
|
+
# In case rubygems has already defined it.
|
24
|
+
unless method_defined?(:datadir)
|
25
|
+
# Return the path to the data directory associated with the
|
26
|
+
# given library/package name. Normally this is just
|
27
|
+
#
|
28
|
+
# "#{Config::CONFIG['datadir']}/#{name}"
|
29
|
+
#
|
30
|
+
# but may be modified by tools like RubyGems to handle
|
31
|
+
# versioned data directories.
|
32
|
+
def self.datadir(package_name)
|
33
|
+
File.join(CONFIG['datadir'], package_name)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
def self.host_os
|
39
|
+
CONFIG['host_os']
|
40
|
+
end
|
41
|
+
|
42
|
+
def linux?
|
43
|
+
host_os =~ /linux|cygwin/
|
44
|
+
end
|
45
|
+
|
46
|
+
def mac?
|
47
|
+
host_os =~ /mac|darwin/
|
48
|
+
end
|
49
|
+
|
50
|
+
def bsd?
|
51
|
+
host_os =~ /bsd/
|
52
|
+
end
|
53
|
+
|
54
|
+
def windows?
|
55
|
+
host_os =~ /mswin|mingw/
|
56
|
+
end
|
57
|
+
|
58
|
+
def solaris?
|
59
|
+
host_os =~ /solaris|sunos/
|
60
|
+
end
|
61
|
+
|
62
|
+
# TODO: who knows what symbian returns?
|
63
|
+
def symbian?
|
64
|
+
host_os =~ /symbian/
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
def posix?
|
69
|
+
linux? or mac? or bsd? or solaris? or begin
|
70
|
+
fork do end
|
71
|
+
true
|
72
|
+
rescue NotImplementedError, NoMethodError
|
73
|
+
false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
File without changes
|
@@ -25,6 +25,8 @@ module Shellwords
|
|
25
25
|
# 1. Use platform condition?
|
26
26
|
# 2. Use separate dos_xxx methods?
|
27
27
|
# 3. Put in separate PowerShellwords module?
|
28
|
+
#
|
29
|
+
# CREDIT: Lavir the Whiolet
|
28
30
|
def dos_escape(cmdline)
|
29
31
|
'"' + cmdline.gsub(/\\(?=\\*\")/, "\\\\\\").gsub(/\"/, "\\\"").gsub(/\\$/, "\\\\\\").gsub("%", "%%") + '"'
|
30
32
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'strscan'
|
2
|
+
|
3
|
+
class StringScanner
|
4
|
+
|
5
|
+
# scans string until +pattern+ is encountered. If +pattern+ will not be
|
6
|
+
# encountered then it returns _nil_ but if +scan_anyway+ is _true_ then
|
7
|
+
# it scans until the end of the string.
|
8
|
+
def scan_before(pattern, scan_anyway = false)
|
9
|
+
if not check_until(pattern) and not scan_anyway then return nil; end
|
10
|
+
result = ""
|
11
|
+
result << getch until check(pattern) or eos?
|
12
|
+
return result
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,9 +1,12 @@
|
|
1
|
-
|
1
|
+
require 'facets/rbconfig'
|
2
2
|
|
3
|
-
|
3
|
+
unless defined?(RUBY_ENGINE)
|
4
|
+
RUBY_ENGINE = 'ruby'
|
5
|
+
end
|
4
6
|
|
5
7
|
# Platform class
|
6
8
|
#
|
9
|
+
# Original version from RubyGems, Copyright (c) 2007 Eric Hodel
|
7
10
|
class Platform
|
8
11
|
|
9
12
|
# A pure-ruby gem that may use Gem::Specification#extensions to build
|
@@ -197,15 +200,20 @@ class Platform
|
|
197
200
|
self === other
|
198
201
|
end
|
199
202
|
|
200
|
-
#
|
203
|
+
# B Y T E O R D E R
|
204
|
+
|
205
|
+
# Byte order of CPU. Determine byte order of underlying machine.
|
206
|
+
#
|
207
|
+
# Examines the byte order of the underlying machine. Returns <code>:big</code>
|
208
|
+
# if Big Endian and <code>:little</code> if Little Endian.
|
201
209
|
#
|
202
210
|
# TODO: This doesn't work well apearently. We need to use a chart for possible
|
203
211
|
# cpus instead, maybe.
|
204
212
|
def byte_order
|
205
213
|
if [0x12345678].pack("L") == "\x12\x34\x56\x78"
|
206
|
-
|
214
|
+
:big
|
207
215
|
else
|
208
|
-
|
216
|
+
:little
|
209
217
|
end
|
210
218
|
end
|
211
219
|
|
@@ -222,5 +230,148 @@ class Platform
|
|
222
230
|
byte_order == :big
|
223
231
|
end
|
224
232
|
|
233
|
+
# R U B Y E N G I N E
|
234
|
+
|
235
|
+
# Return the name of the ruby interpreter.
|
236
|
+
def interpreter
|
237
|
+
@interpreter ||= (
|
238
|
+
if RUBY_PLATFORM == 'parrot'
|
239
|
+
'cardinal'
|
240
|
+
elsif RUBY_ENGINE == 'ruby'
|
241
|
+
if RUBY_DESCRIPTION =~ /Enterprise/i
|
242
|
+
'ree'
|
243
|
+
else
|
244
|
+
'mri'
|
245
|
+
end
|
246
|
+
else
|
247
|
+
RUBY_ENGINE.to_s # jruby, rbx, ironruby, macruby, etc.
|
248
|
+
end
|
249
|
+
)
|
250
|
+
end
|
251
|
+
|
252
|
+
def mri?
|
253
|
+
'mri' === interpreter
|
254
|
+
end
|
255
|
+
alias official_ruby? mri?
|
256
|
+
alias ruby? mri?
|
257
|
+
|
258
|
+
def jruby?
|
259
|
+
'jruby' === interpreter
|
260
|
+
end
|
261
|
+
alias java? jruby?
|
262
|
+
|
263
|
+
def rubinius?
|
264
|
+
'rbx' === interpreter
|
265
|
+
end
|
266
|
+
alias rbx? rubinius?
|
267
|
+
|
268
|
+
def ree?
|
269
|
+
'ree' === interpreter
|
270
|
+
end
|
271
|
+
alias enterprise? ree?
|
272
|
+
|
273
|
+
def ironruby?
|
274
|
+
'ironruby' === interpreter
|
275
|
+
end
|
276
|
+
alias iron_ruby? ironruby?
|
277
|
+
|
278
|
+
def cardinal?
|
279
|
+
'cardinal' === interpreter
|
280
|
+
end
|
281
|
+
alias parrot? cardinal?
|
282
|
+
alias perl? cardinal?
|
283
|
+
|
284
|
+
|
285
|
+
# O P E R A T I N G S Y S T E M
|
286
|
+
|
287
|
+
def host_os
|
288
|
+
RbConfig::CONFIG['host_os']
|
289
|
+
end
|
290
|
+
|
291
|
+
def linux?
|
292
|
+
host_os =~ /linux|cygwin/
|
293
|
+
end
|
294
|
+
|
295
|
+
def mac?
|
296
|
+
host_os =~ /mac|darwin/
|
297
|
+
end
|
298
|
+
|
299
|
+
def bsd?
|
300
|
+
host_os =~ /bsd/
|
301
|
+
end
|
302
|
+
|
303
|
+
def windows?
|
304
|
+
host_os =~ /mswin|mingw/
|
305
|
+
end
|
306
|
+
|
307
|
+
def solaris?
|
308
|
+
host_os =~ /solaris|sunos/
|
309
|
+
end
|
310
|
+
|
311
|
+
# TODO: who knows what symbian returns?
|
312
|
+
def symbian?
|
313
|
+
host_os =~ /symbian/
|
314
|
+
end
|
315
|
+
|
316
|
+
#
|
317
|
+
def posix?
|
318
|
+
linux? or mac? or bsd? or solaris? or begin
|
319
|
+
fork do end
|
320
|
+
true
|
321
|
+
rescue NotImplementedError, NoMethodError
|
322
|
+
false
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
225
326
|
end
|
226
327
|
|
328
|
+
|
329
|
+
# Current CPU's Byte Order
|
330
|
+
#BYTE_ORDER = RbConfig.byte_order
|
331
|
+
|
332
|
+
# Current CPU
|
333
|
+
#CPU = RbConfig.platform.cpu
|
334
|
+
|
335
|
+
# Current Operating System
|
336
|
+
#OS = RbConfig.platform.os
|
337
|
+
|
338
|
+
# Current Operating System Version
|
339
|
+
#OS_VERSION = RbConfig.platform.version
|
340
|
+
|
341
|
+
|
342
|
+
=begin
|
343
|
+
# platform
|
344
|
+
def current_platform
|
345
|
+
arch = Config::CONFIG['arch']
|
346
|
+
#cpu, os = arch.split '-', 2
|
347
|
+
return match_platform(arch)
|
348
|
+
end
|
349
|
+
|
350
|
+
#
|
351
|
+
def match_platform(arch)
|
352
|
+
cpu, os = arch.split '-', 2
|
353
|
+
cpu, os = nil, cpu if os.nil? # java
|
354
|
+
|
355
|
+
cpu = case cpu
|
356
|
+
when /i\d86/ then 'x86'
|
357
|
+
else cpu
|
358
|
+
end
|
359
|
+
|
360
|
+
os = case os
|
361
|
+
when /cygwin/ then [ 'cygwin', nil ]
|
362
|
+
when /darwin(\d+)?/ then [ 'darwin', $1 ]
|
363
|
+
when /freebsd(\d+)/ then [ 'freebsd', $1 ]
|
364
|
+
when /^java$/ then [ 'java', nil ]
|
365
|
+
when /^java([\d.]*)/ then [ 'java', $1 ]
|
366
|
+
when /linux/ then [ 'linux', $1 ]
|
367
|
+
when /mingw32/ then [ 'mingw32', nil ]
|
368
|
+
when /mswin32/ then [ 'mswin32', nil ]
|
369
|
+
when /openbsd(\d+\.\d+)/ then [ 'openbsd', $1 ]
|
370
|
+
when /solaris(\d+\.\d+)/ then [ 'solaris', $1 ]
|
371
|
+
else [ 'unknown', nil ]
|
372
|
+
end
|
373
|
+
|
374
|
+
[cpu, os].flatten.compact.join("-")
|
375
|
+
end
|
376
|
+
=end
|
377
|
+
|