pinball 0.0.7 → 0.0.8
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/README.md +3 -3
- data/lib/pinball/class.rb +7 -7
- data/lib/pinball/container.rb +12 -7
- data/lib/pinball/container_item.rb +1 -1
- data/lib/pinball/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9fd0b5f91dd65bc57c14ffbba9f65951704631c
|
4
|
+
data.tar.gz: 7eb3bd810468fc9f32dd8ec379d58321ad09a3a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67de1450479d707b79dd035a62e1cf6bc6240c54cbe41330dc7e6f158c0b71f6829abc1c65ed77bde84fc536c84ab914b4e40aa6225f2a64e5c22a1b046d4896
|
7
|
+
data.tar.gz: 1eb70c1588bb653b9f97769a375f0c7c6caba0f4ec74c27a681aa78eb8f3a4e90a83126e26ad21356aa8d987c5067beea83b27d6f4d2758eec8d7f3c9f58acf6
|
data/README.md
CHANGED
@@ -97,14 +97,14 @@ This block will be executed it `FirstService` instance context where
|
|
97
97
|
`@current_user` will be accessible.
|
98
98
|
**Notice:** each call of `second_service` will call this block over and over again.
|
99
99
|
|
100
|
-
###
|
100
|
+
### Singletons
|
101
101
|
|
102
102
|
Instead of class injection, singleton injection will not create new objects every time. It will create only one and then
|
103
103
|
returns it. Perfect for stateless services and other singletons. Modifying of classes is not required.
|
104
104
|
|
105
105
|
```ruby
|
106
|
-
|
107
|
-
|
106
|
+
Pinball::Container.configure do
|
107
|
+
define_singleton :second_service, SingletonClass
|
108
108
|
end
|
109
109
|
```
|
110
110
|
|
data/lib/pinball/class.rb
CHANGED
@@ -14,18 +14,18 @@ class Class
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def check_pinball
|
17
|
-
unless
|
18
|
-
|
19
|
-
|
17
|
+
unless is_a? Pinball
|
18
|
+
extend Pinball
|
19
|
+
send(:include, Pinball::Methods)
|
20
20
|
|
21
|
-
|
21
|
+
public_send(:define_singleton_method, :inherited_with_pinball) do |child|
|
22
22
|
inherited_without_pinball(child) if respond_to?(:inherited_without_pinball)
|
23
|
-
child.instance_variable_set :@dependencies,
|
23
|
+
child.instance_variable_set :@dependencies, dependencies
|
24
24
|
child.check_pinball
|
25
25
|
end
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
public_send(:define_singleton_method, :inherited_without_pinball, method(:inherited)) if respond_to?(:inherited)
|
28
|
+
public_send(:define_singleton_method, :inherited, method(:inherited_with_pinball))
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
data/lib/pinball/container.rb
CHANGED
@@ -9,27 +9,27 @@ module Pinball
|
|
9
9
|
|
10
10
|
class << self
|
11
11
|
def configure(&block)
|
12
|
-
|
12
|
+
instance.instance_exec(&block)
|
13
13
|
end
|
14
14
|
|
15
15
|
def lookup(key)
|
16
|
-
|
16
|
+
instance.items[key]
|
17
17
|
end
|
18
18
|
|
19
19
|
def clear
|
20
|
-
|
20
|
+
instance.items.clear
|
21
21
|
end
|
22
22
|
|
23
23
|
def define(key, value = nil, &block)
|
24
|
-
|
24
|
+
instance.define(key, value, &block)
|
25
25
|
end
|
26
26
|
|
27
27
|
def define_singleton(key, klass)
|
28
|
-
|
28
|
+
instance.define_singleton(key, klass)
|
29
29
|
end
|
30
30
|
|
31
31
|
def undefine(key)
|
32
|
-
|
32
|
+
instance.undefine(key)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -57,10 +57,15 @@ module Pinball
|
|
57
57
|
target.class.dependencies.each do |dep|
|
58
58
|
unless target.respond_to?(dep)
|
59
59
|
target.define_singleton_method dep do
|
60
|
-
|
60
|
+
begin
|
61
|
+
Container.instance.items.merge(overridden_dependencies)[dep].fetch(self)
|
62
|
+
rescue NoMethodError
|
63
|
+
raise Pinball::UnknownDependency.new("Dependency #{dep} is unknown, check your pinball config")
|
64
|
+
end
|
61
65
|
end
|
62
66
|
end
|
63
67
|
end
|
68
|
+
|
64
69
|
end
|
65
70
|
end
|
66
71
|
end
|
data/lib/pinball/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pinball
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gleb Sinyavsky
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|