niftie-multiton 0.6 → 0.6.1
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/lib/multiton.rb +16 -26
- data/multiton.gemspec +2 -2
- metadata +2 -2
data/lib/multiton.rb
CHANGED
@@ -1,45 +1,35 @@
|
|
1
1
|
require 'monitor'
|
2
2
|
|
3
3
|
module Kernel
|
4
|
-
def Multiton(
|
5
|
-
|
4
|
+
def Multiton(limit)
|
5
|
+
const_set('INSTANCE_MAP', Multiton::LRUMap.new(limit))
|
6
6
|
Multiton
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
module Multiton
|
11
|
-
def self.
|
12
|
-
base.
|
13
|
-
|
11
|
+
def self.append_features(base)
|
12
|
+
base.const_set('INSTANCE_MAP', Multiton::Map.new) unless base.constants.include?('INSTANCE_MAP')
|
13
|
+
|
14
|
+
def base.instance_map
|
15
|
+
const_get('INSTANCE_MAP')
|
14
16
|
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
superclass.instance_map
|
22
|
-
end
|
23
|
-
super
|
18
|
+
def base.instance(*args, &block)
|
19
|
+
key = begin
|
20
|
+
multiton_key(*args, &block)
|
21
|
+
rescue NameError
|
22
|
+
args
|
24
23
|
end
|
25
24
|
|
26
|
-
|
27
|
-
key
|
28
|
-
|
25
|
+
instance_map.synchronize do
|
26
|
+
instance_map[key] ||= begin
|
27
|
+
multiton_new(*args, &block)
|
29
28
|
rescue NameError
|
30
|
-
args
|
31
|
-
end
|
32
|
-
|
33
|
-
instance_map.synchronize do
|
34
|
-
instance_map[key] ||= begin
|
35
|
-
multiton_new(*args, &block)
|
36
|
-
rescue NameError
|
37
|
-
new(*args, &block)
|
38
|
-
end
|
29
|
+
new(*args, &block)
|
39
30
|
end
|
40
31
|
end
|
41
32
|
end
|
42
|
-
|
43
33
|
end
|
44
34
|
|
45
35
|
class Map
|
data/multiton.gemspec
CHANGED
@@ -3,8 +3,8 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.homepage = 'http://github.com/niftie/multiton'
|
4
4
|
s.author = 'Nicolas Steenlant'
|
5
5
|
s.email = 'nicolas.steenlant@gmail.com'
|
6
|
-
s.version = '0.6'
|
7
|
-
s.date = '2008-12-
|
6
|
+
s.version = '0.6.1'
|
7
|
+
s.date = '2008-12-10'
|
8
8
|
s.summary = ''
|
9
9
|
s.files = ['multiton.gemspec', 'lib/multiton.rb']
|
10
10
|
s.require_path = 'lib'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: niftie-multiton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicolas Steenlant
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-12-
|
12
|
+
date: 2008-12-10 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|