nitro 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 → CHANGELOG} +137 -0
- data/INSTALL +1 -2
- data/README +1 -1
- data/Rakefile +10 -61
- data/benchmark/{nitro/bench.rb → bench.rb} +1 -1
- data/benchmark/{nitro/simple-webrick-n-200.txt → simple-webrick-n-200.txt} +0 -0
- data/benchmark/{nitro/static-webrick-n-200.txt → static-webrick-n-200.txt} +0 -0
- data/benchmark/{nitro/tiny-lhttpd-n-200-c-5.txt → tiny-lhttpd-n-200-c-5.txt} +0 -0
- data/benchmark/{nitro/tiny-webrick-n-200-c-5.txt → tiny-webrick-n-200-c-5.txt} +0 -0
- data/benchmark/{nitro/tiny-webrick-n-200.txt → tiny-webrick-n-200.txt} +0 -0
- data/benchmark/{nitro/tiny2-webrick-n-200.txt → tiny2-webrick-n-200.txt} +0 -0
- data/doc/{ChangeLog.1 → CHANGELOG.1} +0 -0
- data/{RELEASES → doc/RELEASES} +46 -0
- data/doc/faq.txt +7 -0
- data/examples/README.windows +1 -1
- data/examples/ajax/controller.rb +21 -0
- data/examples/ajax/public/index.xhtml +70 -0
- data/examples/ajax/public/js/ajax.js +64 -0
- data/examples/ajax/run.rb +16 -0
- data/examples/blog/README +6 -3
- data/examples/blog/conf/apache.conf +2 -2
- data/examples/blog/conf/lhttpd.conf +2 -2
- data/examples/blog/log/apache.error_log +777 -0
- data/examples/blog/{root → public}/base.xsl +0 -0
- data/examples/blog/{root → public}/fcgi.rb +0 -0
- data/examples/blog/{root → public}/m/bubbles.gif +0 -0
- data/examples/blog/{root → public}/m/comments_curve.gif +0 -0
- data/examples/blog/{root → public}/m/down.gif +0 -0
- data/examples/blog/{root → public}/m/footer_bg.gif +0 -0
- data/examples/blog/{root → public}/m/garrow.gif +0 -0
- data/examples/blog/{root → public}/m/gbull.gif +0 -0
- data/examples/blog/{root → public}/m/grbull.gif +0 -0
- data/examples/blog/{root → public}/m/h1_bg.gif +0 -0
- data/examples/blog/{root → public}/m/header_bg.gif +0 -0
- data/examples/blog/{root → public}/m/nitro.gif +0 -0
- data/examples/blog/{root → public}/m/obull.gif +0 -0
- data/examples/blog/{root → public}/m/page_bg.gif +0 -0
- data/examples/blog/{root → public}/m/rss.gif +0 -0
- data/examples/blog/{root → public}/m/side_title_bg.gif +0 -0
- data/examples/blog/{root → public}/m/sidebar_bg.gif +0 -0
- data/examples/{no_xsl_blog/root → blog/public}/style.css +6 -0
- data/examples/blog/run.rb +10 -12
- data/examples/blog/{lib → src}/blog.rb +3 -3
- data/examples/blog/{lib/blog → src}/controller.rb +13 -2
- data/examples/blog/src/mailer.rb +23 -0
- data/examples/blog/{lib/blog/model.rb → src/models/blog.rb} +4 -7
- data/examples/blog/src/models/content.rb +52 -0
- data/examples/blog/src/views/blog_entry_email.xhtml +16 -0
- data/examples/blog/{root → src/views}/comments.xhtml +0 -0
- data/examples/blog/{root → src/views}/entry_form.xhtml +0 -0
- data/examples/blog/{root → src/views}/error.xhtml +0 -0
- data/examples/blog/{root → src/views}/index.xhtml +0 -0
- data/examples/blog/{root → src/views}/login.xhtml +0 -0
- data/examples/blog/{root → src/views}/recent_posts.xhtml +0 -0
- data/examples/blog/{root → src/views}/view_entry.xhtml +8 -0
- data/examples/blog/{root → src/views}/view_entry.xml +0 -0
- data/examples/blog/src/xsl/base.xsl +153 -0
- data/examples/blog/{root → src/xsl}/style.xsl +2 -2
- data/examples/no_xsl_blog/README +5 -1
- data/examples/no_xsl_blog/conf/apache.conf +2 -2
- data/examples/no_xsl_blog/conf/lhttpd.conf +2 -2
- data/examples/no_xsl_blog/lib/blog/model.rb +1 -1
- data/{lib/parts → examples/no_xsl_blog/lib}/content.rb +1 -11
- data/examples/no_xsl_blog/log/apache.error_log +405 -0
- data/examples/no_xsl_blog/{root → public}/comments.xhtml +0 -0
- data/examples/no_xsl_blog/{root → public}/entry_form.xhtml +0 -0
- data/examples/no_xsl_blog/{root → public}/fcgi.rb +0 -0
- data/examples/no_xsl_blog/{root → public}/index.xhtml +0 -0
- data/examples/no_xsl_blog/{root → public}/login.xhtml +0 -0
- data/examples/no_xsl_blog/{root → public}/m/bubbles.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/comments_curve.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/down.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/footer_bg.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/garrow.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/gbull.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/grbull.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/h1_bg.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/header_bg.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/nitro.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/obull.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/page_bg.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/rss.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/side_title_bg.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/sidebar_bg.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/recent_posts.xhtml +0 -0
- data/examples/{blog/root → no_xsl_blog/public}/style.css +0 -0
- data/examples/no_xsl_blog/{root → public}/view_entry.xhtml +0 -0
- data/examples/no_xsl_blog/{root → public}/view_entry.xml +0 -0
- data/examples/tiny/conf/apache.conf +2 -2
- data/examples/tiny/log/apache.error_log +100 -0
- data/examples/tiny/{root → public}/fcgi.rb +0 -0
- data/examples/tiny/{root → public}/include.xhtml +0 -0
- data/examples/tiny/{root → public}/index.xhtml +0 -0
- data/{bin/proto/root/m → examples/tiny/public}/nitro.png +0 -0
- data/examples/tiny/{root → public}/upload.xhtml +0 -0
- data/examples/tiny/run.rb +1 -2
- data/examples/why_wiki/wiki.yml +1 -0
- data/install.rb +5 -2
- data/lib/nitro.rb +2 -6
- data/lib/nitro/adapters/fastcgi.rb +2 -2
- data/lib/nitro/adapters/webrick.rb +4 -4
- data/lib/nitro/conf.rb +5 -2
- data/lib/nitro/controller.rb +2 -2
- data/lib/nitro/dispatcher.rb +19 -8
- data/lib/nitro/mail.rb +252 -8
- data/lib/nitro/render.rb +24 -21
- data/lib/nitro/runner.rb +1 -1
- data/lib/nitro/scaffold.rb +2 -5
- data/lib/nitro/simple.rb +2 -1
- data/lib/nitro/template.rb +42 -2
- data/test/nitro/tc_controller.rb +9 -4
- data/test/nitro/tc_dispatcher.rb +4 -6
- data/test/nitro/tc_mail.rb +95 -0
- data/test/{root → public}/blog/list.xhtml +0 -0
- data/test/public/dummy_mailer/registration.xhtml +5 -0
- data/vendor/README +0 -1
- metadata +136 -181
- data/benchmark/og/bench.rb +0 -75
- data/benchmark/og/sqlite-no-prepare.1.txt +0 -13
- data/benchmark/og/sqlite-no-prepare.2.txt +0 -13
- data/benchmark/og/sqlite-prepare.1.txt +0 -13
- data/benchmark/og/sqlite-prepare.2.txt +0 -13
- data/bin/proto/README +0 -34
- data/bin/proto/conf/apache.conf +0 -1
- data/bin/proto/conf/app.conf.rb +0 -14
- data/bin/proto/conf/lhttpd.conf +0 -236
- data/bin/proto/ctl +0 -4
- data/bin/proto/lib/README +0 -5
- data/bin/proto/log/README +0 -3
- data/bin/proto/root/fcgi.rb +0 -6
- data/bin/proto/root/index.xhtml +0 -69
- data/bin/proto/root/style.css +0 -152
- data/bin/proto/root/style.xsl +0 -99
- data/doc/og_config.txt +0 -35
- data/doc/og_tutorial.txt +0 -595
- data/examples/og/README +0 -11
- data/examples/og/mock_example.rb +0 -50
- data/examples/og/mysql_to_psql.rb +0 -96
- data/examples/og/run.rb +0 -286
- data/examples/tiny/root/nitro.png +0 -0
- 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/lib/og.rb +0 -185
- data/lib/og/adapter.rb +0 -513
- data/lib/og/adapters/filesys.rb +0 -121
- data/lib/og/adapters/mysql.rb +0 -347
- data/lib/og/adapters/oracle.rb +0 -375
- data/lib/og/adapters/psql.rb +0 -273
- data/lib/og/adapters/sqlite.rb +0 -262
- data/lib/og/backend.rb +0 -297
- data/lib/og/connection.rb +0 -304
- data/lib/og/database.rb +0 -282
- data/lib/og/enchant.rb +0 -125
- data/lib/og/meta.rb +0 -373
- data/lib/og/mock.rb +0 -165
- data/lib/og/observer.rb +0 -53
- data/lib/og/typemacros.rb +0 -23
- data/lib/parts/README +0 -9
- data/test/glue/tc_attribute.rb +0 -22
- data/test/glue/tc_cache.rb +0 -45
- data/test/glue/tc_hash.rb +0 -38
- data/test/glue/tc_logger.rb +0 -39
- data/test/glue/tc_numbers.rb +0 -20
- data/test/glue/tc_property.rb +0 -89
- data/test/glue/tc_property_mixins.rb +0 -93
- data/test/glue/tc_property_type_checking.rb +0 -35
- data/test/glue/tc_strings.rb +0 -103
- data/test/glue/tc_validation.rb +0 -188
- data/test/og/tc_filesys.rb +0 -83
- data/test/og/tc_lifecycle.rb +0 -104
- data/test/og/tc_many_to_many.rb +0 -62
- data/test/og/tc_meta.rb +0 -55
- data/test/og/tc_observer.rb +0 -85
- data/test/og/tc_sqlite.rb +0 -87
- data/test/tc_og.rb +0 -355
- data/vendor/composite_sexp_processor.rb +0 -43
- data/vendor/parse_tree.rb +0 -745
- data/vendor/sexp_processor.rb +0 -453
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
|