sinject 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -1
- data/lib/sinject.rb +25 -0
- data/lib/sinject/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: ae615b99554095a49b4dfdcc5a9a9ea78e4a08d1
|
4
|
+
data.tar.gz: 30d3a94b536b9144b89a6ec56f652f3f769421d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4087a95afe29888fcb5a2a80a9c8171a762e82ce1be89fae688f35fa97615d20ada0e325ce7bbc2840a1d6335109f242561f5b92a8e802133ee925c3ee31aeb
|
7
|
+
data.tar.gz: fb588c3e58110e11bcb3bb3e38c69b7d14a80499b1fb03a605e97f0079fda8d949e97dfc480a94ff4a606ab89be3715651f8858ca073022d3bef5c594b502be5
|
data/README.md
CHANGED
@@ -56,7 +56,7 @@ Dependencies with a custom initialization block must return an object of the reg
|
|
56
56
|
|
57
57
|
**Dependency Contracts**
|
58
58
|
|
59
|
-
Dependency contracts can be defined to validate registered dependencies are valid for the task they are being registered for.
|
59
|
+
Dependency contracts can be defined to validate registered dependencies are valid for the task they are being registered for. *(If you are familiar with other type based languages then you can think of this as a kind of Interface)*
|
60
60
|
|
61
61
|
To create a dependency contract you need to create a new class with empty methods for each of the methods that the dependency needs to respond to in order to fulfill it's role:
|
62
62
|
|
@@ -75,6 +75,27 @@ Sinject will then validate that the registered dependency meets the requirements
|
|
75
75
|
- `DependencyContractMissingMethodsException` is raised when 1 or more methods from the contract could not be found on the dependency.
|
76
76
|
- `DependencyContractInvalidParametersException` is raised when the parameters of a contract method do not match the parameters found on a dependency method.
|
77
77
|
|
78
|
+
**Dependency Groups**
|
79
|
+
|
80
|
+
Dependency registrations groups can be created to allow groups of dependencies to be set without the need for manual registration *(e.g. to include with a gem for auto registration)*, or to allow different dependency groups to bd loaded in different circumstances *(e.g. per environment)*.
|
81
|
+
|
82
|
+
To create a dependency group create a class that inherits from the DependencyGroup base class and implement the *'register'* & *'is_valid'* methods.
|
83
|
+
|
84
|
+
For example:
|
85
|
+
|
86
|
+
#create a development only dependency group
|
87
|
+
class DevelopmentDependencies < DependencyGroup
|
88
|
+
def register(container)
|
89
|
+
container.register(:cache_store, LocalCacheStore, true)
|
90
|
+
container.register(:logger, TerminalLogger, true)
|
91
|
+
end
|
92
|
+
|
93
|
+
def is_valid?
|
94
|
+
Rails.env.development?
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
Only dependency groups that return **True** from the is_valid? method will be loaded.
|
78
99
|
|
79
100
|
**Assigning dependencies**
|
80
101
|
|
data/lib/sinject.rb
CHANGED
@@ -85,6 +85,15 @@ class SinjectContainer
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
+
def load_groups
|
89
|
+
DependencyGroup.descendants.each do |g|
|
90
|
+
group = g.new
|
91
|
+
if group.is_valid?
|
92
|
+
group.register(SinjectContainer.instance)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
88
97
|
private
|
89
98
|
|
90
99
|
def validate_contract(dependency_class, contract_class)
|
@@ -205,3 +214,19 @@ class DependencyInitializeException < StandardError
|
|
205
214
|
end
|
206
215
|
|
207
216
|
end
|
217
|
+
|
218
|
+
class DependencyGroup
|
219
|
+
|
220
|
+
def register(container)
|
221
|
+
|
222
|
+
end
|
223
|
+
|
224
|
+
def is_valid?
|
225
|
+
return true
|
226
|
+
end
|
227
|
+
|
228
|
+
def self.descendants
|
229
|
+
ObjectSpace.each_object(Class).select { |klass| klass < self }
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|
data/lib/sinject/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinject
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vaughan britton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|