manioc 0.1.1 → 0.1.2
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/manioc/container.rb +22 -7
- data/lib/manioc/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a438dc71640e6700d5efb85a5973817236dc0990
|
4
|
+
data.tar.gz: ce5cae5cc25e2e1edf13c08b4bcaadfd7281c264
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99c3852f3e9ab5c68c019bc38f50f9aab951b147e600c5b6755bfcddd3b7c09c70e3a5fb90d65291572e8349ed5325dc54b5bc3c2b21597413dd42b26b70eab3
|
7
|
+
data.tar.gz: 54741d37eb1808c6785543a0d706494b1307e1780f24bce414f137c5786c0b17e9f8a7fbc3cf1e507a2a7695fbbeab4854a0e683091b95cedaa733e3991a09d1
|
data/lib/manioc/container.rb
CHANGED
@@ -16,20 +16,27 @@ module Manioc
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def initialize
|
20
|
-
@constructors
|
19
|
+
def initialize cache: true, preload: false, constructors: {}, &block
|
20
|
+
@constructors = constructors
|
21
|
+
@cache = cache ? {} : nil
|
22
|
+
@preload = preload
|
21
23
|
|
22
24
|
register(&block) if block
|
23
25
|
finalize
|
24
26
|
end
|
25
27
|
|
26
28
|
def with &block
|
27
|
-
self.class.new
|
29
|
+
self.class.new \
|
30
|
+
constructors: @constructors.dup,
|
31
|
+
cache: @cache.any?,
|
32
|
+
preload: @preload,
|
33
|
+
&block
|
28
34
|
end
|
29
35
|
|
30
36
|
def reset key=nil
|
31
|
-
|
32
|
-
keys
|
37
|
+
return unless @cache
|
38
|
+
keys = key ? [key] : @cache.keys
|
39
|
+
keys.each { |k| @cache.delete k }
|
33
40
|
end
|
34
41
|
|
35
42
|
private
|
@@ -39,13 +46,21 @@ module Manioc
|
|
39
46
|
end
|
40
47
|
|
41
48
|
def resolve key
|
42
|
-
|
49
|
+
instance_exec(&@constructors[key])
|
43
50
|
end
|
44
51
|
|
45
52
|
def finalize
|
46
53
|
@constructors.freeze
|
47
54
|
@constructors.each do |key,_|
|
48
|
-
|
55
|
+
if @cache
|
56
|
+
define_singleton_method(key) { @cache[key] ||= resolve key }
|
57
|
+
else
|
58
|
+
define_singleton_method(key) { resolve key }
|
59
|
+
end
|
60
|
+
|
61
|
+
if @preload
|
62
|
+
public_send key
|
63
|
+
end
|
49
64
|
end
|
50
65
|
end
|
51
66
|
end
|
data/lib/manioc/version.rb
CHANGED