diftw 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/diftw/injector.rb +20 -0
- data/lib/diftw/version.rb +1 -1
- 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: e2ca2e3bab186790bc0cb1330edf1060a0beed6f
|
4
|
+
data.tar.gz: 90572c316d59095be4846b9894fac598a9d2138e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 524edb6efd5b288c937e4de007ab255922e44cb92ee07211bacbbb20ca4473497fdb12b564f2ed07b8114520ab7bad81ab86a7a407eeed06565a5f1944c6df79
|
7
|
+
data.tar.gz: 7cc3dace40aadf417ed602d6e376ab8b8198689bba652591581faa0b7bf58d1bdceeb3b7640ace5169b4ce0e5c68446ae5b7a42260ab2cb6e700617a55a1ea48
|
data/lib/diftw/injector.rb
CHANGED
@@ -116,6 +116,26 @@ module DiFtw
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
+
#
|
120
|
+
# Injects dependencies into a specific, existing object.
|
121
|
+
#
|
122
|
+
# DI.inject_instance(obj, :foo, :bar)
|
123
|
+
#
|
124
|
+
# @param instance [Object] The object you wish to inject dependencies into
|
125
|
+
# @param dependencies [Symbol] All dependency names you want to inject.
|
126
|
+
#
|
127
|
+
def inject_instance(instance, *dependencies)
|
128
|
+
injector = self
|
129
|
+
instance.instance_eval do
|
130
|
+
dependencies.each do |dep|
|
131
|
+
define_singleton_method dep do
|
132
|
+
var = "@_diftw_#{dep}"
|
133
|
+
instance_variable_get(var) || instance_variable_set(var, injector[dep])
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
119
139
|
private
|
120
140
|
|
121
141
|
#
|
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.0
|
4
|
+
version: 0.1.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-05 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
|
@@ -46,3 +46,4 @@ signing_key:
|
|
46
46
|
specification_version: 4
|
47
47
|
summary: Dependency Injection For The Win!
|
48
48
|
test_files: []
|
49
|
+
has_rdoc:
|