og 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +27 -0
- data/INSTALL +56 -0
- data/{README.og → README} +3 -3
- data/Rakefile +7 -73
- data/benchmark/bench.rb +75 -0
- data/benchmark/sqlite-no-prepare.1.txt +13 -0
- data/benchmark/sqlite-no-prepare.2.txt +13 -0
- data/benchmark/sqlite-prepare.1.txt +13 -0
- data/benchmark/sqlite-prepare.2.txt +13 -0
- data/doc/AUTHORS +0 -9
- data/{RELEASES.og → doc/RELEASES} +15 -0
- data/doc/config.txt +35 -0
- data/doc/tutorial.txt +595 -0
- data/examples/{og/README → README} +1 -1
- data/examples/{og/mock_example.rb → mock_example.rb} +1 -1
- data/examples/{og/mysql_to_psql.rb → mysql_to_psql.rb} +1 -1
- data/examples/{og/run.rb → run.rb} +1 -1
- data/install.rb +8 -5
- data/lib/og.rb +13 -8
- data/lib/og/adapter.rb +1 -1
- data/lib/og/adapters/filesys.rb +1 -1
- data/lib/og/adapters/mysql.rb +4 -3
- data/lib/og/adapters/oracle.rb +1 -1
- data/lib/og/adapters/psql.rb +4 -3
- data/lib/og/adapters/sqlite.rb +1 -1
- data/lib/og/backend.rb +1 -1
- data/lib/og/connection.rb +1 -1
- data/lib/og/database.rb +1 -1
- data/lib/og/meta.rb +13 -2
- data/lib/og/observer.rb +1 -1
- data/lib/og/typemacros.rb +1 -1
- data/lib/og/validation.rb +81 -0
- data/test/og/tc_validation.rb +89 -0
- metadata +33 -65
- data/ChangeLog +0 -1549
- data/lib/glue.rb +0 -55
- data/lib/glue/array.rb +0 -61
- data/lib/glue/attribute.rb +0 -83
- data/lib/glue/cache.rb +0 -138
- data/lib/glue/flexob.rb +0 -12
- data/lib/glue/hash.rb +0 -122
- data/lib/glue/inflector.rb +0 -91
- data/lib/glue/logger.rb +0 -147
- data/lib/glue/misc.rb +0 -14
- data/lib/glue/mixins.rb +0 -36
- data/lib/glue/number.rb +0 -24
- data/lib/glue/object.rb +0 -32
- data/lib/glue/pool.rb +0 -60
- data/lib/glue/property.rb +0 -408
- data/lib/glue/string.rb +0 -162
- data/lib/glue/time.rb +0 -85
- data/lib/glue/validation.rb +0 -394
- data/vendor/extensions/_base.rb +0 -153
- data/vendor/extensions/_template.rb +0 -36
- data/vendor/extensions/all.rb +0 -21
- data/vendor/extensions/array.rb +0 -68
- data/vendor/extensions/binding.rb +0 -224
- data/vendor/extensions/class.rb +0 -50
- data/vendor/extensions/continuation.rb +0 -71
- data/vendor/extensions/enumerable.rb +0 -250
- data/vendor/extensions/hash.rb +0 -23
- data/vendor/extensions/io.rb +0 -58
- data/vendor/extensions/kernel.rb +0 -42
- data/vendor/extensions/module.rb +0 -114
- data/vendor/extensions/numeric.rb +0 -230
- data/vendor/extensions/object.rb +0 -164
- data/vendor/extensions/ostruct.rb +0 -41
- data/vendor/extensions/string.rb +0 -316
- data/vendor/extensions/symbol.rb +0 -28
data/lib/glue.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
# General libraries used by various projects.
|
2
|
-
#
|
3
|
-
#--
|
4
|
-
# George Moschovitis <gm@navel.gr>
|
5
|
-
# (c) 2004-2005 Navel, all rights reserved.
|
6
|
-
# $Id: glue.rb 215 2005-01-24 10:44:05Z gmosx $
|
7
|
-
#++
|
8
|
-
|
9
|
-
require 'English'
|
10
|
-
require 'pp'
|
11
|
-
|
12
|
-
require 'glue/property'
|
13
|
-
require 'glue/attribute'
|
14
|
-
|
15
|
-
# The standard namespace module.
|
16
|
-
|
17
|
-
module N; end
|
18
|
-
|
19
|
-
class NilClass
|
20
|
-
|
21
|
-
# quite usefull for error tolerant apps.
|
22
|
-
# a bit dangerous? Will have to rethink this.
|
23
|
-
|
24
|
-
def empty?
|
25
|
-
return true
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
class Class
|
30
|
-
#--
|
31
|
-
# gmosx: is this really needed?
|
32
|
-
#++
|
33
|
-
|
34
|
-
def to_i
|
35
|
-
return self.hash
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
module Kernel
|
40
|
-
|
41
|
-
# Pretty prints an exception/error object
|
42
|
-
# usefull for helpfull debug messages
|
43
|
-
#
|
44
|
-
# Input:
|
45
|
-
# The Exception/StandardError object
|
46
|
-
#
|
47
|
-
# Output:
|
48
|
-
# the pretty printed string
|
49
|
-
|
50
|
-
def pp_exception(ex)
|
51
|
-
return %{#{ex.message}\n\tBACKTRACE:\n\t#{ex.backtrace.join("\n\t")}\n\tLOGGED FROM:\n\t#{caller[0]}}
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
data/lib/glue/array.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
# * George Moschovitis <gm@navel.gr>
|
2
|
-
# (c) 2002-2005 Navel, all rights reserved.
|
3
|
-
# $Id: array.rb 266 2005-02-28 14:50:48Z gmosx $
|
4
|
-
|
5
|
-
require 'sync'
|
6
|
-
|
7
|
-
module N
|
8
|
-
|
9
|
-
# A thread-safe array. We use a sync object instead of a
|
10
|
-
# mutex, because it is re-entrant. An exclusive lock is
|
11
|
-
# needed when writing, a shared lock IS NEEDED when reading.
|
12
|
-
|
13
|
-
class SafeArray < Array
|
14
|
-
|
15
|
-
attr :sync
|
16
|
-
|
17
|
-
# gmosx: delegator is not used.
|
18
|
-
|
19
|
-
def initialize(delegator = nil)
|
20
|
-
@sync = Sync.new()
|
21
|
-
end
|
22
|
-
|
23
|
-
def << (value)
|
24
|
-
return @sync.synchronize(Sync::SH) { super }
|
25
|
-
end
|
26
|
-
|
27
|
-
def delete_if(&block)
|
28
|
-
return @sync.synchronize(Sync::SH) { super }
|
29
|
-
end
|
30
|
-
|
31
|
-
def [](key)
|
32
|
-
return @sync.synchronize(Sync::SH) { super }
|
33
|
-
end
|
34
|
-
|
35
|
-
def []=(key, value)
|
36
|
-
return @sync.synchronize(Sync::EX) { super }
|
37
|
-
end
|
38
|
-
|
39
|
-
def delete(key)
|
40
|
-
return @sync.synchronize(Sync::EX) { super }
|
41
|
-
end
|
42
|
-
|
43
|
-
def clear
|
44
|
-
@sync.synchronize(Sync::EX) { super }
|
45
|
-
end
|
46
|
-
|
47
|
-
def size
|
48
|
-
return @sync.synchronize(Sync::SH) { super }
|
49
|
-
end
|
50
|
-
|
51
|
-
def shift
|
52
|
-
return @sync.synchronize(::Sync::EX) { super }
|
53
|
-
end
|
54
|
-
|
55
|
-
def unshift(el)
|
56
|
-
return @sync.synchronize(::Sync::EX) { super }
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
data/lib/glue/attribute.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
# * George Moschovitis <gm@navel.gr>
|
2
|
-
# Original code from Rails distribution.
|
3
|
-
# http://www.rubyonrails.com
|
4
|
-
# $Id$
|
5
|
-
|
6
|
-
#--
|
7
|
-
# Extends the module object with module and instance accessors
|
8
|
-
# for class attributes, just like the native attr* accessors for
|
9
|
-
# instance attributes. Aliases for classes are also provided.
|
10
|
-
#
|
11
|
-
# Example:
|
12
|
-
#
|
13
|
-
# mattr_accessor :my_attr, 'Default value'
|
14
|
-
#++
|
15
|
-
class Module # :nodoc:
|
16
|
-
|
17
|
-
def mattr_reader(*params)
|
18
|
-
default = if params.last.is_a?(Symbol) then nil else params.pop end
|
19
|
-
|
20
|
-
|
21
|
-
for sym in params
|
22
|
-
module_eval <<-"end_eval", __FILE__, __LINE__
|
23
|
-
|
24
|
-
if not defined?(@@#{sym.id2name})
|
25
|
-
@@#{sym.id2name} = #{default.inspect}
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.#{sym.id2name}
|
29
|
-
@@#{sym}
|
30
|
-
end
|
31
|
-
|
32
|
-
def #{sym.id2name}
|
33
|
-
@@#{sym}
|
34
|
-
end
|
35
|
-
|
36
|
-
def call_#{sym.id2name}
|
37
|
-
case @@#{sym.id2name}
|
38
|
-
when Symbol then send(@@#{sym})
|
39
|
-
when Proc then @@#{sym}.call(self)
|
40
|
-
when String then @@#{sym}
|
41
|
-
else nil
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
end_eval
|
46
|
-
end
|
47
|
-
end
|
48
|
-
alias_method :cattr_reader, :mattr_reader
|
49
|
-
|
50
|
-
def mattr_writer(*params)
|
51
|
-
default = if params.last.is_a?(Symbol) then nil else params.pop end
|
52
|
-
|
53
|
-
for sym in params
|
54
|
-
module_eval <<-"end_eval", __FILE__, __LINE__
|
55
|
-
|
56
|
-
if not defined?(@@#{sym.id2name})
|
57
|
-
@@#{sym.id2name} = #{default.inspect.inspect}
|
58
|
-
end
|
59
|
-
|
60
|
-
def self.#{sym.id2name}=(obj)
|
61
|
-
@@#{sym.id2name} = obj
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.set_#{sym.id2name}(obj)
|
65
|
-
@@#{sym.id2name} = obj
|
66
|
-
end
|
67
|
-
|
68
|
-
def #{sym.id2name}=(obj)
|
69
|
-
@@#{sym} = obj
|
70
|
-
end
|
71
|
-
|
72
|
-
end_eval
|
73
|
-
end
|
74
|
-
end
|
75
|
-
alias_method :cattr_writer, :cattr_writer
|
76
|
-
|
77
|
-
def mattr_accessor(*syms)
|
78
|
-
mattr_reader(*syms)
|
79
|
-
mattr_writer(*syms)
|
80
|
-
end
|
81
|
-
alias_method :cattr_accessor, :mattr_accessor
|
82
|
-
|
83
|
-
end
|
data/lib/glue/cache.rb
DELETED
@@ -1,138 +0,0 @@
|
|
1
|
-
# * George Moschovitis <gm@navel.gr>
|
2
|
-
# * Anastasios Koutoumanos <ak@navel.gr>
|
3
|
-
# (c) 2004-2005 Navel, all rights reserved.
|
4
|
-
# $Id: cache.rb 249 2005-02-04 14:03:00Z gmosx $
|
5
|
-
|
6
|
-
module N
|
7
|
-
|
8
|
-
# A cache utilizing a simple LRU (Least Recently Used) policy.
|
9
|
-
# The items managed by this cache must respond to the #key method.
|
10
|
-
# Attempts to optimize reads rather than inserts!
|
11
|
-
#
|
12
|
-
# LRU semantics are enforced by inserting the items in a queue.
|
13
|
-
# The lru item is always at the tail. Two special sentinels
|
14
|
-
# (head, tail) are used to simplify (?) the code.
|
15
|
-
|
16
|
-
class LRUCache < Hash
|
17
|
-
|
18
|
-
# Mix this in your class to make LRU-managable.
|
19
|
-
|
20
|
-
module Item
|
21
|
-
attr_accessor :lru_key, :lru_prev, :lru_next
|
22
|
-
end
|
23
|
-
|
24
|
-
# head-tail sentinels
|
25
|
-
|
26
|
-
class Sentinel; include Item; end
|
27
|
-
|
28
|
-
# the maximum number of items in the cache.
|
29
|
-
|
30
|
-
attr_accessor :max_items
|
31
|
-
|
32
|
-
# the head sentinel
|
33
|
-
|
34
|
-
attr :head
|
35
|
-
|
36
|
-
# the tail sentinel, tail.prev points to the lru item.
|
37
|
-
|
38
|
-
attr :tail
|
39
|
-
|
40
|
-
def initialize(max_items)
|
41
|
-
@max_items = max_items
|
42
|
-
lru_clear()
|
43
|
-
end
|
44
|
-
|
45
|
-
# Lookup an item in the cache.
|
46
|
-
|
47
|
-
def [](key)
|
48
|
-
if item = super
|
49
|
-
return lru_touch(item)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# The inserted item is considered mru!
|
54
|
-
|
55
|
-
def []=(key, item)
|
56
|
-
item = super
|
57
|
-
item.lru_key = key
|
58
|
-
lru_insert(item)
|
59
|
-
end
|
60
|
-
|
61
|
-
# Delete an item from the cache.
|
62
|
-
|
63
|
-
def delete(key)
|
64
|
-
if item = super
|
65
|
-
lru_delete(item)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# Clear the cache.
|
70
|
-
|
71
|
-
def clear
|
72
|
-
super
|
73
|
-
lru_clear()
|
74
|
-
end
|
75
|
-
|
76
|
-
# The first (mru) element in the cache.
|
77
|
-
|
78
|
-
def first
|
79
|
-
@head.lru_next
|
80
|
-
end
|
81
|
-
|
82
|
-
# The last (lru) element in the cache.
|
83
|
-
|
84
|
-
def last
|
85
|
-
@tail.lru_prev
|
86
|
-
end
|
87
|
-
alias_method :lru, :last
|
88
|
-
|
89
|
-
private
|
90
|
-
|
91
|
-
# Delete an item from the lru list.
|
92
|
-
|
93
|
-
def lru_delete(item)
|
94
|
-
lru_join(item.lru_prev, item.lru_next)
|
95
|
-
return item
|
96
|
-
end
|
97
|
-
|
98
|
-
# Join two items in the lru list.
|
99
|
-
# Return y to allow for chaining.
|
100
|
-
|
101
|
-
def lru_join(x, y)
|
102
|
-
x.lru_next = y
|
103
|
-
y.lru_prev = x
|
104
|
-
return y
|
105
|
-
end
|
106
|
-
|
107
|
-
# Append a child item to a parent item in the lru list
|
108
|
-
# (Re)inserts the child in the list.
|
109
|
-
|
110
|
-
def lru_append(parent, child)
|
111
|
-
lru_join(child, parent.lru_next)
|
112
|
-
lru_join(parent, child)
|
113
|
-
end
|
114
|
-
|
115
|
-
# Insert an item
|
116
|
-
|
117
|
-
def lru_insert(item)
|
118
|
-
delete(last.lru_key) if size() > @max_items
|
119
|
-
lru_append(@head, item)
|
120
|
-
end
|
121
|
-
|
122
|
-
# Touch an item, make mru!
|
123
|
-
# Returns the item.
|
124
|
-
|
125
|
-
def lru_touch(item)
|
126
|
-
lru_append(@head, lru_delete(item))
|
127
|
-
end
|
128
|
-
|
129
|
-
# Clear the lru.
|
130
|
-
|
131
|
-
def lru_clear
|
132
|
-
@head = Sentinel.new
|
133
|
-
@tail = Sentinel.new
|
134
|
-
lru_join(@head, @tail)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
data/lib/glue/flexob.rb
DELETED
data/lib/glue/hash.rb
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
# * George Moschovitis <gm@navel.gr>
|
2
|
-
# (c) 2004-2005 Navel, all rights reserved.
|
3
|
-
# $Id: hash.rb 263 2005-02-23 13:45:08Z gmosx $
|
4
|
-
|
5
|
-
require 'sync'
|
6
|
-
|
7
|
-
module N
|
8
|
-
|
9
|
-
# A thread-safe hash. We use a sync object instead of a mutex,
|
10
|
-
# because it is re-entrant. An exclusive lock is needed when
|
11
|
-
# writing, a shared lock IS NEEDED when reading
|
12
|
-
# uses the delegator pattern to allow for multiple
|
13
|
-
# implementations!
|
14
|
-
|
15
|
-
class SafeHash < Hash
|
16
|
-
attr :sync
|
17
|
-
|
18
|
-
# gmosx: delegator is not used.
|
19
|
-
#
|
20
|
-
def initialize(delegator = nil)
|
21
|
-
@sync = ::Sync.new
|
22
|
-
end
|
23
|
-
|
24
|
-
def [](key)
|
25
|
-
@sync.synchronize(::Sync::SH) { super }
|
26
|
-
end
|
27
|
-
|
28
|
-
def []=(key, value)
|
29
|
-
@sync.synchronize(::Sync::EX) { super }
|
30
|
-
end
|
31
|
-
|
32
|
-
def delete(key)
|
33
|
-
@sync.synchronize(::Sync::EX) { super }
|
34
|
-
end
|
35
|
-
|
36
|
-
def clear
|
37
|
-
@sync.synchronize(::Sync::EX) { super }
|
38
|
-
end
|
39
|
-
|
40
|
-
def size
|
41
|
-
@sync.synchronize(::Sync::SH) { super }
|
42
|
-
end
|
43
|
-
|
44
|
-
def values
|
45
|
-
@sync.synchronize(::Sync::SH) { super }
|
46
|
-
end
|
47
|
-
|
48
|
-
def keys
|
49
|
-
@sync.synchronize(::Sync::SH) { super }
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
# A thread-safe hash. We use a sync object instead of a mutex,
|
55
|
-
# because it is re-entrant. An exclusive lock is needed when
|
56
|
-
# writing, a shared lock IS NEEDED when reading.
|
57
|
-
#
|
58
|
-
# === Design
|
59
|
-
#
|
60
|
-
# This class uses the delegator pattern. However we dont use rubys
|
61
|
-
# delegation facilities, they are more general and powerfull than we
|
62
|
-
# need here (and slower). Instead a custom (but simple) solution is
|
63
|
-
# used.
|
64
|
-
#
|
65
|
-
# === Example
|
66
|
-
#
|
67
|
-
# hash = SafeHashDelegator.new(Hash.new)
|
68
|
-
# hash = SafeHashDelegator.new(Hash.new)
|
69
|
-
|
70
|
-
class SafeHashDelegator < Hash
|
71
|
-
attr :delegate, :sync
|
72
|
-
|
73
|
-
def initialize(delegate)
|
74
|
-
@delegate = delegate
|
75
|
-
@sync = ::Sync.new
|
76
|
-
end
|
77
|
-
|
78
|
-
def [](key)
|
79
|
-
@sync.synchronize(::Sync::SH) {
|
80
|
-
@delegate[key]
|
81
|
-
}
|
82
|
-
end
|
83
|
-
|
84
|
-
def []=(key, value)
|
85
|
-
@sync.synchronize(::Sync::EX) {
|
86
|
-
@delegate[key] = value
|
87
|
-
}
|
88
|
-
end
|
89
|
-
|
90
|
-
def delete(key)
|
91
|
-
@sync.synchronize(::Sync::EX) {
|
92
|
-
@delegate.delete(key)
|
93
|
-
}
|
94
|
-
end
|
95
|
-
|
96
|
-
def clear
|
97
|
-
@sync.synchronize(::Sync::EX) {
|
98
|
-
@delegate.clear
|
99
|
-
}
|
100
|
-
end
|
101
|
-
|
102
|
-
def size
|
103
|
-
@sync.synchronize(::Sync::SH) {
|
104
|
-
@delegate.size()
|
105
|
-
}
|
106
|
-
end
|
107
|
-
|
108
|
-
def values
|
109
|
-
@sync.synchronize(::Sync::SH) {
|
110
|
-
@delegate.values()
|
111
|
-
}
|
112
|
-
end
|
113
|
-
|
114
|
-
def keys
|
115
|
-
@sync.synchronize(::Sync::SH) {
|
116
|
-
@delegate.keys()
|
117
|
-
}
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|