diftw 0.3.1 → 0.4.0
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 +2 -2
- data/lib/diftw/builder.rb +7 -0
- data/lib/diftw/injector.rb +9 -2
- 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: 003ba4d7dfddcf1130c2dcc1a82b398265af7c5e
|
4
|
+
data.tar.gz: 290586529ebe1c70de998696f182c06cd6251a07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34f2a2827ee113f6e847318c2b5315d25109901727c0a743fff22b07953aae7fdf4efb1e0300658b5dd3a784101e008469cd90d88d50e79747101df09284b09e
|
7
|
+
data.tar.gz: 6ddc67b51453af2ccc8b29ae2712c06b27c704716af93f2435e5bfc12ea476792b0b1a6acfd194995f36c54e15c7e3aa3668a1938f320d0cd254bef9e9007f6b
|
data/README.md
CHANGED
@@ -76,14 +76,14 @@ Lazy injection is usually fine. But if it isn't, use `inject!`:
|
|
76
76
|
|
77
77
|
# Inject :baz as a class method
|
78
78
|
class SomeClass
|
79
|
-
DI.
|
79
|
+
extend DI.inject :baz
|
80
80
|
end
|
81
81
|
puts SomeClass.baz.message
|
82
82
|
=> 'Baz'
|
83
83
|
|
84
84
|
# Inject :baz as a module method
|
85
85
|
module SomeModule
|
86
|
-
DI.
|
86
|
+
extend DI.inject :baz
|
87
87
|
end
|
88
88
|
puts SomeModule.baz.message
|
89
89
|
=> 'Baz'
|
data/lib/diftw/builder.rb
CHANGED
@@ -45,6 +45,13 @@ module DiFtw
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
49
|
+
def self.extended(base)
|
50
|
+
di_mod = self
|
51
|
+
base.singleton_class.class_eval do
|
52
|
+
include di_mod
|
53
|
+
end
|
54
|
+
end
|
48
55
|
}.tap { |mod|
|
49
56
|
mod.injector = Injector.new(parent: parent_injector)
|
50
57
|
mod._diftw_dependencies = dependencies
|
data/lib/diftw/injector.rb
CHANGED
@@ -125,10 +125,17 @@ module DiFtw
|
|
125
125
|
#
|
126
126
|
# Creates and returns a new Module which contains instance methods for all the dependencies you specified.
|
127
127
|
# Simply include this module in your class, and all it's instances will have their dependencies injected.
|
128
|
+
# Or extend your class with this module, and your class *itself* will have the dependencies injected.
|
128
129
|
#
|
129
130
|
# class Widget
|
130
|
-
# include DI.inject
|
131
|
+
# include DI.inject :foo, :bar
|
131
132
|
# end
|
133
|
+
# Widget.new.foo
|
134
|
+
#
|
135
|
+
# class Spline
|
136
|
+
# extend Di.inject :foo
|
137
|
+
# end
|
138
|
+
# Spline.foo
|
132
139
|
#
|
133
140
|
# @param dependencies [Symbol] All dependency names you want to inject.
|
134
141
|
#
|
@@ -139,7 +146,7 @@ module DiFtw
|
|
139
146
|
#
|
140
147
|
# Injects dependencies into a specific, existing object.
|
141
148
|
#
|
142
|
-
# DI.inject_instance
|
149
|
+
# DI.inject_instance obj, :foo, :bar
|
143
150
|
#
|
144
151
|
# @param instance [Object] The object you wish to inject dependencies into
|
145
152
|
# @param dependencies [Symbol] All dependency names you want to inject.
|
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.4.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-25 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
|