injectable 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -4
- data/lib/injectable.rb +15 -0
- data/lib/injectable/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -11,7 +11,7 @@ Usage
|
|
11
11
|
Say we have a `UserService` that has some basic logic for performing operations
|
12
12
|
related to a `User` and a `FacebookService`. We can tell the `UserService` what
|
13
13
|
its dependencies are via `Injectable`. Note that as of `0.0.2` all objects that
|
14
|
-
can be
|
14
|
+
can be injected into others must include the `Injectable` module.
|
15
15
|
|
16
16
|
```ruby
|
17
17
|
class User
|
@@ -64,7 +64,8 @@ user_service = container.get(:user_service)
|
|
64
64
|
```
|
65
65
|
|
66
66
|
Injectable also supports depending on roles rather than concrete classes by
|
67
|
-
allowing the registration of classes whose instances perform that role
|
67
|
+
allowing the registration of classes whose instances perform that role. An
|
68
|
+
implementation can be registered on a single container itself as a "one off":
|
68
69
|
|
69
70
|
```ruby
|
70
71
|
container = Injectable::Container.new
|
@@ -73,10 +74,13 @@ user_service = container.get(:user_service)
|
|
73
74
|
# `user_service`'s facebook_service will be an instance of DifferentFacebookService
|
74
75
|
```
|
75
76
|
|
76
|
-
You can also define concrete implementations at the global level
|
77
|
+
You can also define concrete implementations at the global level via `configure`:
|
77
78
|
|
78
79
|
```ruby
|
79
|
-
Injectable
|
80
|
+
Injectable.configure do |config|
|
81
|
+
config.register_implementation(:facebook_service, DifferentFacebookService)
|
82
|
+
end
|
83
|
+
|
80
84
|
container = Injectable::Container.new
|
81
85
|
user_service = container.get(:user_service)
|
82
86
|
# `user_service`'s facebook_service will be an instance of DifferentFacebookService
|
data/lib/injectable.rb
CHANGED
@@ -14,6 +14,21 @@ module Injectable
|
|
14
14
|
|
15
15
|
class << self
|
16
16
|
|
17
|
+
# Configure the global injectable registry. Simply just yields to the
|
18
|
+
# registry itself. If no block is provided returns the registry.
|
19
|
+
#
|
20
|
+
# @example Configure the registry.
|
21
|
+
# Injectable.configure do |registry|
|
22
|
+
# registry.register_implementation(:user, User)
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# @return [ Injectable::Registry ] The registry.
|
26
|
+
#
|
27
|
+
# @since 0.0.3
|
28
|
+
def configure
|
29
|
+
block_given? ? yield(Registry) : Registry
|
30
|
+
end
|
31
|
+
|
17
32
|
# Including the Injectable module will extend the class with the necessary
|
18
33
|
# macros.
|
19
34
|
#
|
data/lib/injectable/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: injectable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -55,7 +55,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
55
|
version: '0'
|
56
56
|
segments:
|
57
57
|
- 0
|
58
|
-
hash: -
|
58
|
+
hash: -519657374346971908
|
59
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
60
|
none: false
|
61
61
|
requirements:
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
version: '0'
|
65
65
|
segments:
|
66
66
|
- 0
|
67
|
-
hash: -
|
67
|
+
hash: -519657374346971908
|
68
68
|
requirements: []
|
69
69
|
rubyforge_project:
|
70
70
|
rubygems_version: 1.8.24
|