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.
Files changed (3) hide show
  1. data/lib/multiton.rb +16 -26
  2. data/multiton.gemspec +2 -2
  3. 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(size)
5
- @instance_map = Multiton::LRUMap.new(size)
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.included(base)
12
- base.instance_eval do
13
- @instance_map ||= Multiton::Map.new
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
- class << base
17
- attr_reader :instance_map
18
-
19
- def inherited(subclass)
20
- def subclass.instance_map
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
- def instance(*args, &block)
27
- key = begin
28
- multiton_key(*args, &block)
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-04'
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: "0.6"
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-04 00:00:00 -08:00
12
+ date: 2008-12-10 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15