niftie-multiton 0.1.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.
Files changed (3) hide show
  1. data/lib/multiton.rb +24 -0
  2. data/multiton.gemspec +10 -0
  3. metadata +54 -0
data/lib/multiton.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'thread'
2
+
3
+ module Multiton
4
+
5
+ POOLS = Hash.new { |hash, key| hash[key] = Hash.new }
6
+ MUTEX = Mutex.new
7
+
8
+ def Multiton.append_features(base)
9
+
10
+ def base.instance(*args, &block)
11
+ id = if self.respond_to?(:multiton_id)
12
+ self.multiton_id(*args, &block)
13
+ else
14
+ args
15
+ end
16
+
17
+ Multiton::MUTEX.synchronize do
18
+ Multiton::POOLS[self][id] ||= self.new(*args, &block)
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ end
data/multiton.gemspec ADDED
@@ -0,0 +1,10 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'multiton'
3
+ s.author = 'Nicolas Steenlant'
4
+ s.email = 'nicolas.steenlant@gmail.com'
5
+ s.version = '0.1.0'
6
+ s.date = '2008-11-19'
7
+ s.summary = ''
8
+ s.files = ['multiton.gemspec', 'lib/multiton.rb']
9
+ s.require_path = 'lib'
10
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: niftie-multiton
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas Steenlant
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-19 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: nicolas.steenlant@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - multiton.gemspec
26
+ - lib/multiton.rb
27
+ has_rdoc: false
28
+ homepage:
29
+ post_install_message:
30
+ rdoc_options: []
31
+
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: "0"
39
+ version:
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ requirements: []
47
+
48
+ rubyforge_project:
49
+ rubygems_version: 1.2.0
50
+ signing_key:
51
+ specification_version: 2
52
+ summary: ""
53
+ test_files: []
54
+