racket-registry 0.4.2 → 0.5.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.
- checksums.yaml +4 -4
- data/lib/racket/registry.rb +26 -0
- data/spec/racket_registry.rb +32 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50a4a8cfa27f846f7a46d7d1c68dc5eaf02349d5
|
4
|
+
data.tar.gz: b4c43807c0937b16a06e45c78224c404c94836b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb8daf1cd4767cca9c7be1278e6df7d26b2547e6eadfe6f9f4233fde938de213eb0f2bdc66283712c4e40392cb16f2be71dc41ba336275a49117e814074455a4
|
7
|
+
data.tar.gz: 3a5835f4566c98fd36b7056f01058946c6a6d7d3e65ccf8b506160acdf7fcdaf91a9af10bf066584dd59d275207e80c2c47906b13c12ebb17465a2013dc788f1
|
data/lib/racket/registry.rb
CHANGED
@@ -20,6 +20,32 @@
|
|
20
20
|
module Racket
|
21
21
|
# Racket Registry namespace
|
22
22
|
class Registry
|
23
|
+
class << self
|
24
|
+
# Returns a new registry with all items in the map registered as
|
25
|
+
# non-singleton procs.
|
26
|
+
#
|
27
|
+
# @param [Hash] map
|
28
|
+
# @return [Racket::Registry]
|
29
|
+
def with_map(map)
|
30
|
+
registry = new
|
31
|
+
map.each_pair { |key, value| registry.register(key, value) }
|
32
|
+
registry
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns a new registry with all items in the map registered as
|
36
|
+
# singleton procs.
|
37
|
+
#
|
38
|
+
# @param [Hash] map
|
39
|
+
# @return [Racket::Registry]
|
40
|
+
def with_singleton_map(map)
|
41
|
+
registry = new
|
42
|
+
map.each_pair { |key, value| registry.register_singleton(key, value) }
|
43
|
+
registry
|
44
|
+
end
|
45
|
+
|
46
|
+
alias singleton_map with_singleton_map
|
47
|
+
end
|
48
|
+
|
23
49
|
# Removes the callback specified by +key+ from the registry.
|
24
50
|
#
|
25
51
|
# @param [String|Symbol] key
|
data/spec/racket_registry.rb
CHANGED
@@ -84,6 +84,38 @@ describe 'Racket::Registry registration' do
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
+
describe 'Racket::Registry bulk registration' do
|
88
|
+
it 'should be able to register non-singleton procs in bulk' do
|
89
|
+
registry =
|
90
|
+
Racket::Registry.with_map(
|
91
|
+
one: -> { Object.new },
|
92
|
+
two: -> { Object.new },
|
93
|
+
three: -> { Object.new }
|
94
|
+
)
|
95
|
+
[:one, :two, :three].each do |key|
|
96
|
+
registry.should.respond_to(key)
|
97
|
+
obj1 = registry.send(key)
|
98
|
+
obj2 = registry.send(key)
|
99
|
+
obj1.object_id.should.not.equal(obj2.object_id)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should be able to register singleton procs in bulk' do
|
104
|
+
registry =
|
105
|
+
Racket::Registry.with_singleton_map(
|
106
|
+
one: -> { Object.new },
|
107
|
+
two: -> { Object.new },
|
108
|
+
three: -> { Object.new }
|
109
|
+
)
|
110
|
+
[:one, :two, :three].each do |key|
|
111
|
+
registry.should.respond_to(key)
|
112
|
+
obj1 = registry.send(key)
|
113
|
+
obj2 = registry.send(key)
|
114
|
+
obj1.object_id.should.equal(obj2.object_id)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
87
119
|
describe 'Racket::Registry dependency handling' do
|
88
120
|
# A very simple class
|
89
121
|
class Simple
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: racket-registry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lars Olsson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bacon
|
@@ -119,3 +119,4 @@ specification_version: 4
|
|
119
119
|
summary: Racket Registry - a simple dependency injection container
|
120
120
|
test_files:
|
121
121
|
- spec/racket_registry.rb
|
122
|
+
has_rdoc:
|