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
data/lib/glue/logger.rb CHANGED
@@ -8,42 +8,42 @@ require 'logger'
8
8
  #++
9
9
 
10
10
  class Logger
11
- alias_method :devel, :debug
12
- alias_method :fine, :debug
13
-
14
- # Prints a trace message to DEBUGLOG (at debug level).
15
- # Useful for emitting the value of variables, etc. Use
16
- # like this:
17
- #
18
- # x = y = 5
19
- # trace 'x' # -> 'x = 5'
20
- # trace 'x ** y' # -> 'x ** y = 3125'
21
- #
22
- # If you have a more complicated value, like an array of
23
- # hashes, then you'll probably want to use an alternative
24
- # output format. For instance:
25
- #
26
- # trace 'value', :yaml
27
- #
28
- # Valid output format values (the _style_ parameter) are:
29
- #
30
- # :p :inspect
31
- # :pp (pretty-print, using 'pp' library)
32
- # :s :to_s
33
- # :y :yaml :to_yaml (using the 'yaml' library')
34
- #
35
- # The default is <tt>:p</tt>.
36
- #
37
- # CREDITS:
38
- #
39
- # This code comes straight from the dev-utils Gem.
40
- # Author: Gavin Sinclair <gsinclair@soyabean.com.au>
41
-
11
+ alias_method :devel, :debug
12
+ alias_method :fine, :debug
13
+
14
+ # Prints a trace message to DEBUGLOG (at debug level).
15
+ # Useful for emitting the value of variables, etc. Use
16
+ # like this:
17
+ #
18
+ # x = y = 5
19
+ # trace 'x' # -> 'x = 5'
20
+ # trace 'x ** y' # -> 'x ** y = 3125'
21
+ #
22
+ # If you have a more complicated value, like an array of
23
+ # hashes, then you'll probably want to use an alternative
24
+ # output format. For instance:
25
+ #
26
+ # trace 'value', :yaml
27
+ #
28
+ # Valid output format values (the _style_ parameter) are:
29
+ #
30
+ # :p :inspect
31
+ # :pp (pretty-print, using 'pp' library)
32
+ # :s :to_s
33
+ # :y :yaml :to_yaml (using the 'yaml' library')
34
+ #
35
+ # The default is <tt>:p</tt>.
36
+ #
37
+ # CREDITS:
38
+ #
39
+ # This code comes straight from the dev-utils Gem.
40
+ # Author: Gavin Sinclair <gsinclair@soyabean.com.au>
41
+
42
42
  def trace(expr, style=:p)
43
43
  unless expr.respond_to? :to_str
44
44
  warn "trace: Can't evaluate the given value: #{caller.first}"
45
45
  else
46
- require 'facet/binding-of-caller'
46
+ require 'facet/binding-of-caller'
47
47
 
48
48
  Binding.of_caller do |b|
49
49
  value = b.eval(expr.to_str)
@@ -56,7 +56,7 @@ class Logger
56
56
  message = "#{expr} = #{value_s}"
57
57
  lines = message.split(/\n/)
58
58
  indent = " "
59
- debug(lines.shift)
59
+ debug(lines.shift)
60
60
  lines.each do |line|
61
61
  debug(indent + line)
62
62
  end
@@ -66,60 +66,60 @@ class Logger
66
66
 
67
67
  TRACE_STYLES = {} # :nodoc:
68
68
  TRACE_STYLES.update(
69
- :pp => :pp_s, :s => :to_s, :p => :inspect,
70
- :y => :to_yaml, :yaml => :to_yaml,
71
- :inspect => :inspect, :to_yaml => :to_yaml
72
- )
73
-
74
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
75
- # Global logger interface.
76
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
77
-
78
- # Override the logger with your custom version.
79
-
80
- @@global_logger = Logger.new(STDERR)
81
-
82
- # Set the global Logger.
83
-
84
- def self.set(logger)
85
- if logger.is_a?(String)
86
- @@global_logger = Logger.new(logger)
87
- elsif logger.is_a?(Logger)
88
- @@global_logger = logger
89
- else
90
- raise ArgumentError.new
91
- end
92
- end
93
-
94
- def self.get
95
- @@global_logger
96
- end
97
-
98
- def self.warn(str)
99
- @@global_logger.warn(str)
100
- end
101
-
102
- def self.info(str)
103
- @@global_logger.info(str)
104
- end
105
-
106
- def self.debug(str)
107
- @@global_logger.debug(str)
108
- end
109
-
110
- def self.error(str)
111
- @@global_logger.error(str)
112
- end
113
-
114
- #--
115
- # Saddly have to duplicate the code to make
116
- # Binding.of_caller work.
117
- #++
69
+ :pp => :pp_s, :s => :to_s, :p => :inspect,
70
+ :y => :to_yaml, :yaml => :to_yaml,
71
+ :inspect => :inspect, :to_yaml => :to_yaml
72
+ )
73
+
74
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
75
+ # Global logger interface.
76
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
77
+
78
+ # Override the logger with your custom version.
79
+
80
+ @@global_logger = Logger.new(STDERR)
81
+
82
+ # Set the global Logger.
83
+
84
+ def self.set(logger)
85
+ if logger.is_a?(String)
86
+ @@global_logger = Logger.new(logger)
87
+ elsif logger.is_a?(Logger)
88
+ @@global_logger = logger
89
+ else
90
+ raise ArgumentError.new
91
+ end
92
+ end
93
+
94
+ def self.get
95
+ @@global_logger
96
+ end
97
+
98
+ def self.warn(str)
99
+ @@global_logger.warn(str)
100
+ end
101
+
102
+ def self.info(str)
103
+ @@global_logger.info(str)
104
+ end
105
+
106
+ def self.debug(str)
107
+ @@global_logger.debug(str)
108
+ end
109
+
110
+ def self.error(str)
111
+ @@global_logger.error(str)
112
+ end
113
+
114
+ #--
115
+ # Saddly have to duplicate the code to make
116
+ # Binding.of_caller work.
117
+ #++
118
118
  def self.trace(expr, style=:p)
