glue 0.20.0 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +161 -110
- data/INSTALL +12 -12
- data/README +1 -1
- data/Rakefile +43 -45
- data/doc/AUTHORS +5 -5
- data/doc/LICENSE +3 -3
- data/doc/RELEASES +32 -24
- data/install.rb +7 -17
- data/lib/facet/object/alias_class.rb +12 -0
- data/lib/glue.rb +35 -35
- data/lib/glue/array.rb +46 -46
- data/lib/glue/aspects.rb +199 -209
- data/lib/glue/attribute.rb +15 -15
- data/lib/glue/autoreload.rb +1 -1
- data/lib/glue/builder.rb +48 -0
- data/lib/glue/builder/xml.rb +114 -0
- data/lib/glue/cache.rb +189 -0
- data/lib/glue/configuration.rb +108 -90
- data/lib/glue/flexob.rb +17 -17
- data/lib/glue/hash.rb +71 -71
- data/lib/glue/helper.rb +12 -12
- data/lib/glue/idgen.rb +9 -0
- data/lib/glue/idgen/md5.rb +24 -0
- data/lib/glue/idgen/sequential.rb +15 -0
- data/lib/glue/literal_method.rb +44 -0
- data/lib/glue/localization.rb +130 -0
- data/lib/glue/logger.rb +98 -98
- data/lib/glue/misc.rb +7 -7
- data/lib/glue/mixins.rb +19 -19
- data/lib/glue/number.rb +8 -8
- data/lib/glue/object.rb +2 -2
- data/lib/glue/pool.rb +43 -43
- data/lib/glue/property.rb +392 -392
- data/lib/glue/sanitize.rb +34 -34
- data/lib/glue/settings.rb +1 -1
- data/lib/glue/snapshot.rb +104 -0
- data/lib/glue/string.rb +129 -129
- data/lib/glue/time.rb +53 -53
- data/lib/glue/uri.rb +162 -162
- data/lib/glue/validation.rb +421 -421
- data/lib/vendor/blankslate.rb +53 -0
- data/test/glue/builder/tc_xml.rb +56 -0
- data/test/glue/tc_aspects.rb +90 -90
- data/test/glue/tc_attribute.rb +11 -11
- data/test/glue/tc_builder.rb +30 -0
- data/test/glue/tc_configuration.rb +97 -97
- data/test/glue/tc_flexob.rb +10 -10
- data/test/glue/tc_hash.rb +23 -23
- data/test/glue/tc_localization.rb +49 -0
- data/test/glue/tc_logger.rb +31 -31
- data/test/glue/tc_numbers.rb +9 -9
- data/test/glue/tc_property.rb +67 -67
- data/test/glue/tc_property_mixins.rb +17 -17
- data/test/glue/tc_property_type_checking.rb +13 -13
- data/test/glue/tc_strings.rb +94 -94
- data/test/glue/tc_uri.rb +65 -65
- data/test/glue/tc_validation.rb +196 -196
- metadata +26 -4
data/test/glue/tc_flexob.rb
CHANGED
@@ -5,15 +5,15 @@ require 'glue/flexob'
|
|
5
5
|
|
6
6
|
class TC_Flexob < Test::Unit::TestCase # :nodoc: all
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
8
|
+
def test_all
|
9
|
+
f = Flexob.new
|
10
|
+
f.title = 'Test'
|
11
|
+
f[:another] = 'Another'
|
12
|
+
|
13
|
+
assert_equal 'Test', f.title
|
14
|
+
assert_equal 'Another', f.another
|
15
|
+
assert_equal 'Another', f[:another]
|
16
|
+
assert_equal 'Another', f['another']
|
17
|
+
end
|
18
18
|
|
19
19
|
end
|
data/test/glue/tc_hash.rb
CHANGED
@@ -2,35 +2,35 @@ require "test/unit"
|
|
2
2
|
require "glue/hash"
|
3
3
|
|
4
4
|
class TestCaseGlueCache < Test::Unit::TestCase # :nodoc: all
|
5
|
-
|
5
|
+
include Glue
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
def setup
|
8
|
+
@safe_cache = SafeHash.new(Hash.new)
|
9
|
+
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
def teardown
|
12
|
+
@safe_cache = nil
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
def test_safe_cache
|
16
|
+
assert_equal(nil, @safe_cache["no_item"])
|
17
|
+
item1 = "item1"
|
18
|
+
@safe_cache["key1"] = item1
|
19
|
+
assert_equal(item1, @safe_cache["key1"])
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
@safe_cache["rem1"] = item1
|
22
|
+
@safe_cache.delete("rem1")
|
23
|
+
assert_equal(nil, @safe_cache["rem1"])
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
@safe_cache.clear()
|
26
|
+
assert_equal(0, @safe_cache.size)
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
@safe_cache["i1"] = "i1"
|
29
|
+
@safe_cache["i2"] = "i1"
|
30
|
+
@safe_cache["i3"] = "i1"
|
31
|
+
assert_equal(3, @safe_cache.size)
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
assert_equal(3, @safe_cache.values.size)
|
34
|
+
end
|
35
35
|
|
36
36
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
require 'glue/localization'
|
7
|
+
|
8
|
+
class TestCaseLocalization < Test::Unit::TestCase # :nodoc: all
|
9
|
+
include Glue
|
10
|
+
|
11
|
+
def setup
|
12
|
+
locale_en = {
|
13
|
+
'See you' => 'See you',
|
14
|
+
:long_paragraph => 'The best new books, up to 30% reduced price',
|
15
|
+
:price => 'Price: %d %s',
|
16
|
+
:proc_price => proc { |value, cur| "Price: #{value} #{cur}" }
|
17
|
+
}
|
18
|
+
|
19
|
+
locale_de = {
|
20
|
+
'See you' => 'Auf wieder sehen',
|
21
|
+
:long_paragraph => 'Die besten neuer buecher, bis zu 30% reduziert',
|
22
|
+
:price => 'Preis: %d %s',
|
23
|
+
:proc_price => proc { |value, cur| "Preis: #{value} #{cur}" }
|
24
|
+
}
|
25
|
+
|
26
|
+
Localization.add(
|
27
|
+
:en => locale_en,
|
28
|
+
:de => locale_de
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_all
|
33
|
+
lc = Localization.get
|
34
|
+
assert_equal 'See you', lc['See you']
|
35
|
+
assert_equal 'The best new books, up to 30% reduced price', lc[:long_paragraph]
|
36
|
+
|
37
|
+
lc = Localization.get(:en)
|
38
|
+
assert_equal 'See you', lc['See you']
|
39
|
+
assert_equal 'The best new books, up to 30% reduced price', lc[:long_paragraph]
|
40
|
+
assert_equal 'Price: 100 euro', lc[:price, 100, 'euro']
|
41
|
+
assert_equal 'Price: 100 euro', lc[:proc_price, 100, 'euro']
|
42
|
+
|
43
|
+
lc = Localization.get(:de)
|
44
|
+
assert_equal 'Auf wieder sehen', lc['See you']
|
45
|
+
assert_equal 'Die besten neuer buecher, bis zu 30% reduziert', lc[:long_paragraph]
|
46
|
+
assert_equal 'Preis: 100 euro', lc.translate(:price, 100, 'euro')
|
47
|
+
assert_equal 'Preis: 100 euro', lc[:proc_price, 100, 'euro']
|
48
|
+
end
|
49
|
+
end
|
data/test/glue/tc_logger.rb
CHANGED
@@ -8,36 +8,36 @@ require 'glue/logger'
|
|
8
8
|
|
9
9
|
class TC_Logger < Test::Unit::TestCase # :nodoc: all
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
11
|
+
def setup
|
12
|
+
@io = StringIO.new('')
|
13
|
+
Logger.set(Logger.new(@io))
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_logger
|
17
|
+
Logger.info 'hello'
|
18
|
+
assert_equal(" INFO: hello\n", @io.string)
|
19
|
+
|
20
|
+
# bug: Binding.of_caller thinks Logger is the caller.
|
21
|
+
a = 14
|
22
|
+
b = 13
|
23
|
+
Logger.trace 'a * b'
|
24
|
+
assert_equal(" INFO: hello\nDEBUG: a * b = 182\n", @io.string)
|
25
|
+
|
26
|
+
@io.string = ''
|
27
|
+
Logger.debug 'hello'
|
28
|
+
assert_equal("DEBUG: hello\n", @io.string)
|
29
|
+
|
30
|
+
# test logging level.
|
31
|
+
Logger.get.level = Logger::INFO
|
32
|
+
Logger.debug 'world'
|
33
|
+
assert_equal("DEBUG: hello\n", @io.string)
|
34
|
+
|
35
|
+
# bug:
|
36
|
+
Logger.error 'Have forgotten that :)'
|
37
|
+
|
38
|
+
#
|
39
|
+
Logger.set('hello.log')
|
40
|
+
assert_instance_of(Logger, Logger.get)
|
41
|
+
end
|
42
42
|
|
43
43
|
end
|
data/test/glue/tc_numbers.rb
CHANGED
@@ -2,17 +2,17 @@ require 'test/unit'
|
|
2
2
|
require 'glue/number'
|
3
3
|
|
4
4
|
class TestCaseNumberUtils < Test::Unit::TestCase # :nodoc: all
|
5
|
-
|
5
|
+
include Glue
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
def setup
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
def teardown
|
11
|
+
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def test_ceil_multiple
|
14
|
+
assert_equal(20, NumberUtils.ceil_multiple(15, 10))
|
15
|
+
assert_equal(10, NumberUtils.ceil_multiple(1, 10))
|
16
|
+
end
|
17
17
|
|
18
18
|
end
|
data/test/glue/tc_property.rb
CHANGED
@@ -7,7 +7,7 @@ require 'glue/logger'
|
|
7
7
|
require 'glue/property'
|
8
8
|
|
9
9
|
def VarChar(size)
|
10
|
-
|
10
|
+
return String, :sql => "VARCHAR(#{ size })"
|
11
11
|
end
|
12
12
|
NotNull = {:sql => "NOT NULL"}.freeze
|
13
13
|
Null = {:sql => "NULL"}.freeze
|
@@ -17,80 +17,80 @@ Property.type_checking = false
|
|
17
17
|
module Test # :nodoc: all
|
18
18
|
|
19
19
|
class Msg
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
20
|
+
include Og::Unmanageable
|
21
|
+
|
22
|
+
prop Fixnum, :owner_oid
|
23
|
+
prop_accessor :val1, :val2, :val3, Fixnum, :sql => "smallint"
|
24
|
+
prop_accessor :title, :body, String
|
25
|
+
prop_accessor :test, String, :sql => "char(10) NOT NULL"
|
26
|
+
prop_accessor :count, Fixnum
|
27
|
+
prop_accessor :create_time, Time
|
28
|
+
|
29
|
+
# a marshaled property
|
30
|
+
prop_accessor Array, :options
|
31
|
+
|
32
|
+
# property with macro arguments!
|
33
|
+
prop_accessor :address, VarChar(30), NotNull
|
34
|
+
|
35
|
+
def initialize
|
36
|
+
@create_time = Time.now
|
37
|
+
@options = []
|
38
|
+
end
|
39
39
|
|
40
40
|
end
|
41
41
|
|
42
42
|
class SubMsg < Msg
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
43
|
+
# to avoid conflicts with tc_og.rb
|
44
|
+
include Og::Unmanageable
|
45
|
+
|
46
|
+
# duplicate definition with different type!
|
47
|
+
prop_accessor :count, Float
|
48
|
+
|
49
|
+
# another property
|
50
|
+
prop_accessor :another, Fixnum
|
51
51
|
end
|
52
52
|
|
53
53
|
class TC_N_Properties < Test::Unit::TestCase
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
55
|
+
def setup
|
56
|
+
@msg1 = Msg.new
|
57
|
+
end
|
58
|
+
|
59
|
+
def teardown
|
60
|
+
@msg1 = nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_props
|
64
|
+
|
65
|
+
# bug: props for subclasses.
|
66
|
+
# bug: props propagated to base classes.
|
67
|
+
|
68
|
+
assert(SubMsg.__props)
|
69
|
+
assert_equal(Msg.__props.size(), SubMsg.__props.size() - 1)
|
70
|
+
|
71
|
+
assert_equal(11, Msg.__props.size)
|
72
|
+
assert_equal(12, SubMsg.__props.size)
|
73
|
+
|
74
|
+
# bug: duplicate definition
|
75
|
+
|
76
|
+
assert_equal(Float, SubMsg.__props.find { |p| :count == p.symbol }.klass)
|
77
|
+
|
78
|
+
# dont force conversion
|
79
|
+
|
80
|
+
@msg1.count = 2.4
|
81
|
+
assert_equal(Float, @msg1.count.class)
|
82
|
+
|
83
|
+
# force conversion
|
84
|
+
|
85
|
+
@msg1.__force_count(2.4)
|
86
|
+
assert_equal(Fixnum, @msg1.count.class)
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_macro_params
|
90
|
+
sql = Msg.__props.find { |p| :address == p.symbol }.meta[:sql]
|
91
|
+
assert_equal 'VARCHAR(30) NOT NULL', sql
|
92
|
+
end
|
93
|
+
|
94
94
|
end
|
95
95
|
|
96
96
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# * Thomas Quas <tquas@yahoo.com>
|
2
2
|
# * George Moschovitis <gm@navel.gr>
|
3
|
-
# $Id: tc_property_mixins.rb
|
3
|
+
# $Id: tc_property_mixins.rb 182 2005-07-22 10:07:50Z gmosx $
|
4
4
|
|
5
5
|
$LOAD_PATH.unshift 'lib'
|
6
6
|
|
@@ -9,13 +9,13 @@ require 'glue/property'
|
|
9
9
|
|
10
10
|
module Mixin
|
11
11
|
prop_accessor :date
|
12
|
-
|
12
|
+
meta :dummy, [123]
|
13
13
|
end
|
14
14
|
|
15
15
|
class MixedOnly
|
16
16
|
include Mixin
|
17
|
-
|
18
|
-
|
17
|
+
__meta[:dummy] << 5
|
18
|
+
__meta[:dummy] << 3
|
19
19
|
end
|
20
20
|
|
21
21
|
class MixedOnly2
|
@@ -36,13 +36,13 @@ class Empty
|
|
36
36
|
end
|
37
37
|
|
38
38
|
class Base
|
39
|
-
|
40
|
-
|
39
|
+
prop_accessor :date
|
40
|
+
meta :dummy, [123]
|
41
41
|
end
|
42
42
|
|
43
43
|
class Child1 < Base
|
44
|
-
|
45
|
-
|
44
|
+
__meta[:dummy].first << 5
|
45
|
+
__meta[:dummy].first << 3
|
46
46
|
end
|
47
47
|
|
48
48
|
class Child2 < Base
|
@@ -74,15 +74,15 @@ class TC_MixinsTest < ::Test::Unit::TestCase
|
|
74
74
|
assert( obj.respond_to?( :dummy ) )
|
75
75
|
end
|
76
76
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
77
|
+
def test_crosspolination
|
78
|
+
assert_equal 3, MixedOnly.__meta[:dummy].size
|
79
|
+
assert_equal 1, MixedOnly2.__meta[:dummy].size
|
80
|
+
assert_equal 1, Mixin.__meta[:dummy].size
|
81
81
|
=begin
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
82
|
+
gmosx: THINK!
|
83
|
+
assert_equal 3, Child1.__meta[:dummy].first.size
|
84
|
+
assert_equal 1, Child2.__meta[:dummy].first.size
|
85
|
+
assert_equal 1, Base.__meta[:dummy].first.size
|
86
86
|
=end
|
87
|
-
|
87
|
+
end
|
88
88
|
end
|