glue 0.15.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # Original code from Rails distribution.
3
3
  # http://www.rubyonrails.com
4
- # $Id$
4
+ # $Id: attribute.rb 1 2005-04-11 11:04:30Z gmosx $
5
5
 
6
6
  #--
7
7
  # Extends the module object with module and instance accessors
@@ -37,15 +37,6 @@ class Module # :nodoc:
37
37
  @@#{sym}
38
38
  end
39
39
 
40
- def call_#{sym.id2name}
41
- case @@#{sym.id2name}
42
- when Symbol then send(@@#{sym})
43
- when Proc then @@#{sym}.call(self)
44
- when String then @@#{sym}
45
- else nil
46
- end
47
- end
48
-
49
40
  end_eval
50
41
  end
51
42
  end
data/lib/glue/cache.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # * Anastasios Koutoumanos <ak@navel.gr>
3
3
  # (c) 2004-2005 Navel, all rights reserved.
4
- # $Id: cache.rb 282 2005-03-10 12:24:53Z gmosx $
4
+ # $Id: cache.rb 1 2005-04-11 11:04:30Z gmosx $
5
5
 
6
- module N
6
+ module Glue
7
7
 
8
8
  # A cache utilizing a simple LRU (Least Recently Used) policy.
9
9
  # The items managed by this cache must respond to the #key method.
@@ -1,4 +1,4 @@
1
- # Dynamic include
1
+ # = Dynamic include
2
2
  #
3
3
  # Allows you to include dyanamic mixins.
4
4
  #
@@ -23,9 +23,10 @@
23
23
  #
24
24
  # * George Moschovitis <gm@navel.gr>
25
25
  # (c) 2004-2005 Navel, all rights reserved.
26
- # $Id: dynamic_include.rb 338 2005-03-31 16:26:10Z gmosx $
26
+ # $Id: dynamic_include.rb 1 2005-04-11 11:04:30Z gmosx $
27
27
 
28
28
  class Module
29
+
29
30
  alias_method :__include_without_options__, :include
30
31
 
31
32
  def include(*args)
@@ -39,4 +40,6 @@ class Module
39
40
 
40
41
  __include_without_options__(*args)
41
42
  end
43
+ alias_method :dynamic_include, :include
44
+
42
45
  end
data/lib/glue/flexob.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id$
3
+ # $Id: flexob.rb 1 2005-04-11 11:04:30Z gmosx $
4
4
 
5
5
  require 'ostruct'
6
6
 
@@ -9,4 +9,11 @@ require 'ostruct'
9
9
 
10
10
  class Flexob < OpenStruct
11
11
 
12
+ def update(hash)
13
+ hash.each do |k, v|
14
+ send("#{k}=", v)
15
+ end
16
+ end
17
+ alias_method :set, :update
18
+
12
19
  end
data/lib/glue/hash.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id: hash.rb 282 2005-03-10 12:24:53Z gmosx $
3
+ # $Id: hash.rb 1 2005-04-11 11:04:30Z gmosx $
4
4
 
5
5
  require 'sync'
6
6
 
7
- module N
7
+ module Glue
8
8
 
9
9
  # A thread-safe hash. We use a sync object instead of a mutex,
10
10
  # because it is re-entrant. An exclusive lock is needed when
@@ -1,7 +1,7 @@
1
1
  # Code from RubyOnRails (http://www.rubyonrails.com)
2
2
  # Copyright (c) 2004-2005 David Heinemeier Hansson.
3
3
 
4
- module N
4
+ module Glue
5
5
 
6
6
  # The Inflector transforms words from singular to plural,
7
7
  # class names to table names, modulized class names to ones without,
data/lib/glue/logger.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id: logger.rb 316 2005-03-21 10:14:03Z gmosx $
3
+ # $Id: logger.rb 1 2005-04-11 11:04:30Z gmosx $
4
4
 
5
5
  require 'logger'
6
6
 
@@ -153,7 +153,7 @@ class Logger
153
153
 
154
154
  end
155
155
 
156
- module N
156
+ module Glue
157
157
 
158
158
  # Add logging capabilities to the including class.
159
159
  # When using the log/logger variables always check
data/lib/glue/misc.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id$
3
+ # $Id: misc.rb 1 2005-04-11 11:04:30Z gmosx $
4
4
 
5
5
  # Executes a Ruby block without warnings.
6
6
 
@@ -13,17 +13,3 @@ def silence_warnings
13
13
  end
14
14
  end
15
15
 
16
- #
17
-
18
- def execution_root
19
- for c in caller.reverse
20
- path = c.split(':')[-2]
21
-
22
- if path == $0
23
- return File.dirname(path)
24
- end
25
-
26
- raise 'Cannot find execution root directory'
27
- end
28
- end
29
-
data/lib/glue/mixins.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id$
3
+ # $Id: mixins.rb 1 2005-04-11 11:04:30Z gmosx $
4
4
 
5
- module N
5
+ module Glue
6
6
 
7
7
  # Generic expiring functionality mixin.
8
8
 
data/lib/glue/number.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id: number.rb 282 2005-03-10 12:24:53Z gmosx $
3
+ # $Id: number.rb 1 2005-04-11 11:04:30Z gmosx $
4
4
 
5
- module N;
5
+ module Glue;
6
6
 
7
7
  # Implement as a module to avoid class polution. You can
8
8
  # still use Ruby's advanced features to include the module in your
data/lib/glue/object.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id: object.rb 282 2005-03-10 12:24:53Z gmosx $
3
+ # $Id: object.rb 1 2005-04-11 11:04:30Z gmosx $
4
4
 
5
5
  # Code from RubyOnRails (http://www.rubyonrails.com)
6
6
 
data/lib/glue/pool.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id: pool.rb 282 2005-03-10 12:24:53Z gmosx $
3
+ # $Id: pool.rb 1 2005-04-11 11:04:30Z gmosx $
4
4
 
5
5
  require 'thread'
6
6
  require 'monitor'
7
7
 
8
- module N
8
+ module Glue
9
9
 
10
10
  # Generalized object pool implementation. Implemented as a thread
11
11
  # safe stack. Exclusive locking is needed both for push and pop.
data/lib/glue/property.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # * Michael Neumann <mneumann@ntecs.de>
3
3
  # (c) 2004-2005 Navel, all rights reserved.
4
- # $Id: property.rb 326 2005-03-28 11:07:17Z gmosx $
4
+ # $Id: property.rb 20 2005-04-15 15:18:36Z gmosx $
5
5
 
6
6
  require 'glue/attribute'
7
7
  require 'glue/array'
8
8
  require 'glue/hash'
9
9
 
10
- module N
10
+ module Glue
11
11
 
12
12
  # Ruby attributes are typeless and generally this is good.
13
13
  # Some times we need extra metadata though, for example in
@@ -91,8 +91,8 @@ module PropertyUtils
91
91
 
92
92
  def self.enchant(target, force = false)
93
93
  unless target.instance_variables.include?('@__props')
94
- target.instance_variable_set('@__meta', N::SafeHash.new)
95
- target.instance_variable_set('@__props', N::SafeArray.new)
94
+ target.instance_variable_set('@__meta', Glue::SafeHash.new)
95
+ target.instance_variable_set('@__props', Glue::SafeArray.new)
96
96
 
97
97
  # gmosx: Ruby surprises and amazes me! We are in the Metaclass
98
98
  # when defining methods and attributes so @__props is really
@@ -124,8 +124,8 @@ module PropertyUtils
124
124
 
125
125
  target.module_eval %{
126
126
  def self.inherited(child)
127
- N::PropertyUtils.enchant(child)
128
- N::PropertyUtils.copy_props(self, child)
127
+ Glue::PropertyUtils.enchant(child)
128
+ Glue::PropertyUtils.copy_props(self, child)
129
129
  # gmosx: We have to define @@__props first to avoid reusing
130
130
  # the hash from the module. super must stay at the end.
131
131
  super
@@ -139,11 +139,11 @@ module PropertyUtils
139
139
 
140
140
  target.module_eval %{
141
141
  def self.append_features(base)
142
- N::PropertyUtils.enchant(base)
143
- N::PropertyUtils.copy_props(self, base)
142
+ Glue::PropertyUtils.enchant(base)
143
+ Glue::PropertyUtils.copy_props(self, base)
144
144
  # gmosx: We have to define @@__props first to avoid reusing
145
145
  # the hash from the module. super must stay at the end.
146
- N::PropertyUtils.include_meta_mixins(base)
146
+ Glue::PropertyUtils.include_meta_mixins(base)
147
147
  super
148
148
  end
149
149
  }
@@ -230,7 +230,7 @@ module PropertyUtils
230
230
  def #{s}=(val)
231
231
  }
232
232
 
233
- if N::Property.type_checking
233
+ if Glue::Property.type_checking
234
234
  code << %{
235
235
  unless #{prop.klass} == val.class
236
236
  raise "Invalid type, expected '#{prop.klass}', is '\#\{val.class\}'."
@@ -255,9 +255,10 @@ module PropertyUtils
255
255
  # Include meta-language mixins
256
256
 
257
257
  def self.include_meta_mixins(target)
258
- target.module_eval %{ include N::Validation } if defined?(N::Validation)
258
+ target.module_eval %{ include Glue::Validation } if defined?(Glue::Validation)
259
259
  # gmosx: TODO, make Og::MetaLanguage equivalent to Validation.
260
260
  target.module_eval %{ extend Og::MetaLanguage } if defined?(Og::MetaLanguage)
261
+ target.module_eval %{ include Glue::Aspects } if defined?(Glue::Aspects)
261
262
  end
262
263
 
263
264
  # Resolves the parameters passed to the propxxx macros
@@ -314,12 +315,12 @@ class Module
314
315
  # --> creates reader and writer.
315
316
 
316
317
  def prop(*params)
317
- meta, klass, symbols = N::PropertyUtils.resolve_prop_params(params)
318
+ meta, klass, symbols = Glue::PropertyUtils.resolve_prop_params(params)
318
319
  symbol = symbols.first
319
320
 
320
- N::PropertyUtils.enchant(self)
321
+ Glue::PropertyUtils.enchant(self)
321
322
 
322
- property = N::Property.new(symbol, klass, meta)
323
+ property = Glue::Property.new(symbol, klass, meta)
323
324
 
324
325
  reader = meta[:reader] || true
325
326
  writer = writer || meta[:writer] || false
@@ -331,11 +332,11 @@ class Module
331
332
  meta[:writer] = true if meta[:writer].nil?
332
333
  end
333
334
 
334
- N::PropertyUtils.add_prop(self, property)
335
+ Glue::PropertyUtils.add_prop(self, property)
335
336
 
336
337
  # gmosx: should be placed AFTER enchant!
337
338
 
338
- N::PropertyUtils.include_meta_mixins(self)
339
+ Glue::PropertyUtils.include_meta_mixins(self)
339
340
  end
340
341
 
341
342
  # Helper method. Accepts a collection of symbols and generates
@@ -345,7 +346,7 @@ class Module
345
346
  # prop_reader String, :name, :title, :body, :sql => "char(32)"
346
347
 
347
348
  def prop_reader(*params)
348
- meta, klass, symbols = N::PropertyUtils.resolve_prop_params(params)
349
+ meta, klass, symbols = Glue::PropertyUtils.resolve_prop_params(params)
349
350
 
350
351
  meta[:reader] = true
351
352
  meta[:writer] = false
@@ -362,7 +363,7 @@ class Module
362
363
  # prop_writer String, :name, :title, :body, :sql => "char(32)"
363
364
 
364
365
  def prop_writer(*params)
365
- meta, klass, symbols = N::PropertyUtils.resolve_prop_params(params)
366
+ meta, klass, symbols = Glue::PropertyUtils.resolve_prop_params(params)
366
367
 
367
368
  meta[:reader] = false
368
369
  meta[:writer] = true
@@ -379,7 +380,7 @@ class Module
379
380
  # prop_accessor String, :name, :title, :body, :sql => "char(32)"
380
381
 
381
382
  def prop_accessor(*params)
382
- meta, klass, symbols = N::PropertyUtils.resolve_prop_params(params)
383
+ meta, klass, symbols = Glue::PropertyUtils.resolve_prop_params(params)
383
384
 
384
385
  meta[:reader] = true
385
386
  meta[:writer] = true
@@ -400,7 +401,7 @@ class Module
400
401
  def meta(key, *val)
401
402
  val = val.first if val.size == 1
402
403
 
403
- N::PropertyUtils.enchant(self)
404
+ Glue::PropertyUtils.enchant(self)
404
405
 
405
406
  self.module_eval %{
406
407
  @__meta[key] ||= []
data/lib/glue/string.rb CHANGED
@@ -2,11 +2,11 @@
2
2
  # * Anastasios Koutoumanos <ak@navel.gr>
3
3
  # * Elias Karakoulakis <ekarak@ktismata.com>
4
4
  # (c) 2004-2005 Navel, all rights reserved.
5
- # $Id: string.rb 282 2005-03-10 12:24:53Z gmosx $
5
+ # $Id: string.rb 1 2005-04-11 11:04:30Z gmosx $
6
6
 
7
- require "uri"
7
+ require 'uri'
8
8
 
9
- module N;
9
+ module Glue;
10
10
 
11
11
  # General string utilities collection.
12
12
  #
data/lib/glue/time.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id: time.rb 282 2005-03-10 12:24:53Z gmosx $
3
+ # $Id: time.rb 1 2005-04-11 11:04:30Z gmosx $
4
4
 
5
5
  require 'time.rb'
6
6
 
7
- module N;
7
+ module Glue;
8
8
 
9
9
  # General time utilities collection
10
10
  #
@@ -1,8 +1,8 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id$
3
+ # $Id: validation.rb 1 2005-04-11 11:04:30Z gmosx $
4
4
 
5
- module N
5
+ module Glue
6
6
 
7
7
  # Implements a meta-language for validating managed
8
8
  # objects. Typically used in Validator objects but can be
@@ -30,8 +30,8 @@ module N
30
30
  # validate_format :name, :format => /[a-z]*/, :msg => 'invalid format', :on => :create
31
31
  # end
32
32
  #
33
- # class N::CustomUserValidator
34
- # include N::Validation
33
+ # class CustomUserValidator
34
+ # include Validation
35
35
  # validate_length :name, :range => 2..6, :msg_short => :name_too_short, :msg_long => :name_too_long
36
36
  # end
37
37
  #
@@ -48,7 +48,7 @@ module N
48
48
  # p user.errors.on(:name)
49
49
  # end
50
50
  #
51
- # unless errors = N::CustomUserValidator.errors(user)
51
+ # unless errors = CustomUserValidator.errors(user)
52
52
  # user.save
53
53
  # else
54
54
  # p errors[:name]
@@ -127,7 +127,7 @@ module Validation
127
127
  return @errors.empty?
128
128
  rescue NoMethodError => e
129
129
  # gmosx: hmm this is potentially dangerous.
130
- N::Validation.eval_validate(self.class)
130
+ Glue::Validation.eval_validate(self.class)
131
131
  retry
132
132
  end
133
133
  end
@@ -185,7 +185,7 @@ module Validation
185
185
 
186
186
  def validate_value(*params)
187
187
  c = {
188
- :msg => N::Validation::Errors.no_value,
188
+ :msg => Glue::Validation::Errors.no_value,
189
189
  :on => :save
190
190
  }
191
191
  c.update(params.pop) if params.last.is_a?(Hash)
@@ -212,8 +212,8 @@ module Validation
212
212
 
213
213
  def validate_confirmation(*params)
214
214
  c = {
215
- :msg => N::Validation::Errors.no_confirmation,
216
- :postfix => N::Validation::MetaLanguage.confirmation_postfix,
215
+ :msg => Glue::Validation::Errors.no_confirmation,
216
+ :postfix => Glue::Validation::MetaLanguage.confirmation_postfix,
217
217
  :on => :save
218
218
  }
219
219
  c.update(params.pop) if params.last.is_a?(Hash)
@@ -247,8 +247,8 @@ module Validation
247
247
  def validate_format(*params)
248
248
  c = {
249
249
  :format => nil,
250
- :msg_no_value => N::Validation::Errors.no_value,
251
- :msg => N::Validation::Errors.invalid_format,
250
+ :msg_no_value => Glue::Validation::Errors.no_value,
251
+ :msg => Glue::Validation::Errors.invalid_format,
252
252
  :on => :save
253
253
  }
254
254
  c.update(params.pop) if params.last.is_a?(Hash)
@@ -286,9 +286,9 @@ module Validation
286
286
  c = {
287
287
  :min => nil, :max => nil, :range => nil, :length => nil,
288
288
  :msg => nil,
289
- :msg_no_value => N::Validation::Errors.no_value,
290
- :msg_short => N::Validation::Errors.too_short,
291
- :msg_long => N::Validation::Errors.too_long,
289
+ :msg_no_value => Glue::Validation::Errors.no_value,
290
+ :msg_short => Glue::Validation::Errors.too_short,
291
+ :msg_long => Glue::Validation::Errors.too_long,
292
292
  :on => :save
293
293
  }
294
294
  c.update(params.pop) if params.last.is_a?(Hash)
@@ -311,7 +311,7 @@ module Validation
311
311
 
312
312
  for name in params
313
313
  if min
314
- c[:msg] ||= N::Validation::Errors.too_short
314
+ c[:msg] ||= Glue::Validation::Errors.too_short
315
315
  code = %{
316
316
  if obj.#{name}.nil?
317
317
  errors.add(:#{name}, '#{c[:msg_no_value]}')
@@ -322,7 +322,7 @@ module Validation
322
322
  end;
323
323
  }
324
324
  elsif max
325
- c[:msg] ||= N::Validation::Errors.too_long
325
+ c[:msg] ||= Glue::Validation::Errors.too_long
326
326
  code = %{
327
327
  if obj.#{name}.nil?
328
328
  errors.add(:#{name}, '#{c[:msg_no_value]}')
@@ -347,7 +347,7 @@ module Validation
347
347
  end;
348
348
  }
349
349
  elsif length
350
- c[:msg] ||= N::Validation::Errors.invalid_length
350
+ c[:msg] ||= Glue::Validation::Errors.invalid_length
351
351
  code = %{
352
352
  if obj.#{name}.nil?
353
353
  errors.add(:#{name}, '#{c[:msg_no_value]}')
@@ -374,7 +374,7 @@ module Validation
374
374
  def validate_inclusion(*params)
375
375
  c = {
376
376
  :in => nil,
377
- :msg => N::Validation::Errors.no_inclusion,
377
+ :msg => Glue::Validation::Errors.no_inclusion,
378
378
  :allow_nil => false,
379
379
  :on => :save
380
380
  }
@@ -422,7 +422,7 @@ module Validation
422
422
  def validate_numeric(*params)
423
423
  c = {
424
424
  :integer => false,
425
- :msg => N::Validation::Errors.no_numeric,
425
+ :msg => Glue::Validation::Errors.no_numeric,
426
426
  :on => :save
427
427
  }
428
428
  c.update(params.pop) if params.last.is_a?(Hash)
@@ -456,6 +456,6 @@ end
456
456
  end
457
457
 
458
458
  class Module # :nodoc: all
459
- include N::Validation::MetaLanguage
459
+ include Glue::Validation::MetaLanguage
460
460
  end
461
461