119
119
  unless expr.respond_to? :to_str
120
120
  warn "trace: Can't evaluate the given value: #{caller.first}"
121
121
  else
122
- require 'facet/binding-of-caller'
122
+ require 'facet/binding-of-caller'
123
123
 
124
124
  Binding.of_caller do |b|
125
125
  value = eval(expr.to_str, b)
@@ -132,28 +132,28 @@ class Logger
132
132
  message = "#{expr} = #{value_s}"
133
133
  lines = message.split(/\n/)
134
134
  indent = " "
135
- debug(lines.shift)
135
+ debug(lines.shift)
136
136
  lines.each do |line|
137
137
  debug(indent + line)
138
138
  end
139
139
  end
140
140
  end
141
141
  end
142
-
143
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
144
-
145
- private
146
-
147
- # the default Ruby logger has a hardwired silly format.
148
- # we use some Ruby magic to fix it!
142
+
143
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
144
+
145
+ private
146
+
147
+ # the default Ruby logger has a hardwired silly format.
148
+ # we use some Ruby magic to fix it!
149
149
 
150
- remove_const "Format"
150
+ remove_const "Format"
151
151
 
152
- Format = "%5s: %s\n"
152
+ Format = "%5s: %s\n"
153
153
 
154
- def format_message(severity, timestamp, msg, progname)
155
- Format % [severity, msg]
156
- end
154
+ def format_message(severity, timestamp, msg, progname)
155
+ Format % [severity, msg]
156
+ end
157
157
 
158
158
  end
159
159
 
@@ -169,8 +169,8 @@ module Glue
169
169
  # logger is dissabled (@log == nil).
170
170
 
171
171
  module Logging
172
- attr_accessor :logger
173
- alias_method :log, :logger
172
+ attr_accessor :logger
173
+ alias_method :log, :logger
174
174
  end
175
175
 
176
176
  end
data/lib/glue/misc.rb CHANGED
@@ -1,15 +1,15 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id: misc.rb 1 2005-04-11 11:04:30Z gmosx $
3
+ # $Id: misc.rb 182 2005-07-22 10:07:50Z gmosx $
4
4
 
5
5
  # Executes a Ruby block without warnings.
6
6
 
7
7
  def silence_warnings
8
- old_verbose, $VERBOSE = $VERBOSE, nil
9
- begin
10
- yield
11
- ensure
12
- $VERBOSE = old_verbose
13
- end
8
+ old_verbose, $VERBOSE = $VERBOSE, nil
9
+ begin
10
+ yield
11
+ ensure
12
+ $VERBOSE = old_verbose
13
+ end
14
14
  end
15
15
 
data/lib/glue/mixins.rb CHANGED
@@ -1,36 +1,36 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id: mixins.rb 1 2005-04-11 11:04:30Z gmosx $
3
+ # $Id: mixins.rb 182 2005-07-22 10:07:50Z gmosx $
4
4
 
5
5
  module Glue
6
6
 
7
7
  # Generic expiring functionality mixin.
8
8
 
9
9
  module Expirable
10
- attr_accessor :expires
10
+ attr_accessor :expires
11
11
 
12
- # Set the expires timeout for this entry.
12
+ # Set the expires timeout for this entry.
13
13
 
14
- def expires_after(timeout = (60*60*24))
15
- @expires = Time.now + timeout
16
- end
14
+ def expires_after(timeout = (60*60*24))
15
+ @expires = Time.now + timeout
16
+ end
17
17
 
