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.
Files changed (58) hide show
  1. data/CHANGELOG +161 -110
  2. data/INSTALL +12 -12
  3. data/README +1 -1
  4. data/Rakefile +43 -45
  5. data/doc/AUTHORS +5 -5
  6. data/doc/LICENSE +3 -3
  7. data/doc/RELEASES +32 -24
  8. data/install.rb +7 -17
  9. data/lib/facet/object/alias_class.rb +12 -0
  10. data/lib/glue.rb +35 -35
  11. data/lib/glue/array.rb +46 -46
  12. data/lib/glue/aspects.rb +199 -209
  13. data/lib/glue/attribute.rb +15 -15
  14. data/lib/glue/autoreload.rb +1 -1
  15. data/lib/glue/builder.rb +48 -0
  16. data/lib/glue/builder/xml.rb +114 -0
  17. data/lib/glue/cache.rb +189 -0
  18. data/lib/glue/configuration.rb +108 -90
  19. data/lib/glue/flexob.rb +17 -17
  20. data/lib/glue/hash.rb +71 -71
  21. data/lib/glue/helper.rb +12 -12
  22. data/lib/glue/idgen.rb +9 -0
  23. data/lib/glue/idgen/md5.rb +24 -0
  24. data/lib/glue/idgen/sequential.rb +15 -0
  25. data/lib/glue/literal_method.rb +44 -0
  26. data/lib/glue/localization.rb +130 -0
  27. data/lib/glue/logger.rb +98 -98
  28. data/lib/glue/misc.rb +7 -7
  29. data/lib/glue/mixins.rb +19 -19
  30. data/lib/glue/number.rb +8 -8
  31. data/lib/glue/object.rb +2 -2
  32. data/lib/glue/pool.rb +43 -43
  33. data/lib/glue/property.rb +392 -392
  34. data/lib/glue/sanitize.rb +34 -34
  35. data/lib/glue/settings.rb +1 -1
  36. data/lib/glue/snapshot.rb +104 -0
  37. data/lib/glue/string.rb +129 -129
  38. data/lib/glue/time.rb +53 -53
  39. data/lib/glue/uri.rb +162 -162
  40. data/lib/glue/validation.rb +421 -421
  41. data/lib/vendor/blankslate.rb +53 -0
  42. data/test/glue/builder/tc_xml.rb +56 -0
  43. data/test/glue/tc_aspects.rb +90 -90
  44. data/test/glue/tc_attribute.rb +11 -11
  45. data/test/glue/tc_builder.rb +30 -0
  46. data/test/glue/tc_configuration.rb +97 -97
  47. data/test/glue/tc_flexob.rb +10 -10
  48. data/test/glue/tc_hash.rb +23 -23
  49. data/test/glue/tc_localization.rb +49 -0
  50. data/test/glue/tc_logger.rb +31 -31
  51. data/test/glue/tc_numbers.rb +9 -9
  52. data/test/glue/tc_property.rb +67 -67
  53. data/test/glue/tc_property_mixins.rb +17 -17
  54. data/test/glue/tc_property_type_checking.rb +13 -13
  55. data/test/glue/tc_strings.rb +94 -94
  56. data/test/glue/tc_uri.rb +65 -65
  57. data/test/glue/tc_validation.rb +196 -196
  58. 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
@@ -7,95 +7,95 @@ include Glue
7
7
 
8
8
  class TestCaseAspects < Test::Unit::TestCase # :nodoc: all
9
9
 
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
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
@@ -5,18 +5,18 @@ require 'glue/attribute'
5
5
 
6
6
  class TC_Attribute < Test::Unit::TestCase # :nodoc: all
7
7
 
8
- class Dummy
9
- cattr_accessor :value, 'Default'
10
- cattr_reader :reader, 3
11
- end
8
+ class Dummy
9
+ cattr_accessor :value, 'Default'
10
+ cattr_reader :reader, 3
11
+ end
12
12
 
13
- def test_attr
14
- assert_equal 'Default', Dummy.value
15
- assert_nothing_raised { Dummy.value = 2 }
16
- assert_equal 2, Dummy.value
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
- assert_equal 3, Dummy.reader
19
- assert_raise(NoMethodError) { Dummy.reader = 19 }
20
- end
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
- setting :root_dir, :default => '/home/gmosx', :doc => 'The root directory for the app'
10
- setting :conn_count, :default => 5, :type => Fixnum
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
- setting :max_age, :default => 4, :doc => 'Maximum allowed age'
14
+ setting :max_age, :default => 4, :doc => 'Maximum allowed age'
15
15
  end
16
16
 
17
17
  class Configuration
18
- def self.clear_all_settings
19
- @@owners = Hash.new
20
- end
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
- 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
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
- end_val
103
+ end_val
104
104
 
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
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