glue 0.18.1 → 0.19.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 +28 -0
- data/doc/RELEASES +12 -1
- data/lib/glue.rb +3 -2
- data/lib/glue/attribute.rb +18 -5
- data/lib/glue/autoreload.rb +30 -0
- data/lib/glue/flexob.rb +14 -4
- data/lib/glue/logger.rb +9 -1
- data/lib/glue/property.rb +45 -20
- data/test/glue/tc_flexob.rb +19 -0
- data/test/glue/tc_logger.rb +4 -0
- metadata +4 -2
data/CHANGELOG
CHANGED
@@ -1,5 +1,33 @@
|
|
1
|
+
17-06-2005 George Moschovitis <gm@navel.gr>
|
2
|
+
|
3
|
+
* lib/glue/autoreload.rb: added.
|
4
|
+
|
5
|
+
16-06-2005 George Moschovitis <gm@navel.gr>
|
6
|
+
|
7
|
+
* lib/glue/attribute.rb: only create singleton accessors.
|
8
|
+
|
9
|
+
* lib/glue/logger.rb (#set): improved API, now accepts String.
|
10
|
+
|
11
|
+
07-06-2005 George Moschovitis <gm@navel.gr>
|
12
|
+
|
13
|
+
* lib/glue/property.rb (##copy_features): implemented.
|
14
|
+
|
15
|
+
* lib/glue/flexob.rb: implemented each.
|
16
|
+
|
17
|
+
04-06-2005 George Moschovitis <gm@navel.gr>
|
18
|
+
|
19
|
+
* test/glue/flexob.rb: implemented.
|
20
|
+
|
21
|
+
* lib/glue/flexob.rb: added [] accessors.
|
22
|
+
|
23
|
+
* lib/glue/property.rb: metadata alias for __meta,
|
24
|
+
made __meta a flexob for extra ..flexibility,
|
25
|
+
added support for boolean metadata.
|
26
|
+
|
1
27
|
31-05-2005 George Moschovitis <gm@navel.gr>
|
2
28
|
|
29
|
+
* --- VERSION 0.19.0 ---
|
30
|
+
|
3
31
|
* test/*: fixes to pass again.
|
4
32
|
|
5
33
|
27-05-2005 George Moschovitis <gm@navel.gr>
|
data/doc/RELEASES
CHANGED
@@ -1,4 +1,15 @@
|
|
1
|
-
== Version 0.
|
1
|
+
== Version 0.19.0
|
2
|
+
|
3
|
+
* Improved Logger.
|
4
|
+
|
5
|
+
* Improved mattr_accessor.
|
6
|
+
|
7
|
+
* Added autoreload support.
|
8
|
+
|
9
|
+
* Improved metadata.
|
10
|
+
|
11
|
+
|
12
|
+
== Version 0.18.0 was released on 01/06/2005.
|
2
13
|
|
3
14
|
Deprecated many methods. Facet methods are used instead.
|
4
15
|
|
data/lib/glue.rb
CHANGED
@@ -27,6 +27,7 @@ class NilClass
|
|
27
27
|
def blank?
|
28
28
|
true
|
29
29
|
end
|
30
|
+
|
30
31
|
end
|
31
32
|
|
32
33
|
class Class
|
@@ -51,7 +52,7 @@ module Kernel
|
|
51
52
|
# the pretty printed string
|
52
53
|
|
53
54
|
def pp_exception(ex)
|
54
|
-
return %{#{ex.message}\n #{ex.backtrace.join("\n ")}\n LOGGED FROM: #{caller[0]
|
55
|
+
return %{#{ex.message}\n #{ex.backtrace.join("\n ")}\n LOGGED FROM: #{caller[0]}}
|
55
56
|
end
|
56
57
|
|
57
58
|
end
|
@@ -60,7 +61,7 @@ module Glue
|
|
60
61
|
|
61
62
|
# The version.
|
62
63
|
|
63
|
-
Version = '0.
|
64
|
+
Version = '0.19.0'
|
64
65
|
|
65
66
|
# Library path.
|
66
67
|
|
data/lib/glue/attribute.rb
CHANGED
@@ -16,7 +16,10 @@
|
|
16
16
|
#++
|
17
17
|
|
18
18
|
class Module # :nodoc:
|
19
|
-
|
19
|
+
|
20
|
+
# A macro that creates a reader method for class/module
|
21
|
+
# attributes.
|
22
|
+
|
20
23
|
def mattr_reader(*params)
|
21
24
|
default = if params.last.is_a?(Symbol) then nil else params.pop end
|
22
25
|
|
@@ -30,15 +33,20 @@ class Module # :nodoc:
|
|
30
33
|
def self.#{sym.id2name}
|
31
34
|
@@#{sym}
|
32
35
|
end
|
33
|
-
|
36
|
+
=begin
|
37
|
+
# gmosx: NOT NEEDED!
|
38
|
+
|
34
39
|
def #{sym.id2name}
|
35
40
|
@@#{sym}
|
36
41
|
end
|
37
|
-
|
42
|
+
=end
|
38
43
|
end_eval
|
39
44
|
end
|
40
45
|
end
|
41
46
|
alias_method :cattr_reader, :mattr_reader
|
47
|
+
|
48
|
+
# A macro that creates a writer method for class/module
|
49
|
+
# attributes.
|
42
50
|
|
43
51
|
def mattr_writer(*params)
|
44
52
|
default = if params.last.is_a?(Symbol) then nil else params.pop end
|
@@ -57,15 +65,20 @@ class Module # :nodoc:
|
|
57
65
|
def self.set_#{sym.id2name}(obj)
|
58
66
|
@@#{sym.id2name} = obj
|
59
67
|
end
|
60
|
-
|
68
|
+
=begin
|
69
|
+
# gmosx: NOT NEEDED!
|
70
|
+
|
61
71
|
def #{sym.id2name}=(obj)
|
62
72
|
@@#{sym} = obj
|
63
73
|
end
|
64
|
-
|
74
|
+
=end
|
65
75
|
end_eval
|
66
76
|
end
|
67
77
|
end
|
68
78
|
alias_method :cattr_writer, :cattr_writer
|
79
|
+
|
80
|
+
# A macro that creates a reader and a writer method for
|
81
|
+
# class/module attributes.
|
69
82
|
|
70
83
|
def mattr_accessor(*syms)
|
71
84
|
mattr_reader(*syms)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Copied from Wee 0.8.0
|
2
|
+
# (c) 2004 Michael Neumann.
|
3
|
+
|
4
|
+
module Kernel
|
5
|
+
|
6
|
+
def autoreload(check_interval=10)
|
7
|
+
Thread.new(Time.now) { |start_time|
|
8
|
+
file_mtime = {}
|
9
|
+
loop do
|
10
|
+
sleep check_interval
|
11
|
+
$LOADED_FEATURES.each do |feature|
|
12
|
+
$LOAD_PATH.each do |lp|
|
13
|
+
file = File.join(lp, feature)
|
14
|
+
if (File.exists?(file) and
|
15
|
+
File.stat(file).mtime > (file_mtime[file] || start_time))
|
16
|
+
file_mtime[file] = File.stat(file).mtime
|
17
|
+
STDERR.puts "reload #{ file }"
|
18
|
+
begin
|
19
|
+
load(file)
|
20
|
+
rescue Exception => e
|
21
|
+
STDERR.puts e.inspect
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/lib/glue/flexob.rb
CHANGED
@@ -1,7 +1,3 @@
|
|
1
|
-
# * George Moschovitis <gm@navel.gr>
|
2
|
-
# (c) 2004-2005 Navel, all rights reserved.
|
3
|
-
# $Id: flexob.rb 1 2005-04-11 11:04:30Z gmosx $
|
4
|
-
|
5
1
|
require 'ostruct'
|
6
2
|
|
7
3
|
# A flexible Object.
|
@@ -15,5 +11,19 @@ class Flexob < OpenStruct
|
|
15
11
|
end
|
16
12
|
end
|
17
13
|
alias_method :set, :update
|
14
|
+
|
15
|
+
def []=(key, val)
|
16
|
+
@table[key.to_sym] = val
|
17
|
+
end
|
18
|
+
|
19
|
+
def [](key)
|
20
|
+
@table[key.to_sym]
|
21
|
+
end
|
22
|
+
|
23
|
+
def each(&block)
|
24
|
+
@table.each(&block)
|
25
|
+
end
|
18
26
|
|
19
27
|
end
|
28
|
+
|
29
|
+
# * George Moschovitis <gm@navel.gr>
|
data/lib/glue/logger.rb
CHANGED
@@ -79,8 +79,16 @@ class Logger
|
|
79
79
|
|
80
80
|
@@global_logger = Logger.new(STDERR)
|
81
81
|
|
82
|
+
# Set the global Logger.
|
83
|
+
|
82
84
|
def self.set(logger)
|
83
|
-
|
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
|
84
92
|
end
|
85
93
|
|
86
94
|
def self.get
|
data/lib/glue/property.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'glue/attribute'
|
2
|
+
require 'glue/flexob'
|
2
3
|
require 'glue/array'
|
3
4
|
require 'glue/hash'
|
4
5
|
|
@@ -81,8 +82,9 @@ module PropertyUtils
|
|
81
82
|
|
82
83
|
def self.enchant(target, force = false)
|
83
84
|
unless target.instance_variables.include?('@__props')
|
84
|
-
|
85
|
-
target.instance_variable_set('@
|
85
|
+
# FIXME: should be thread safe here!
|
86
|
+
target.instance_variable_set('@__meta', Flexob.new)
|
87
|
+
target.instance_variable_set('@__props', SafeArray.new)
|
86
88
|
|
87
89
|
# gmosx: Ruby surprises and amazes me! We are in the Metaclass
|
88
90
|
# when defining methods and attributes so @__props is really
|
@@ -109,6 +111,10 @@ module PropertyUtils
|
|
109
111
|
def self.__meta=(meta)
|
110
112
|
@__meta = meta
|
111
113
|
end
|
114
|
+
|
115
|
+
def self.metadata
|
116
|
+
@__meta
|
117
|
+
end
|
112
118
|
}
|
113
119
|
|
114
120
|
if target.is_a?(Class)
|
@@ -120,8 +126,9 @@ module PropertyUtils
|
|
120
126
|
def self.inherited(child)
|
121
127
|
Glue::PropertyUtils.enchant(child)
|
122
128
|
Glue::PropertyUtils.copy_props(self, child)
|
123
|
-
# gmosx: We have to define @@__props first to avoid
|
124
|
-
# the hash from the module. super must stay
|
129
|
+
# gmosx: We have to define @@__props first to avoid
|
130
|
+
# reusing the hash from the module. super must stay
|
131
|
+
# at the end.
|
125
132
|
super
|
126
133
|
end
|
127
134
|
}
|
@@ -132,12 +139,11 @@ module PropertyUtils
|
|
132
139
|
# their features to classes that include it.
|
133
140
|
|
134
141
|
target.module_eval %{
|
135
|
-
def self.append_features(base)
|
136
|
-
|
137
|
-
|
138
|
-
#
|
139
|
-
|
140
|
-
Glue::PropertyUtils.include_meta_mixins(base)
|
142
|
+
def self.append_features(base)
|
143
|
+
# gmosx: We have to define @@__props first to avoid
|
144
|
+
# reusing the hash from the module. super must stay
|
145
|
+
# at the end.
|
146
|
+
Glue::PropertyUtils.copy_features(self, base)
|
141
147
|
super
|
142
148
|
end
|
143
149
|
}
|
@@ -155,7 +161,11 @@ module PropertyUtils
|
|
155
161
|
|
156
162
|
# copy the metadata.
|
157
163
|
src.__meta.each do |k, val|
|
158
|
-
|
164
|
+
if val.is_a?(TrueClass)
|
165
|
+
dest.__meta[k] = val
|
166
|
+
else
|
167
|
+
dest.__meta[k] = val.dup
|
168
|
+
end
|
159
169
|
# val.each { |v| dest.meta(k, v) } if val
|
160
170
|
end
|
161
171
|
end
|
@@ -256,6 +266,12 @@ module PropertyUtils
|
|
256
266
|
target.send(:include, Og::EntityMixin) if defined?(Og::EntityMixin)
|
257
267
|
end
|
258
268
|
|
269
|
+
def self.copy_features(this, other)
|
270
|
+
Glue::PropertyUtils.enchant(other)
|
271
|
+
Glue::PropertyUtils.copy_props(this, other)
|
272
|
+
Glue::PropertyUtils.include_meta_mixins(other)
|
273
|
+
end
|
274
|
+
|
259
275
|
# Resolves the parameters passed to the propxxx macros
|
260
276
|
# to generate the meta, klass and symbols variables. This
|
261
277
|
# way the common functionality is factored out.
|
@@ -292,7 +308,7 @@ module PropertyUtils
|
|
292
308
|
|
293
309
|
end
|
294
310
|
|
295
|
-
end
|
311
|
+
end
|
296
312
|
|
297
313
|
class Module
|
298
314
|
|
@@ -303,7 +319,8 @@ class Module
|
|
303
319
|
# Use the prop_reader, prop_writer, prop_accessor methods
|
304
320
|
# for multiple properties.
|
305
321
|
#
|
306
|
-
# Examples
|
322
|
+
# === Examples
|
323
|
+
#
|
307
324
|
# prop String, :name, :sql => "char(32), :sql_index => "name(32)"
|
308
325
|
# --> creates only writer.
|
309
326
|
# prop Fixnum, :oid, writer = true, :sql => "integer PRIMARY KEY"
|
@@ -394,15 +411,23 @@ class Module
|
|
394
411
|
#++
|
395
412
|
|
396
413
|
def meta(key, *val)
|
397
|
-
val = val.first if val.size == 1
|
398
|
-
|
399
414
|
Glue::PropertyUtils.enchant(self)
|
400
415
|
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
416
|
+
if val.empty?
|
417
|
+
self.module_eval %{
|
418
|
+
@__meta[key] = true
|
419
|
+
}
|
420
|
+
else
|
421
|
+
val = val.first if val.size == 1
|
422
|
+
|
423
|
+
self.module_eval %{
|
424
|
+
@__meta[key] ||= []
|
425
|
+
@__meta[key].delete_if { |v| val == v }
|
426
|
+
@__meta[key] << val
|
427
|
+
}
|
428
|
+
end
|
406
429
|
end
|
407
430
|
|
408
431
|
end
|
432
|
+
|
433
|
+
# * George Moschovitis <gm@navel.gr>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'glue/flexob'
|
5
|
+
|
6
|
+
class TC_Flexob < Test::Unit::TestCase # :nodoc: all
|
7
|
+
|
8
|
+
def test_all
|
9
|
+
f = Flexob.new
|
10
|
+
f.title = 'Test'
|
11
|
+
f[:another] = 'Another'
|
12
|
+
|
13
|
+
assert_equal 'Test', f.title
|
14
|
+
assert_equal 'Another', f.another
|
15
|
+
assert_equal 'Another', f[:another]
|
16
|
+
assert_equal 'Another', f['another']
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/test/glue/tc_logger.rb
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
|
|
3
3
|
specification_version: 1
|
4
4
|
name: glue
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2005-06-
|
6
|
+
version: 0.19.0
|
7
|
+
date: 2005-06-17
|
8
8
|
summary: Glue utilities
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- lib/glue/property.rb
|
47
47
|
- lib/glue/sanitize.rb
|
48
48
|
- lib/glue/number.rb
|
49
|
+
- lib/glue/autoreload.rb
|
49
50
|
- lib/glue/aspects.rb
|
50
51
|
- lib/glue/misc.rb
|
51
52
|
- lib/glue/time.rb
|
@@ -66,6 +67,7 @@ files:
|
|
66
67
|
- test/glue/tc_logger.rb
|
67
68
|
- test/glue/tc_aspects.rb
|
68
69
|
- test/glue/tc_property_type_checking.rb
|
70
|
+
- test/glue/tc_flexob.rb
|
69
71
|
- test/glue/tc_hash.rb
|
70
72
|
- test/glue/tc_attribute.rb
|
71
73
|
- test/glue/tc_property.rb
|