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
 
    
        data/lib/glue/logger.rb
    CHANGED
    
    | 
         @@ -8,42 +8,42 @@ require 'logger' 
     | 
|
| 
       8 
8 
     | 
    
         
             
            #++
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
            class Logger
         
     | 
| 
       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 
     | 
    
         
            +
              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 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
       108 
     | 
    
         
            -
             
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
             
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
             
     | 
| 
       115 
     | 
    
         
            -
             
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       146 
     | 
    
         
            -
             
     | 
| 
       147 
     | 
    
         
            -
             
     | 
| 
       148 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
      
 150 
     | 
    
         
            +
              remove_const "Format"
         
     | 
| 
       151 
151 
     | 
    
         | 
| 
       152 
     | 
    
         
            -
             
     | 
| 
      
 152 
     | 
    
         
            +
              Format = "%5s: %s\n"
         
     | 
| 
       153 
153 
     | 
    
         | 
| 
       154 
     | 
    
         
            -
             
     | 
| 
       155 
     | 
    
         
            -
             
     | 
| 
       156 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       173 
     | 
    
         
            -
             
     | 
| 
      
 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  
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
      
 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  
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
      
 10 
     | 
    
         
            +
              attr_accessor :expires
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
      
 12 
     | 
    
         
            +
              # Set the expires timeout for this entry.
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
              def expires_after(timeout = (60*60*24))
         
     | 
| 
      
 15 
     | 
    
         
            +
                @expires = Time.now + timeout
         
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 18 
     | 
    
         
            +
              # Set the expire timeout for this entry. The timeout happens
         
     | 
| 
      
 19 
     | 
    
         
            +
              # after (base + rand(spread)) seconds.
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
      
 21 
     | 
    
         
            +
              def expires_spread(base, spread)
         
     | 
| 
      
 22 
     | 
    
         
            +
                @expires = Time.now + base + rand(spread)
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
      
 25 
     | 
    
         
            +
              # Is this entry expired?
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
      
 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  
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
      
 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  
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     |