diftw 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -0
- data/lib/diftw/injector.rb +16 -1
- data/lib/diftw/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: e6366250c8436b7ac8f13cbdb141c00df330b3b3
|
4
|
+
data.tar.gz: 5539558b8a792c39d348d26dc99ab1eefef1f291
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa432f1b19cef264335f41bada27a5acee05263ba05c5c0ff40ea897b761ee18f6445a5196ee19400c5c2d851d919307de4c556785fc9467aaf3c40dbe04ee12
|
7
|
+
data.tar.gz: 2dd9517311e3f10047874923c36ad2222b22561c158dd4e43ba86eff2524afdbe4539ebd1eb896702bd8674901679a5a0e8d7fad4b988fc0c7ede1cd74c3b18c
|
data/README.md
CHANGED
@@ -174,3 +174,19 @@ To inject different dependencies in these environments, you have several options
|
|
174
174
|
DI[:foo] = -> { OpenStruct.new(message: 'Test Foo') }
|
175
175
|
|
176
176
|
And you can use the parent-child injector features described above.
|
177
|
+
|
178
|
+
### Injecting in before(:each)
|
179
|
+
|
180
|
+
If you want to re-inject something into a class's injector in something like rspec's `before(:each)`:
|
181
|
+
|
182
|
+
before :each do
|
183
|
+
# Give all MyService instances 'Test foo' as #foo
|
184
|
+
MyService.injector[:foo] = -> {
|
185
|
+
'Test foo'
|
186
|
+
}
|
187
|
+
end
|
188
|
+
|
189
|
+
after :each do
|
190
|
+
# Remove the override & fallback to whatever was registered in the root injector
|
191
|
+
MyService.injector.delete :foo
|
192
|
+
end
|
data/lib/diftw/injector.rb
CHANGED
@@ -64,7 +64,7 @@ module DiFtw
|
|
64
64
|
#
|
65
65
|
# @param name [Symbol] name of the dependency
|
66
66
|
# @param y [Proc] the dependency wrapped in a Proc or block
|
67
|
-
# @return [Injector] returns the Injector object
|
67
|
+
# @return [DiFtw::Injector] returns the Injector object
|
68
68
|
#
|
69
69
|
def register(name, y = nil, &block)
|
70
70
|
registry[name] = y || block
|
@@ -106,6 +106,21 @@ module DiFtw
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
+
#
|
110
|
+
# Unregisters the dependency from this injector instance. This means requests for this dependency
|
111
|
+
# will continue on up the chain.
|
112
|
+
#
|
113
|
+
# @param name [Symbol] name of the dependency
|
114
|
+
# @return [DiFtw::Injector] returns the Injector object
|
115
|
+
#
|
116
|
+
def delete(name)
|
117
|
+
registry.delete name
|
118
|
+
if singleton
|
119
|
+
instance_variable_set "@_singleton_#{name}", nil
|
120
|
+
end
|
121
|
+
self
|
122
|
+
end
|
123
|
+
|
109
124
|
#
|
110
125
|
# Creates and returns a new Module which contains instance methods for all the dependencies you specified.
|
111
126
|
# Simply include this module in your class, and all it's instances will have their dependencies injected.
|
data/lib/diftw/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diftw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Hollinger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A small dependency injection library for Ruby
|
14
14
|
email: jordan.hollinger@gmail.com
|