glue 0.20.0 → 0.21.0
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 +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
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#--
|
3
|
+
# Copyright 2004 by Jim Weirich (jim@weirichhouse.org).
|
4
|
+
# All rights reserved.
|
5
|
+
|
6
|
+
# Permission is granted for use, copying, modification, distribution,
|
7
|
+
# and distribution of modified versions of this work as long as the
|
8
|
+
# above copyright notice is included.
|
9
|
+
#++
|
10
|
+
|
11
|
+
module Builder
|
12
|
+
|
13
|
+
# BlankSlate provides an abstract base class with no predefined
|
14
|
+
# methods (except for <tt>\_\_send__</tt> and <tt>\_\_id__</tt>).
|
15
|
+
# BlankSlate is useful as a base class when writing classes that
|
16
|
+
# depend upon <tt>method_missing</tt> (e.g. dynamic proxies).
|
17
|
+
class BlankSlate
|
18
|
+
class << self
|
19
|
+
def hide(name)
|
20
|
+
undef_method name if
|
21
|
+
instance_methods.include?(name.to_s) and
|
22
|
+
name !~ /^(__|instance_eval)/
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
instance_methods.each { |m| hide(m) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Since Ruby is very dynamic, methods added to the ancestors of
|
31
|
+
# BlankSlate <em>after BlankSlate is defined</em> will show up in the
|
32
|
+
# list of available BlankSlate methods. We handle this by defining a hook in the Object and Kernel classes that will hide any defined
|
33
|
+
module Kernel
|
34
|
+
class << self
|
35
|
+
alias_method :blank_slate_method_added, :method_added
|
36
|
+
def method_added(name)
|
37
|
+
blank_slate_method_added(name)
|
38
|
+
return if self != Kernel
|
39
|
+
Builder::BlankSlate.hide(name)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class Object
|
45
|
+
class << self
|
46
|
+
alias_method :blank_slate_method_added, :method_added
|
47
|
+
def method_added(name)
|
48
|
+
blank_slate_method_added(name)
|
49
|
+
return if self != Object
|
50
|
+
Builder::BlankSlate.hide(name)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'glue/builder/xml'
|
5
|
+
|
6
|
+
class TC_BuildersXml < Test::Unit::TestCase # :nodoc: all
|
7
|
+
include Glue
|
8
|
+
|
9
|
+
def test_string
|
10
|
+
x = XmlBuilder.new
|
11
|
+
|
12
|
+
x.start_tag!('html').
|
13
|
+
start_tag!('title').text!('hello').end_tag!('title').
|
14
|
+
end_tag!('html')
|
15
|
+
|
16
|
+
assert_equal '<html><title>hello</title></html>', x.buffer
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_missing
|
20
|
+
x = XmlBuilder.new
|
21
|
+
x.b('This is bold')
|
22
|
+
assert_equal '<b>This is bold</b>', x.buffer
|
23
|
+
|
24
|
+
x = XmlBuilder.new
|
25
|
+
x.a('Navel', :href => 'http://www.navel.gr')
|
26
|
+
assert_equal '<a href="http://www.navel.gr">Navel</a>', x.buffer
|
27
|
+
|
28
|
+
|
29
|
+
x = XmlBuilder.new
|
30
|
+
x.b {
|
31
|
+
x.i 'Hello', :class =>'new'
|
32
|
+
x.p 'Paragraph'
|
33
|
+
}
|
34
|
+
assert_equal '<b><i class="new">Hello</i><p>Paragraph</p></b>', x.buffer
|
35
|
+
|
36
|
+
x = XmlBuilder.new
|
37
|
+
x.hr
|
38
|
+
assert_equal '<hr />', x.buffer
|
39
|
+
|
40
|
+
x = XmlBuilder.new
|
41
|
+
x.hr(:style => 'height: 1px')
|
42
|
+
assert_equal '<hr style="height: 1px" />', x.buffer
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_xml_builder
|
46
|
+
buffer = ''
|
47
|
+
x = XmlBuilder.new(buffer)
|
48
|
+
|
49
|
+
x.start_tag!('html').
|
50
|
+
start_tag!('title').text!('hello').end_tag!('title').
|
51
|
+
end_tag!('html')
|
52
|
+
|
53
|
+
assert_equal '<html><title>hello</title></html>', buffer
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
data/test/glue/tc_aspects.rb
CHANGED
@@ -7,95 +7,95 @@ include Glue
|
|
7
7
|
|
8
8
|
class TestCaseAspects < Test::Unit::TestCase # :nodoc: all
|
9
9
|
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
10
|
+
class Monitor
|
11
|
+
def self.pre(this)
|
12
|
+
this.ma = 2
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.post(this)
|
16
|
+
this.mb = 5
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module Localize
|
21
|
+
def localize
|
22
|
+
@ll = 5
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module Tester
|
27
|
+
include Aspects
|
28
|
+
|
29
|
+
attr_accessor :ta
|
30
|
+
pre { |this| this.ta = 5 }
|
31
|
+
end
|
32
|
+
|
33
|
+
class Dummy
|
34
|
+
include Aspects
|
35
|
+
include Tester
|
36
|
+
|
37
|
+
attr_accessor :a, :b, :c
|
38
|
+
attr_accessor :oa, :ob
|
39
|
+
attr_accessor :ma, :mb
|
40
|
+
attr_accessor :ll
|
41
|
+
attr_accessor :pa
|
42
|
+
|
43
|
+
pre :pre_advice
|
44
|
+
wrap Monitor
|
45
|
+
wrap Localize, :pre => :localize
|
46
|
+
post { |this| this.pa = 3 }
|
47
|
+
|
48
|
+
def initialize
|
49
|
+
@a = 0
|
50
|
+
end
|
51
|
+
|
52
|
+
def hello(q)
|
53
|
+
@a += 1 + q
|
54
|
+
end
|
55
|
+
|
56
|
+
def pre_advice
|
57
|
+
@b = 1
|
58
|
+
@a += 1
|
59
|
+
end
|
60
|
+
|
61
|
+
def post_advice
|
62
|
+
@c = 1
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
# Class aspect.
|
68
|
+
|
69
|
+
class Observer < Aspect
|
70
|
+
def self.pre(this)
|
71
|
+
this.oa = 9
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Instance aspect.
|
76
|
+
|
77
|
+
class Epilogue < Aspect
|
78
|
+
def post(this)
|
79
|
+
this.ob = 9
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_all
|
84
|
+
Observer.wrap(Dummy, :hello)
|
85
|
+
Epilogue.new.wrap(Dummy, :hello)
|
86
|
+
Aspects.wrap(Dummy, :hello)
|
87
|
+
|
88
|
+
d = Dummy.new
|
89
|
+
d.hello(3)
|
90
|
+
assert_equal 5, d.a
|
91
|
+
assert_equal 1, d.b
|
92
|
+
assert_equal 9, d.oa
|
93
|
+
assert_equal 9, d.ob
|
94
|
+
assert_equal 2, d.ma
|
95
|
+
assert_equal 5, d.mb
|
96
|
+
assert_equal 5, d.ll
|
97
|
+
assert_equal 3, d.pa
|
98
|
+
assert_equal 5, d.ta
|
99
|
+
end
|
100
100
|
|
101
101
|
end
|
data/test/glue/tc_attribute.rb
CHANGED
@@ -5,18 +5,18 @@ require 'glue/attribute'
|
|
5
5
|
|
6
6
|
class TC_Attribute < Test::Unit::TestCase # :nodoc: all
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
class Dummy
|
9
|
+
cattr_accessor :value, 'Default'
|
10
|
+
cattr_reader :reader, 3
|
11
|
+
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def test_attr
|
14
|
+
assert_equal 'Default', Dummy.value
|
15
|
+
assert_nothing_raised { Dummy.value = 2 }
|
16
|
+
assert_equal 2, Dummy.value
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
assert_equal 3, Dummy.reader
|
19
|
+
assert_raise(NoMethodError) { Dummy.reader = 19 }
|
20
|
+
end
|
21
21
|
|
22
22
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'glue/builder'
|
5
|
+
|
6
|
+
class TC_Builder < Test::Unit::TestCase # :nodoc: all
|
7
|
+
include Glue
|
8
|
+
|
9
|
+
module TestMixin
|
10
|
+
def hello
|
11
|
+
'hello'
|
12
|
+
end
|
13
|
+
def world
|
14
|
+
'world'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class TestBuilder < Builder
|
19
|
+
include_builder TestMixin
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_all
|
23
|
+
t = TestBuilder.new(doc = '')
|
24
|
+
t.hello
|
25
|
+
t.world
|
26
|
+
assert_equal 'helloworld', doc
|
27
|
+
t.hello
|
28
|
+
assert_equal 'helloworldhello', doc
|
29
|
+
end
|
30
|
+
end
|
@@ -6,93 +6,93 @@ require 'glue/configuration'
|
|
6
6
|
# Hack: To make compatible with rake test.
|
7
7
|
|
8
8
|
class Dummy
|
9
|
-
|
10
|
-
|
9
|
+
setting :root_dir, :default => '/home/gmosx', :doc => 'The root directory for the app'
|
10
|
+
setting :conn_count, :default => 5, :type => Fixnum
|
11
11
|
end
|
12
12
|
|
13
13
|
class Another
|
14
|
-
|
14
|
+
setting :max_age, :default => 4, :doc => 'Maximum allowed age'
|
15
15
|
end
|
16
16
|
|
17
17
|
class Configuration
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
def self.clear_all_settings
|
19
|
+
@@owners = Hash.new
|
20
|
+
end
|
21
21
|
end
|
22
22
|
|
23
23
|
class TC_Configuration < Test::Unit::TestCase # :nodoc: all
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
94
|
-
|
95
|
-
|
25
|
+
class Internal
|
26
|
+
setting :radius, :default => 4
|
27
|
+
end
|
28
|
+
|
29
|
+
def setup
|
30
|
+
# gmosx: A hack to make compatible with rake. All code in this
|
31
|
+
# method is not needed if you only run this test (or in your
|
32
|
+
# real aplications of course).
|
33
|
+
|
34
|
+
Configuration.clear_all_settings
|
35
|
+
|
36
|
+
Dummy.class_eval do
|
37
|
+
setting :root_dir, :default => '/home/gmosx', :doc => 'The root directory for the app'
|
38
|
+
setting :conn_count, :default => 5, :type => Fixnum
|
39
|
+
end
|
40
|
+
|
41
|
+
Another.class_eval do
|
42
|
+
setting :max_age, :default => 4, :doc => 'Maximum allowed age'
|
43
|
+
end
|
44
|
+
|
45
|
+
Internal.class_eval do
|
46
|
+
setting :radius, :default => 4
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_all
|
51
|
+
assert_equal 4, Configuration.settings.size
|
52
|
+
assert_equal 4, Configuration.all.size
|
53
|
+
|
54
|
+
assert_equal 2, Configuration.settings(Dummy).size
|
55
|
+
assert_equal 1, Configuration.settings(Another).size
|
56
|
+
|
57
|
+
assert_equal Fixnum, Configuration.settings(Dummy)[:conn_count].type
|
58
|
+
assert_equal String, Configuration[Dummy][:root_dir].type
|
59
|
+
|
60
|
+
assert_equal '/home/gmosx', Dummy.root_dir
|
61
|
+
assert_equal 4, Another.max_age
|
62
|
+
|
63
|
+
Dummy.root_dir = '/changed/dir'
|
64
|
+
assert_equal '/changed/dir', Dummy.root_dir
|
65
|
+
assert_equal '/changed/dir', Configuration[Dummy][:root_dir].value
|
66
|
+
|
67
|
+
Another.max_age = 99
|
68
|
+
assert_equal 99, Configuration[Another][:max_age].value
|
69
|
+
|
70
|
+
# test reverse setting.
|
71
|
+
|
72
|
+
Configuration[Another][:max_age].value = 69
|
73
|
+
assert_equal 69, Configuration[Another][:max_age].value
|
74
|
+
assert_equal 69, Another.max_age
|
75
|
+
|
76
|
+
# setup
|
77
|
+
|
78
|
+
Configuration.setup(
|
79
|
+
Dummy => {
|
80
|
+
:root_dir => '/gmosx/2',
|
81
|
+
:conn_count => 12
|
82
|
+
},
|
83
|
+
Another => {
|
84
|
+
:max_age => 2
|
85
|
+
},
|
86
|
+
TC_Configuration::Internal => {
|
87
|
+
:radius => 99
|
88
|
+
}
|
89
|
+
)
|
90
|
+
|
91
|
+
assert_equal '/gmosx/2', Dummy.root_dir
|
92
|
+
assert_equal '/gmosx/2', Configuration[Dummy][:root_dir].value
|
93
|
+
assert_equal 2, Another.max_age
|
94
|
+
|
95
|
+
Configuration.parse <<-end_val
|
96
96
|
Another:
|
97
97
|
max_age: 5
|
98
98
|
TC_Configuration.Internal:
|
@@ -100,26 +100,26 @@ TC_Configuration.Internal:
|
|
100
100
|
Dummy:
|
101
101
|
root_dir: /gmosx/99
|
102
102
|
conn_count: 33
|
103
|
-
|
103
|
+
end_val
|
104
104
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
105
|
+
assert_equal '/gmosx/99', Dummy.root_dir
|
106
|
+
assert_equal '/gmosx/99', Configuration[Dummy][:root_dir].value
|
107
|
+
assert_equal 5, Another.max_age
|
108
|
+
|
109
|
+
# cooler ;-)
|
110
|
+
|
111
|
+
assert_equal String, Configuration.Dummy[:root_dir].type
|
112
|
+
assert_equal String, Configuration.Dummy.root_dir.type
|
113
|
+
|
114
|
+
# alias
|
115
|
+
|
116
|
+
assert_equal String, Settings.Dummy.root_dir.type
|
117
|
+
assert_equal 5, Settings.Another.max_age.value
|
118
|
+
|
119
|
+
# Handle namespace
|
120
|
+
|
121
|
+
assert_equal 99, Internal.radius
|
122
|
+
assert_equal 99, TC_Configuration::Internal.radius
|
123
|
+
end
|
124
124
|
|
125
125
|
end
|