pinball 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 47516b049661968362374418a15718a832ee2748
4
- data.tar.gz: 935d17aab842e964e98d32e993edffb1c1fe57c9
3
+ metadata.gz: d9fd0b5f91dd65bc57c14ffbba9f65951704631c
4
+ data.tar.gz: 7eb3bd810468fc9f32dd8ec379d58321ad09a3a1
5
5
  SHA512:
6
- metadata.gz: 26597ab29677f387763717c6b6aaf780ce4c3fd4af30680d463ee4eca89247da56bce48772f6d70480f504e4caac0570b7de775b4e56418958e85254dddcf3cc
7
- data.tar.gz: 10d39becea4769759500d0846073ac61752e87e5a9324fc55886c494ccceb8dd7831830691c82a2b70d55eb2e7d1bb7adcfc2bb0ec1000b2e904cce111721c74
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
- ### Singleton injection
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
- class Service
107
- inject_singleton :service
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 self.is_a? Pinball
18
- self.extend Pinball
19
- self.send(:include, Pinball::Methods)
17
+ unless is_a? Pinball
18
+ extend Pinball
19
+ send(:include, Pinball::Methods)
20
20
 
21
- self.send(:define_singleton_method, :inherited_with_pinball) do |child|
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, self.dependencies
23
+ child.instance_variable_set :@dependencies, dependencies
24
24
  child.check_pinball
25
25
  end
26
26
 
27
- self.send(:define_singleton_method, :inherited_without_pinball, self.method(:inherited)) if self.respond_to?(:inherited)
28
- self.send(:define_singleton_method, :inherited, self.method(:inherited_with_pinball))
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
@@ -9,27 +9,27 @@ module Pinball
9
9
 
10
10
  class << self
11
11
  def configure(&block)
12
- self.instance.instance_exec(&block)
12
+ instance.instance_exec(&block)
13
13
  end
14
14
 
15
15
  def lookup(key)
16
- Pinball::Container.instance.items[key]
16
+ instance.items[key]
17
17
  end
18
18
 
19
19
  def clear
20
- Pinball::Container.instance.items.clear
20
+ instance.items.clear
21
21
  end
22
22
 
23
23
  def define(key, value = nil, &block)
24
- Pinball::Container.instance.define(key, value, &block)
24
+ instance.define(key, value, &block)
25
25
  end
26
26
 
27
27
  def define_singleton(key, klass)
28
- Pinball::Container.instance.define_singleton(key, klass)
28
+ instance.define_singleton(key, klass)
29
29
  end
30
30
 
31
31
  def undefine(key)
32
- Pinball::Container.instance.undefine(key)
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
- Container.instance.items.merge(overridden_dependencies)[dep].fetch(self) rescue raise Pinball::UnknownDependency.new("Dependency #{dep} is unknown, check your pinball config")
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
@@ -9,7 +9,7 @@ module Pinball
9
9
  def fetch(target)
10
10
  if value.is_a? Proc
11
11
  target.instance_eval(&value)
12
- elsif value.is_a? Module #Class definition
12
+ elsif value.is_a? Module
13
13
  value.new
14
14
  else
15
15
  value
@@ -1,3 +1,3 @@
1
1
  module Pinball
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
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.7
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-09-27 00:00:00.000000000 Z
11
+ date: 2014-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler