sinject 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae615b99554095a49b4dfdcc5a9a9ea78e4a08d1
4
- data.tar.gz: 30d3a94b536b9144b89a6ec56f652f3f769421d0
3
+ metadata.gz: b4b501138ed0b8872f405861b14cde245114c751
4
+ data.tar.gz: d88eebbbfd2396a0ac99b666bedd68ac2ff0697a
5
5
  SHA512:
6
- metadata.gz: c4087a95afe29888fcb5a2a80a9c8171a762e82ce1be89fae688f35fa97615d20ada0e325ce7bbc2840a1d6335109f242561f5b92a8e802133ee925c3ee31aeb
7
- data.tar.gz: fb588c3e58110e11bcb3bb3e38c69b7d14a80499b1fb03a605e97f0079fda8d949e97dfc480a94ff4a606ab89be3715651f8858ca073022d3bef5c594b502be5
6
+ metadata.gz: 91617b66be38aa50184ce4632e0599245f51b6aa8a53f235bb7f3d53d051f3b8b7a57eafec890fa65cd86848166dd846c78e9d613ed54d8fda5d80b0d27487df
7
+ data.tar.gz: d4faa88400fc584775400549212b7bb2b7f868999d831891fe7900f08d3875303389308216cd3efa05b8692a14e617d35a0858db414c216f7b2bf4b418457a8e
data/README.md CHANGED
@@ -27,7 +27,7 @@ If you're using rails then after you've installed the gem you need to create a *
27
27
 
28
28
  **Registering dependencies**
29
29
 
30
- Dependency objects need to be registered with the container before use, to do so you need to configure the SinjectContainer from the *'dependencies.rb'* file:
30
+ Dependency objects need to be registered with the container before use, to do so you need to configure the SinjectContainer: [If you're using rails this will need to be done within the *'dependencies.rb'* file]
31
31
 
32
32
  #initialize the container
33
33
  container = SinjectContainer.new
@@ -43,7 +43,7 @@ Dependencies can be registered with the container in 2 modes:
43
43
 
44
44
  The registration mode can be set by specifying **true** or **false** to the *'single_instance'* argument of the containers register method.
45
45
 
46
- Dependencies that require custom initialization can be registered with an initialization block to handle creation of the dependency, this allows you more control over how the dependency is created:
46
+ Dependencies that require custom initialization can be registered with an initialization block to handle the creation of the dependency, this allows you more control over how the dependency is created if required:
47
47
 
48
48
  container.register(:cache_store, RedisCacheStore, true) do
49
49
  instance = RedisCacheStore.new
@@ -77,9 +77,9 @@ Sinject will then validate that the registered dependency meets the requirements
77
77
 
78
78
  **Dependency Groups**
79
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)*.
80
+ Dependency registration 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 be loaded in different circumstances *(e.g. per environment)*.
81
81
 
82
- To create a dependency group create a class that inherits from the DependencyGroup base class and implement the *'register'* & *'is_valid'* methods.
82
+ To create a dependency group, create a class that inherits from the `DependencyGroup` base class and implement the `register` & `is_valid?` methods.
83
83
 
84
84
  For example:
85
85
 
@@ -95,8 +95,10 @@ For example:
95
95
  end
96
96
  end
97
97
 
98
- Only dependency groups that return **True** from the is_valid? method will be loaded.
98
+ To load valid dependency groups the following method needs to be called from the container:
99
99
 
100
+ container.load_groups
101
+
100
102
  **Assigning dependencies**
101
103
 
102
104
  To assign a dependency to an object you need to add the dependency attribute to the class and specify the symbol key that was used to register the dependency with the SinjectContainer:
data/lib/sinject.rb CHANGED
@@ -39,6 +39,11 @@ class SinjectContainer
39
39
  # single_instance: (Boolean)
40
40
  def register(key, dependency_class_name, single_instance = false, contract_class_name = nil, &initialize_block)
41
41
 
42
+ #check if a dependency has already been registered for this key.
43
+ if is_registered?(key)
44
+ raise DependencyRegistrationException.new(key)
45
+ end
46
+
42
47
  #check if a contract has been specified
43
48
  if contract_class_name != nil
44
49
  #validate the dependency class against the contract
@@ -215,6 +220,18 @@ class DependencyInitializeException < StandardError
215
220
 
216
221
  end
217
222
 
223
+ class DependencyRegistrationException < StandardError
224
+
225
+ def initialize(key)
226
+ @key = key
227
+ end
228
+
229
+ def to_s
230
+ "A Dependency has already been registered for the key: '#{key}'"
231
+ end
232
+
233
+ end
234
+
218
235
  class DependencyGroup
219
236
 
220
237
  def register(container)
@@ -1,3 +1,3 @@
1
1
  module Sinject
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinject
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - vaughan britton