glue 0.22.0 → 0.23.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/README +3 -3
- data/Rakefile +3 -3
- data/{CHANGELOG → doc/CHANGELOG.1} +0 -0
- data/doc/RELEASES +10 -0
- data/lib/glue.rb +7 -12
- data/lib/glue/configuration.rb +4 -4
- data/lib/glue/fixture.rb +3 -4
- data/lib/glue/helper.rb +1 -2
- data/lib/glue/logger.rb +43 -23
- data/lib/glue/metadata.rb +60 -0
- data/lib/glue/mock.rb +40 -0
- data/lib/glue/property.rb +33 -9
- data/lib/glue/property.rb.old +438 -0
- data/lib/glue/template.rb +1 -1
- data/lib/glue/uri.rb +2 -2
- data/test/glue/tc_metadata.rb +33 -0
- metadata +53 -57
- data/lib/glue/annotation.rb +0 -33
- data/lib/glue/array.rb +0 -61
- data/lib/glue/autoreload.rb +0 -30
- data/lib/glue/cache.rb +0 -189
- data/lib/glue/hash.rb +0 -122
- data/lib/glue/misc.rb +0 -15
- data/lib/glue/number.rb +0 -24
- data/lib/glue/object.rb +0 -35
- data/lib/glue/pool.rb +0 -60
- data/lib/glue/snapshot.rb +0 -104
- data/lib/glue/string.rb +0 -162
- data/lib/glue/time.rb +0 -85
- data/lib/vendor/blankslate.rb +0 -53
- data/test/glue/tc_hash.rb +0 -36
- data/test/glue/tc_numbers.rb +0 -18
- data/test/glue/tc_strings.rb +0 -102
@@ -0,0 +1,33 @@
|
|
1
|
+
__END__
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
4
|
+
|
5
|
+
require 'yaml'
|
6
|
+
require 'test/unit'
|
7
|
+
require 'glue/metadata'
|
8
|
+
|
9
|
+
class Dummy
|
10
|
+
include MetadataMixin
|
11
|
+
|
12
|
+
attr_accessor :name
|
13
|
+
ann :name, :class => String
|
14
|
+
ann :properties => :name
|
15
|
+
|
16
|
+
def run
|
17
|
+
puts 'hello'
|
18
|
+
end
|
19
|
+
ann :run, :doc => 'documentation'
|
20
|
+
ann :order => 'oid DESC'
|
21
|
+
end
|
22
|
+
|
23
|
+
class TestMetadata < Test::Unit::TestCase # :nodoc: all
|
24
|
+
|
25
|
+
def test_all
|
26
|
+
p Dummy.metadata.self.properties
|
27
|
+
assert_equal 'documentation', Dummy.metadata.run.doc
|
28
|
+
assert_equal 'oid DESC', Dummy.metadata.self.order
|
29
|
+
assert_equal 1, Dummy.metadata.self.properties.size
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: glue
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2005-08-
|
6
|
+
version: 0.23.0
|
7
|
+
date: 2005-08-31 00:00:00 +03:00
|
8
8
|
summary: Glue utilities
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -29,84 +29,71 @@ cert_chain:
|
|
29
29
|
authors:
|
30
30
|
- George Moschovitis
|
31
31
|
files:
|
32
|
-
- README
|
33
|
-
- CHANGELOG
|
34
32
|
- Rakefile
|
33
|
+
- README
|
35
34
|
- INSTALL
|
36
35
|
- install.rb
|
37
36
|
- doc/RELEASES
|
38
37
|
- doc/LICENSE
|
39
38
|
- doc/AUTHORS
|
39
|
+
- doc/CHANGELOG.1
|
40
40
|
- lib/glue
|
41
41
|
- lib/html
|
42
42
|
- lib/glue.rb
|
43
|
-
- lib/
|
44
|
-
- lib/glue/
|
45
|
-
- lib/glue/array.rb
|
43
|
+
- lib/glue/builder
|
44
|
+
- lib/glue/mailer
|
46
45
|
- lib/glue/validation.rb
|
47
|
-
- lib/glue/flexob.rb
|
48
|
-
- lib/glue/hash.rb
|
49
|
-
- lib/glue/property.rb
|
50
|
-
- lib/glue/sanitize.rb
|
51
|
-
- lib/glue/number.rb
|
52
|
-
- lib/glue/autoreload.rb
|
53
46
|
- lib/glue/uri.rb
|
54
|
-
- lib/glue/
|
55
|
-
- lib/glue/
|
56
|
-
- lib/glue/
|
57
|
-
- lib/glue/
|
58
|
-
- lib/glue/
|
59
|
-
- lib/glue/
|
60
|
-
- lib/glue/string.rb
|
61
|
-
- lib/glue/object.rb
|
47
|
+
- lib/glue/template.rb
|
48
|
+
- lib/glue/settings.rb
|
49
|
+
- lib/glue/sanitize.rb
|
50
|
+
- lib/glue/property.rb.old
|
51
|
+
- lib/glue/property.rb
|
52
|
+
- lib/glue/mock.rb
|
62
53
|
- lib/glue/mixins.rb
|
63
|
-
- lib/glue/
|
64
|
-
- lib/glue/
|
54
|
+
- lib/glue/metadata.rb
|
55
|
+
- lib/glue/mailer.rb
|
56
|
+
- lib/glue/mail.rb
|
57
|
+
- lib/glue/logger.rb
|
65
58
|
- lib/glue/localization.rb
|
66
59
|
- lib/glue/helper.rb
|
67
|
-
- lib/glue/
|
68
|
-
- lib/glue/builder.rb
|
60
|
+
- lib/glue/flexob.rb
|
69
61
|
- lib/glue/fixture.rb
|
70
|
-
- lib/glue/
|
71
|
-
- lib/glue/
|
72
|
-
- lib/glue/
|
73
|
-
- lib/glue/
|
74
|
-
- lib/glue/mailer.rb
|
75
|
-
- lib/glue/template.rb
|
62
|
+
- lib/glue/configuration.rb
|
63
|
+
- lib/glue/builder.rb
|
64
|
+
- lib/glue/attribute.rb
|
65
|
+
- lib/glue/aspects.rb
|
76
66
|
- lib/glue/builder/xml.rb
|
77
|
-
- lib/glue/mailer/incoming.rb
|
78
67
|
- lib/glue/mailer/outgoing.rb
|
79
|
-
- lib/
|
80
|
-
- lib/html/node.rb
|
68
|
+
- lib/glue/mailer/incoming.rb
|
81
69
|
- lib/html/version.rb
|
82
70
|
- lib/html/tokenizer.rb
|
83
|
-
- lib/
|
84
|
-
-
|
71
|
+
- lib/html/node.rb
|
72
|
+
- lib/html/document.rb
|
85
73
|
- test/fixture
|
74
|
+
- test/glue
|
86
75
|
- test/public
|
87
|
-
- test/
|
88
|
-
- test/
|
76
|
+
- test/fixture/user.yml
|
77
|
+
- test/fixture/article.yml
|
78
|
+
- test/fixture/article.csv
|
79
|
+
- test/glue/builder
|
89
80
|
- test/glue/tc_validation.rb
|
90
|
-
- test/glue/
|
81
|
+
- test/glue/tc_uri.rb
|
82
|
+
- test/glue/tc_template.rb
|
91
83
|
- test/glue/tc_property_mixins.rb
|
92
|
-
- test/glue/tc_logger.rb
|
93
|
-
- test/glue/tc_aspects.rb
|
94
|
-
- test/glue/builder
|
95
|
-
- test/glue/tc_property_type_checking.rb
|
96
|
-
- test/glue/tc_flexob.rb
|
97
|
-
- test/glue/tc_hash.rb
|
98
|
-
- test/glue/tc_attribute.rb
|
99
84
|
- test/glue/tc_property.rb
|
100
|
-
- test/glue/
|
101
|
-
- test/glue/
|
85
|
+
- test/glue/tc_property_type_checking.rb
|
86
|
+
- test/glue/tc_metadata.rb
|
87
|
+
- test/glue/tc_mail.rb
|
88
|
+
- test/glue/tc_logger.rb
|
102
89
|
- test/glue/tc_localization.rb
|
90
|
+
- test/glue/tc_flexob.rb
|
103
91
|
- test/glue/tc_fixture.rb
|
104
|
-
- test/glue/
|
105
|
-
- test/glue/
|
92
|
+
- test/glue/tc_configuration.rb
|
93
|
+
- test/glue/tc_builder.rb
|
94
|
+
- test/glue/tc_attribute.rb
|
95
|
+
- test/glue/tc_aspects.rb
|
106
96
|
- test/glue/builder/tc_xml.rb
|
107
|
-
- test/fixture/user.yml
|
108
|
-
- test/fixture/article.yml
|
109
|
-
- test/fixture/article.csv
|
110
97
|
- test/public/dummy_mailer
|
111
98
|
- test/public/dummy_mailer/registration.xhtml
|
112
99
|
test_files: []
|
@@ -118,21 +105,30 @@ rdoc_options:
|
|
118
105
|
- "--all"
|
119
106
|
- "--inline-source"
|
120
107
|
extra_rdoc_files:
|
121
|
-
- README
|
122
|
-
- CHANGELOG
|
123
108
|
- Rakefile
|
109
|
+
- README
|
124
110
|
- INSTALL
|
125
111
|
executables: []
|
126
112
|
extensions: []
|
127
113
|
requirements: []
|
128
114
|
dependencies:
|
129
115
|
- !ruby/object:Gem::Dependency
|
130
|
-
name:
|
116
|
+
name: nano
|
117
|
+
version_requirement:
|
118
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
119
|
+
requirements:
|
120
|
+
-
|
121
|
+
- ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 0.8.2
|
124
|
+
version:
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: mega
|
131
127
|
version_requirement:
|
132
128
|
version_requirements: !ruby/object:Gem::Version::Requirement
|
133
129
|
requirements:
|
134
130
|
-
|
135
131
|
- ">="
|
136
132
|
- !ruby/object:Gem::Version
|
137
|
-
version: 0.
|
133
|
+
version: 0.3.1
|
138
134
|
version:
|
data/lib/glue/annotation.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# Based on an original idea by Aslak Hellesoy.
|
2
|
-
|
3
|
-
require 'glue/hash'
|
4
|
-
|
5
|
-
class Module
|
6
|
-
def ann(anns)
|
7
|
-
@@anns ||= SafeHash.new
|
8
|
-
def self.method_missing(sym, *args) #:nodoc:
|
9
|
-
@@anns[sym]
|
10
|
-
end
|
11
|
-
t = Thread.current
|
12
|
-
t[:attr_anns] ||= {}
|
13
|
-
t[:attr_anns].merge!(anns)
|
14
|
-
end
|
15
|
-
|
16
|
-
alias old_attr_reader attr_reader #:nodoc:
|
17
|
-
def attr_reader(*syms) #:nodoc:
|
18
|
-
t = Thread.current
|
19
|
-
syms.each do |sym|
|
20
|
-
@@anns[sym] = t[:attr_anns]
|
21
|
-
end
|
22
|
-
|
23
|
-
t[:attr_anns] = nil
|
24
|
-
old_attr_reader(*syms)
|
25
|
-
end
|
26
|
-
|
27
|
-
def attr_accessor(*syms) #:nodoc:
|
28
|
-
attr_reader(*syms)
|
29
|
-
attr_writer(*syms)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# * George Moschovitis <gm@navel.gr>
|
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 182 2005-07-22 10:07:50Z gmosx $
|
4
|
-
|
5
|
-
require 'sync'
|
6
|
-
|
7
|
-
module Glue
|
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/autoreload.rb
DELETED
@@ -1,30 +0,0 @@
|
|
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/cache.rb
DELETED
@@ -1,189 +0,0 @@
|
|
1
|
-
unless Enumerable.instance_methods.include?("min_by")
|
2
|
-
# for Ruby 1.8
|
3
|
-
module Enumerable
|
4
|
-
def min_by(&block)
|
5
|
-
min {|i,j| block.call(i) <=> block.call(j) }
|
6
|
-
end
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
module Glue
|
11
|
-
|
12
|
-
# Abstract super class of all cache implementations.
|
13
|
-
class Cache; end
|
14
|
-
|
15
|
-
# Abstract super class of all caching strategies.
|
16
|
-
class Cache::Strategy; end
|
17
|
-
|
18
|
-
# Implements an unbounded cache strategy. The cache size can
|
19
|
-
# grow to infinity.
|
20
|
-
|
21
|
-
class Cache::Strategy::Unbounded < Cache::Strategy
|
22
|
-
class Item < Struct.new(:value); end
|
23
|
-
def item_class() Item end
|
24
|
-
|
25
|
-
def access(item) end
|
26
|
-
def delete(item) end
|
27
|
-
def insert_or_extrude(item, enum) end
|
28
|
-
end
|
29
|
-
|
30
|
-
# Abstract class for a capacity bounded strategy. Only up to
|
31
|
-
# _capacity_ items are allowed to be stored in the cache
|
32
|
-
# at any time.
|
33
|
-
|
34
|
-
class Cache::Strategy::CapacityBounded < Cache::Strategy
|
35
|
-
attr_accessor :capacity
|
36
|
-
|
37
|
-
def initialize(capacity)
|
38
|
-
@capacity = capacity
|
39
|
-
@n_items = 0 # number of items in cache
|
40
|
-
end
|
41
|
-
|
42
|
-
def inc(item)
|
43
|
-
raise if full?
|
44
|
-
@n_items += 1
|
45
|
-
end
|
46
|
-
|
47
|
-
def dec(item)
|
48
|
-
raise if empty?
|
49
|
-
@n_items -= 1
|
50
|
-
end
|
51
|
-
|
52
|
-
def full?
|
53
|
-
@n_items >= @capacity
|
54
|
-
end
|
55
|
-
|
56
|
-
def empty?
|
57
|
-
@n_items == 0
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
# Implements the least frequently used (LFU) strategy.
|
62
|
-
|
63
|
-
class Cache::Strategy::LFU < Cache::Strategy::CapacityBounded
|
64
|
-
class Item < Struct.new(:value, :freq); end
|
65
|
-
def item_class() Item end
|
66
|
-
|
67
|
-
def access(item)
|
68
|
-
item.freq += 1
|
69
|
-
end
|
70
|
-
|
71
|
-
def delete(item)
|
72
|
-
dec(item)
|
73
|
-
end
|
74
|
-
|
75
|
-
# enum::
|
76
|
-
# a [key, item] enumerable
|
77
|
-
|
78
|
-
def insert_or_extrude(item, enum)
|
79
|
-
# find least recently used key/item and yield
|
80
|
-
yield enum.min_by {|key, it| it.freq} while full?
|
81
|
-
item.freq = 0
|
82
|
-
inc(item)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
# Implements the least recently used (LRU) strategy.
|
87
|
-
|
88
|
-
class Cache::Strategy::LRU < Cache::Strategy::CapacityBounded
|
89
|
-
class Item < Struct.new(:value, :time); end
|
90
|
-
def item_class() Item end
|
91
|
-
|
92
|
-
def access(item)
|
93
|
-
item.time = Time.now
|
94
|
-
end
|
95
|
-
|
96
|
-
def delete(item)
|
97
|
-
dec(item)
|
98
|
-
end
|
99
|
-
|
100
|
-
# enum::
|
101
|
-
# a [key, item] enumerable
|
102
|
-
#
|
103
|
-
def insert_or_extrude(item, enum)
|
104
|
-
# find least recently used key/item and yield
|
105
|
-
yield enum.min_by {|key, it| it.time} while full?
|
106
|
-
item.time = Time.now
|
107
|
-
inc(item)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
# Implements a cache using a parameterizable strategy and a storage.
|
112
|
-
# The protocol that the _store_ must understand is:
|
113
|
-
#
|
114
|
-
# fetch(key) -> val
|
115
|
-
# has_key?(key)
|
116
|
-
# delete(key) -> val
|
117
|
-
# each {|key, val| }
|
118
|
-
|
119
|
-
class Cache::StorageCache < Cache
|
120
|
-
|
121
|
-
def initialize(strategy, store=Hash.new, store_on_update=false)
|
122
|
-
@strategy = strategy
|
123
|
-
@store = store
|
124
|
-
@store_on_update = store_on_update
|
125
|
-
end
|
126
|
-
|
127
|
-
def has_key?(key)
|
128
|
-
@store.has_key?(key)
|
129
|
-
end
|
130
|
-
|
131
|
-
def delete(key)
|
132
|
-
if @store.has_key?(key)
|
133
|
-
item = @store.delete(key)
|
134
|
-
@strategy.delete(item)
|
135
|
-
item.value
|
136
|
-
else
|
137
|
-
nil
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
def fetch(key, default_value=nil)
|
142
|
-
if @store.has_key?(key)
|
143
|
-
item = @store.fetch(key)
|
144
|
-
@strategy.access(item)
|
145
|
-
@store.store(key, item) if @store_on_update
|
146
|
-
item.value
|
147
|
-
else
|
148
|
-
default_value
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
def store(key, value)
|
153
|
-
if @store.has_key?(key)
|
154
|
-
# update only
|
155
|
-
item = @store.fetch(key)
|
156
|
-
item.value = value
|
157
|
-
@strategy.access(item)
|
158
|
-
@store.store(key, item) if @store_on_update
|
159
|
-
else
|
160
|
-
# insert new item
|
161
|
-
item = @strategy.item_class.new
|
162
|
-
item.value = value
|
163
|
-
@strategy.insert_or_extrude(item, @store) do |k, i|
|
164
|
-
@strategy.delete(i)
|
165
|
-
@store.delete(k)
|
166
|
-
end
|
167
|
-
@store.store(key, item) # correct!
|
168
|
-
end
|
169
|
-
value
|
170
|
-
end
|
171
|
-
|
172
|
-
alias [] fetch
|
173
|
-
alias []= store
|
174
|
-
end
|
175
|
-
|
176
|
-
# Implements an in-memory cache (uses a Hash as store) with a LRU replacement
|
177
|
-
# stragegy.
|
178
|
-
|
179
|
-
class Cache::MemoryLRUCache < Cache::StorageCache
|
180
|
-
DEFAULT_CAPACITY = 20
|
181
|
-
|
182
|
-
def initialize(capacity=DEFAULT_CAPACITY)
|
183
|
-
super(Cache::Strategy::LRU.new(capacity))
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
end # module Glue
|
188
|
-
|
189
|
-
# * Michael Neumann <mneumann@ntecs.de>
|