core_ex 0.4.0 → 0.5.1.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/ChangeLog +251 -0
- data/NEWS +29 -0
- data/README +1 -1
- data/SPEC.yml +10 -10
- data/lib/core_ex/dependencies_ext/constant_load_path.rb +1 -1
- data/lib/core_ex/embedded_tests.rb +1 -1
- data/lib/core_ex/enumerable.rb +87 -5
- data/lib/core_ex/exception.rb +1 -1
- data/lib/core_ex/file_utils.rb +1 -1
- data/lib/core_ex/lazy_loading.rb +159 -0
- data/lib/core_ex/module/attr_once.rb +1 -1
- data/lib/core_ex/module/import.rb +4 -6
- data/lib/core_ex/module/in_place.rb +1 -1
- data/lib/core_ex/module/mix_in_with_args.rb +1 -1
- data/lib/core_ex/numeric.rb +46 -0
- data/lib/core_ex/object/instance_eval_with_args.rb +1 -1
- data/lib/core_ex/object/singleton_class.rb +1 -1
- data/lib/core_ex/object/the_first_time.rb +1 -1
- data/lib/core_ex/pathname.rb +17 -11
- data/lib/core_ex/proc.rb +80 -1
- data/lib/core_ex/rakefile_base.rf +192 -296
- data/lib/core_ex/require.rb +1 -1
- data/lib/core_ex/string.rb +11 -2
- data/lib/core_ex/time.rb +1 -1
- data/lib/core_ex/try_dup.rb +1 -1
- data/lib/core_ex/yaml.rb +101 -79
- data/lib/core_ex.rb +129 -128
- data/lib/d_time.rb +225 -53
- data/lib/dumpable_proc.rb +1 -10
- data/lib/path_list.rb +18 -7
- data/lib/temp_path.rb +3 -3
- data/lib/test/unit/u_i/yaml/test_runner.rb +1 -1
- data/lib/version.rb +309 -69
- data/lib/yaml_extension.rb +1 -1
- data/test/fixtures/lazy_loading/a_b/a/c.rb +6 -0
- data/test/fixtures/lazy_loading/a_b/a.rb +2 -0
- data/test/fixtures/lazy_loading/a_b/b/c.rb +4 -0
- data/test/fixtures/lazy_loading/a_b/b.rb +2 -0
- data/test/fixtures/lazy_loading/double/a/bouhou.rb +2 -0
- data/test/fixtures/lazy_loading/double/a/foo_bar.rb +5 -0
- data/test/fixtures/lazy_loading/double/a/sub/a/suba.rb +7 -0
- data/test/fixtures/lazy_loading/double/b/root/sub/b.rb +6 -0
- data/test/fixtures/lazy_loading/double/b/root/sub.rb +4 -0
- data/test/fixtures/lazy_loading/double/b/root.rb +2 -0
- data/test/fixtures/lazy_loading/foo_bars/foo_bar.rb +4 -0
- data/test/fixtures/lazy_loading/foo_bars/mods/mod.rb +6 -0
- data/test/fixtures/lazy_loading/foo_bars/mods/sub_mod.rb +6 -0
- data/test/fixtures/lazy_loading/foo_bars/mods/sub_sub_mod.rb +7 -0
- data/test/fixtures/lazy_loading/foo_bars/mods.rb +4 -0
- data/test/fixtures/lazy_loading/foo_bars/sub_foo_bar.rb +5 -0
- data/test/fixtures/lazy_loading/foo_bars/titis/tutu.rb +6 -0
- data/test/fixtures/lazy_loading/foo_bars/totos.rb +6 -0
- data/test/fixtures/lazy_loading/foo_bars.rb +4 -0
- data/test/lazy_loading/test_already_present_name_absolute.rb +6 -0
- data/test/lazy_loading/test_already_present_name_relative.rb +11 -0
- data/test/lazy_loading/test_inside_another_module.rb +5 -0
- data/test/lazy_loading/test_lazy_loading.rb +179 -0
- data/test/sanity/multiple-requires.yml +22 -4
- data/test/unit-suite.yml +5 -4
- metadata +119 -80
- data/SPEC.dyn.yml +0 -10
- data/SPEC.gemspec +0 -13
- data/test/test-unit-setup.rb +0 -19
- /data/test/{resources → fixtures}/require/test_require +0 -0
- /data/test/{resources → fixtures}/require/test_require_rb.rb +0 -0
- /data/test/{resources → fixtures}/require/test_require_so.so +0 -0
- /data/test/{resources → fixtures}/use-from-gems.rb +0 -0
- /data/test/{resources → fixtures}/yaml_testrunner/unit_test.rb +0 -0
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
2
|
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
3
|
# License:: Gnu General Public License.
|
4
|
-
# Revision:: $Id: import.rb
|
4
|
+
# Revision:: $Id: /w/fey/ruby_ex/trunk/core_ex/lib/core_ex/module/import.rb 8038 2005-12-31T02:27:43.641243Z ertai $
|
5
5
|
|
6
6
|
|
7
7
|
module CoreEx
|
@@ -10,13 +10,11 @@ module CoreEx
|
|
10
10
|
|
11
11
|
module Import
|
12
12
|
|
13
|
-
def
|
13
|
+
def import! ( *args )
|
14
14
|
return true if args.empty?
|
15
|
-
Dependency.
|
15
|
+
Dependency.depend_on(*args)
|
16
16
|
end
|
17
17
|
|
18
|
-
alias_method :import!, :require_or_load
|
19
|
-
|
20
18
|
end # module Import
|
21
19
|
|
22
20
|
end # module Module
|
@@ -25,4 +23,4 @@ end # module CoreEx
|
|
25
23
|
|
26
24
|
test_section __FILE__ do
|
27
25
|
|
28
|
-
end
|
26
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
2
|
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
3
|
# License:: Gnu General Public License.
|
4
|
-
# Revision:: $Id: in_place.rb
|
4
|
+
# Revision:: $Id: /w/fey/ruby_ex/trunk/core_ex/lib/core_ex/module/in_place.rb 7986 2005-10-02T14:34:28.115711Z ertai $
|
5
5
|
|
6
6
|
module CoreEx
|
7
7
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
2
|
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
3
|
# License:: Gnu General Public License.
|
4
|
-
# Revision:: $Id: mix_in_with_args.rb
|
4
|
+
# Revision:: $Id: /w/fey/ruby_ex/trunk/core_ex/lib/core_ex/module/mix_in_with_args.rb 7960 2005-09-15T23:18:43.901701Z ertai $
|
5
5
|
|
6
6
|
|
7
7
|
class Module
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
|
+
# License:: Gnu General Public License.
|
4
|
+
# Revision:: $Id: /w/fey/ruby_ex/trunk/core_ex/lib/core_ex/numeric.rb 8026 2005-12-06T16:19:28.192022Z ertai $
|
5
|
+
|
6
|
+
|
7
|
+
module CoreEx
|
8
|
+
|
9
|
+
module Numeric
|
10
|
+
|
11
|
+
def fact
|
12
|
+
result = 1
|
13
|
+
i = self
|
14
|
+
until i.zero? do
|
15
|
+
result *= i
|
16
|
+
i -= 1
|
17
|
+
end
|
18
|
+
result
|
19
|
+
end
|
20
|
+
alias_method :_!, :fact
|
21
|
+
|
22
|
+
end # module Numeric
|
23
|
+
|
24
|
+
::Numeric.send :include, Numeric
|
25
|
+
|
26
|
+
test_section __FILE__ do
|
27
|
+
class TestNumeric < ::Test::Unit::TestCase
|
28
|
+
|
29
|
+
def setup
|
30
|
+
end
|
31
|
+
|
32
|
+
def teardown
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_fact
|
36
|
+
assert_equal 403291461126605635584000000, 26._!
|
37
|
+
assert_equal 1, 0._!
|
38
|
+
assert_equal 1, 1._!
|
39
|
+
assert_equal 24, 4._!
|
40
|
+
end
|
41
|
+
|
42
|
+
end # class TestNumeric
|
43
|
+
end
|
44
|
+
|
45
|
+
end # module CoreEx
|
46
|
+
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
2
|
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
3
|
# License:: Gnu General Public License.
|
4
|
-
# Revision:: $Id: instance_eval_with_args.rb
|
4
|
+
# Revision:: $Id: /w/fey/ruby_ex/trunk/core_ex/lib/core_ex/object/instance_eval_with_args.rb 7960 2005-09-15T23:18:43.901701Z ertai $
|
5
5
|
|
6
6
|
|
7
7
|
module CoreEx
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
2
|
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
3
|
# License:: Gnu General Public License.
|
4
|
-
# Revision:: $Id: singleton_class.rb
|
4
|
+
# Revision:: $Id: /w/fey/ruby_ex/trunk/core_ex/lib/core_ex/object/singleton_class.rb 7987 2005-10-02T14:49:42.566599Z ertai $
|
5
5
|
|
6
6
|
|
7
7
|
module CoreEx
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
2
|
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
3
|
# License:: Gnu General Public License.
|
4
|
-
# Revision:: $Id: the_first_time.rb
|
4
|
+
# Revision:: $Id: /w/fey/ruby_ex/trunk/core_ex/lib/core_ex/object/the_first_time.rb 7987 2005-10-02T14:49:42.566599Z ertai $
|
5
5
|
|
6
6
|
|
7
7
|
module CoreEx
|
data/lib/core_ex/pathname.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
# Author: Nicolas Despres <polrop@lrde.epita.fr>.
|
3
3
|
# License: Gnu General Public License.
|
4
4
|
|
5
|
-
# $LastChangedBy:
|
6
|
-
# $Id: pathname.rb
|
5
|
+
# $LastChangedBy: pouillar $
|
6
|
+
# $Id: /w/fey/ruby_ex/trunk/core_ex/lib/core_ex/pathname.rb 22106 2006-02-21T23:09:19.405133Z pouillar $
|
7
7
|
|
8
8
|
|
9
9
|
|
@@ -17,6 +17,14 @@ module CoreEx
|
|
17
17
|
alias_method :split_no_args, :split
|
18
18
|
end
|
19
19
|
|
20
|
+
def overwrite ( new_contents )
|
21
|
+
open('w') do |file|
|
22
|
+
file.print new_contents
|
23
|
+
end
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
|
20
28
|
# Allow this kind of things:
|
21
29
|
#
|
22
30
|
# root = Pathname.new('/tmp/test')
|
@@ -118,11 +126,11 @@ module CoreEx
|
|
118
126
|
|
119
127
|
attr_accessor :open_mode
|
120
128
|
|
121
|
-
def split_with_load_path ( load_paths
|
129
|
+
def split_with_load_path ( load_paths=$LOAD_PATH )
|
122
130
|
str = to_s
|
123
131
|
load_paths = load_paths.sort { |x, y| y.to_path.to_s.size <=> x.to_path.to_s.size }
|
124
132
|
load_paths.each do |load_path|
|
125
|
-
if str =~ /^#{Regexp.quote(load_path
|
133
|
+
if str =~ /^#{Regexp.quote(load_path)}\/*(.*)/
|
126
134
|
return [load_path.to_path, Regexp.last_match[1].to_path]
|
127
135
|
end
|
128
136
|
end
|
@@ -136,12 +144,10 @@ module CoreEx
|
|
136
144
|
|
137
145
|
def load_path!
|
138
146
|
string = expand_path.cleanpath.to_s
|
139
|
-
raise "bad path name `#{
|
140
|
-
|
141
|
-
path = string.to_path
|
142
|
-
return false if Controllers.load_paths.any? { |c| c.to_path == path }
|
143
|
-
Controllers.load_paths.unshift Dependencies::ConstantLoadPath.new(string)
|
147
|
+
raise "bad path name `#{path}' need a directory" unless directory?
|
148
|
+
return false if $LOAD_PATH.include? string
|
144
149
|
$LOAD_PATH.unshift string
|
150
|
+
return true
|
145
151
|
end
|
146
152
|
|
147
153
|
def expand_path_with ( directories, extensions=nil )
|
@@ -226,8 +232,8 @@ test_section __FILE__ do
|
|
226
232
|
|
227
233
|
def setup
|
228
234
|
@test = __FILE__.to_path.dirname.parent.parent + 'test'
|
229
|
-
@
|
230
|
-
@req = @
|
235
|
+
@fixtures = @test + 'fixtures'
|
236
|
+
@req = @fixtures + 'require'
|
231
237
|
@s = 'test_require'
|
232
238
|
@s_dne = 'test_require_dne'
|
233
239
|
@s_so = 'test_require_so.so'
|
data/lib/core_ex/proc.rb
CHANGED
@@ -1,13 +1,19 @@
|
|
1
1
|
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
2
|
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
3
|
# License:: Gnu General Public License.
|
4
|
-
# Revision:: $Id: proc.rb
|
4
|
+
# Revision:: $Id: /w/fey/ruby_ex/trunk/core_ex/lib/core_ex/proc.rb 8014 2005-10-26T12:35:42.562387Z ertai $
|
5
5
|
|
6
6
|
|
7
7
|
module CoreEx
|
8
8
|
|
9
9
|
module Proc
|
10
10
|
|
11
|
+
class ArityError < ArgumentError
|
12
|
+
def initialize
|
13
|
+
super("Bad number of arguments")
|
14
|
+
end
|
15
|
+
end # class ArityError
|
16
|
+
|
11
17
|
setup do
|
12
18
|
have YamlExtension
|
13
19
|
end
|
@@ -28,6 +34,27 @@ module CoreEx
|
|
28
34
|
to_s
|
29
35
|
end
|
30
36
|
|
37
|
+
def to_proc
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
def instance_call ( anObject, *args, &block )
|
42
|
+
argc = args.size
|
43
|
+
case arity
|
44
|
+
when 1 + argc
|
45
|
+
call(anObject, *args, &block)
|
46
|
+
when argc, -1
|
47
|
+
raise ArgumentError, "No block needed" if block
|
48
|
+
anObject.instance_eval_with_args(*args, &self)
|
49
|
+
else
|
50
|
+
if arity < 0 and argc >= arity.abs - 2
|
51
|
+
call(anObject, *args, &block)
|
52
|
+
else
|
53
|
+
raise ArityError
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
31
58
|
module ClassMethods
|
32
59
|
def yaml_load ( val )
|
33
60
|
DumpableProc.new(val.to_s)
|
@@ -47,6 +74,15 @@ module CoreEx
|
|
47
74
|
method(:teardown).to_proc => __LINE__,
|
48
75
|
TestProc.instance_method(:setup).bind(self).to_proc => __LINE__
|
49
76
|
}
|
77
|
+
mock_args = @mock_args = []
|
78
|
+
@m_ = proc { mock_args << [:_, object_id] }
|
79
|
+
@m_0 = proc { || mock_args << [:'0', object_id] }
|
80
|
+
@m_as = proc { |*a| mock_args << [:as, a, object_id] }
|
81
|
+
@m_a_bs = proc { |a, *b| mock_args << [:a_bs, a, b, object_id] }
|
82
|
+
@m_a = proc { |a| mock_args << [:a, a, object_id] }
|
83
|
+
@m_a_b = proc { |a, b| mock_args << [:a_b, a, b, object_id] }
|
84
|
+
@m_a_b_c = proc { |a, b, c| mock_args << [:a_b_c, a, b, c, object_id] }
|
85
|
+
@m_procs = [@m_, @m_0, @m_as, @m_a_bs, @m_a, @m_a_b, @m_a_b_c]
|
50
86
|
end
|
51
87
|
|
52
88
|
def teardown
|
@@ -70,6 +106,49 @@ module CoreEx
|
|
70
106
|
assert_equal(10, @val[])
|
71
107
|
end
|
72
108
|
|
109
|
+
def assert_instance_call ( ref, proc, args )
|
110
|
+
assert_nothing_raised do
|
111
|
+
begin
|
112
|
+
proc.instance_call(*args)
|
113
|
+
rescue Proc::ArityError => ex
|
114
|
+
assert_equal :ArityError, ref
|
115
|
+
assert_equal [], @mock_args
|
116
|
+
return
|
117
|
+
end
|
118
|
+
end
|
119
|
+
assert_equal ref, @mock_args.shift
|
120
|
+
assert_equal [], @mock_args
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_instance_call
|
124
|
+
a, b, c = 'a', 'b', 'c'
|
125
|
+
ai, bi, ci, si = a.object_id, b.object_id, c.object_id, object_id
|
126
|
+
|
127
|
+
assert_instance_call [:_, ai], @m_, [a]
|
128
|
+
assert_instance_call [:'0', ai], @m_0, [a]
|
129
|
+
assert_instance_call [:as, [], ai], @m_as, [a]
|
130
|
+
assert_instance_call [:a_bs, a, [], si], @m_a_bs, [a]
|
131
|
+
assert_instance_call [:a, a, si], @m_a, [a]
|
132
|
+
assert_instance_call :ArityError, @m_a_b, [a]
|
133
|
+
assert_instance_call :ArityError, @m_a_b_c, [a]
|
134
|
+
|
135
|
+
assert_instance_call [:_, ai], @m_, [a, b]
|
136
|
+
assert_instance_call :ArityError, @m_0, [a, b]
|
137
|
+
assert_instance_call [:as, [b], ai], @m_as, [a, b]
|
138
|
+
assert_instance_call [:a_bs, a, [b], si], @m_a_bs, [a, b]
|
139
|
+
assert_instance_call [:a, b, ai], @m_a, [a, b]
|
140
|
+
assert_instance_call [:a_b, a, b, si], @m_a_b, [a, b]
|
141
|
+
assert_instance_call :ArityError, @m_a_b_c, [a, b]
|
142
|
+
|
143
|
+
assert_instance_call [:_, ai], @m_, [a, b, c]
|
144
|
+
assert_instance_call :ArityError, @m_0, [a, b, c]
|
145
|
+
assert_instance_call [:as, [b, c], ai], @m_as, [a, b, c]
|
146
|
+
assert_instance_call [:a_bs, a, [b, c], si], @m_a_bs, [a, b, c]
|
147
|
+
assert_instance_call :ArityError, @m_a, [a, b, c]
|
148
|
+
assert_instance_call [:a_b, b, c, ai], @m_a_b, [a, b, c]
|
149
|
+
assert_instance_call [:a_b_c, a, b, c, si], @m_a_b_c, [a, b, c]
|
150
|
+
end
|
151
|
+
|
73
152
|
end # class TestProc
|
74
153
|
|
75
154
|
end
|