injectable 0.0.4 → 0.0.5

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.
data/README.md CHANGED
@@ -54,6 +54,16 @@ container = Injectable::Container.new(user, facebook_service)
54
54
  user_service = container.get(:user_service)
55
55
  ```
56
56
 
57
+ Objects can also be added to the container post instantiation.
58
+
59
+ ```ruby
60
+ user = User.new
61
+ facebook_service = FacebookService.new
62
+ container = Injectable::Container.new
63
+ container.put(user, facebook_service)
64
+ user_service = container.get(:user_service)
65
+ ```
66
+
57
67
  Since `User` and `FacebookService` take no arguments, we don't even need to
58
68
  pass them into the container - it will automatically instantiate new ones:
59
69
 
@@ -47,6 +47,25 @@ module Injectable
47
47
  end
48
48
  end
49
49
 
50
+ # Put objects into the container. Can be a single or multiple instances.
51
+ #
52
+ # @example Put an object in the container.
53
+ # container.put(user)
54
+ #
55
+ # @example Put multiple objects in the container.
56
+ # container.put(user, user_finder)
57
+ #
58
+ # @param [ *Object ] objects The objects to put in the container.
59
+ #
60
+ # @return [ Injectable::Container ] The container itself.
61
+ #
62
+ # @since 0.0.0
63
+ def put(*objects)
64
+ objects.flatten.each do |object|
65
+ instantiated_objects[object.class] = object
66
+ end and self
67
+ end
68
+
50
69
  # This error is raised when asking for an object out of the container that
51
70
  # cannot be resolved.
52
71
  #
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Injectable
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
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
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-17 00:00:00.000000000 Z
12
+ date: 2013-01-18 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Dead simple Ruby dependency injection
15
15
  email:
@@ -42,7 +42,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
42
42
  version: '0'
43
43
  segments:
44
44
  - 0
45
- hash: 1285461619687616243
45
+ hash: -1355353312328350373
46
46
  required_rubygems_version: !ruby/object:Gem::Requirement
47
47
  none: false
48
48
  requirements:
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  version: '0'
52
52
  segments:
53
53
  - 0
54
- hash: 1285461619687616243
54
+ hash: -1355353312328350373
55
55
  requirements: []
56
56
  rubyforge_project:
57
57
  rubygems_version: 1.8.24