18
- # Set the expire timeout for this entry. The timeout happens
19
- # after (base + rand(spread)) seconds.
18
+ # Set the expire timeout for this entry. The timeout happens
19
+ # after (base + rand(spread)) seconds.
20
20
 
21
- def expires_spread(base, spread)
22
- @expires = Time.now + base + rand(spread)
23
- end
21
+ def expires_spread(base, spread)
22
+ @expires = Time.now + base + rand(spread)
23
+ end
24
24
 
25
- # Is this entry expired?
25
+ # Is this entry expired?
26
26
 
27
- def expired?
28
- if @expires.nil? or (Time.now > @expires)
29
- return true
30
- else
31
- return false
32
- end
33
- end
27
+ def expired?
28
+ if @expires.nil? or (Time.now > @expires)
29
+ return true
30
+ else
31
+ return false
32
+ end
33
+ end
34
34
  end
35
35
 
36
36
  end
data/lib/glue/number.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id: number.rb 74 2005-05-24 07:29:50Z gmosx $
3
+ # $Id: number.rb 182 2005-07-22 10:07:50Z gmosx $
4
4
 
5
5
  module Glue;
6
6
 
@@ -11,13 +11,13 @@ module Glue;
11
11
 
12
12
  module NumberUtils
13
13
 
14
- # Returns the multiple ceil of a number
15
-
16
- def self.ceil_multiple(num, multiple)
17
- # gmosx: to_f is needed!
18
- # gmosx: IS THERE a more optimized way to do this?
19
- return ((num.to_f/multiple).ceil*multiple)
20
- end
14
+ # Returns the multiple ceil of a number
15
+
16
+ def self.ceil_multiple(num, multiple)
17
+ # gmosx: to_f is needed!
18
+ # gmosx: IS THERE a more optimized way to do this?
19
+ return ((num.to_f/multiple).ceil*multiple)
20
+ end
21
21
 
22
22
  end
23
23
 
data/lib/glue/object.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  class Object #:nodoc:
7
7
  def remove_subclasses_of(superclass)
8
8
  subclasses_of(superclass).each do |subclass|
9
- Object.send(:remove_const, subclass) rescue nil
9
+ Object.send(:remove_const, subclass) rescue nil
10
10
  end
11
11
  end
12
12
 
@@ -14,7 +14,7 @@ class Object #:nodoc:
14
14
  subclasses = []
15
15
  ObjectSpace.each_object(Class) do |c|
16
16
  if c.ancestors.include?(superclass) and superclass != c
17
- subclasses << c
17
+ subclasses << c
18
18
  end
19
19
  end
20
20
  return subclasses
data/lib/glue/pool.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id: pool.rb 1 2005-04-11 11:04:30Z gmosx $
3
+ # $Id: pool.rb 182 2005-07-22 10:07:50Z gmosx $
4
4
 
5
5
  require 'thread'
6
6
  require 'monitor'
@@ -13,48 +13,48 @@ module Glue
13
13
  # INVESTIGATE: Could use the SizedQueue/Queue.
14
14
 
15
15
  class Pool < Array
16
- include MonitorMixin
17
-
18
- def initialize
19
- super
20
- @cv = new_cond()
21
- end
22
-
23
- # Add, restore an object to the pool.
24
-
25
- def push(obj)
26
- synchronize do
27
- super
28
- @cv.signal()
29
- end
30
- end
31
-
32
- # Obtain an object from the pool.
33
-
34
- def pop
35
- synchronize do
36
- @cv.wait_while { empty? }
37
- super
38
- end
39
- end
40
-
41
- # Obtains an object, passes it to a block for processing
42
- # and restores it to the pool.
43
-
44
- def obtain
45
- result = nil
46
-
47
- begin
48
- obj = pop()
49
-
50
- result = yield(obj)
51
- ensure
52
- push(obj)
53
- end
54
-
55
- return result
56
- end
57
-
16
+ include MonitorMixin
17
+
18
+ def initialize
19
+ super
20
+ @cv = new_cond()
21
+ end
22
+
23
+ # Add, restore an object to the pool.
24
+
25
+ def push(obj)
26
+ synchronize do
27
+ super
28
+ @cv.signal()
29
+ end
30
+ end
31
+
32
+ # Obtain an object from the pool.
33
+
34
+ def pop
35
+ synchronize do
36
+ @cv.wait_while { empty? }
37
+ super
38
+ end
39
+ end
40
+
41
+ # Obtains an object, passes it to a block for processing
42
+ # and restores it to the pool.
43
+
44
+ def obtain
45
+ result = nil
46
+
47
+ begin
48
+ obj = pop()
49
+
50
+ result = yield(obj)
51
+ ensure
52
+ push(obj)
53
+ end
54
+
55
+ return result
56
+ end
57
+
58
58
  end
59
59
 
60
60
  end