dim 0.9.1 → 1.0.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.
- data/.rvmrc +1 -1
- data/Gemfile.lock +1 -1
- data/README.markdown +77 -0
- data/dim.gemspec +4 -6
- data/lib/dim/version.rb +1 -1
- metadata +6 -8
- data/README.md +0 -16
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm use 1.9.2@dim --create
|
1
|
+
rvm use 1.9.2-p136@dim --create
|
data/Gemfile.lock
CHANGED
data/README.markdown
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# DIM: Dependency Injection - Minimal
|
2
|
+
|
3
|
+
DIM is [Jim Weirich's](http://onestepback.org) minimalistic dependency injection framework, maintained in
|
4
|
+
gem form by [Mike Subelsky](http://subelsky.com).
|
5
|
+
|
6
|
+
Dependency injection lets you organize all of your app's object setup code in one place by creating a
|
7
|
+
container. Whenver an object in your application needs access to another object or resource, it asks
|
8
|
+
the container to provide it (using lazily-evaluated code blocks).
|
9
|
+
|
10
|
+
When testing your code, you can either stub out services on the container, or you can provide a substitute container.
|
11
|
+
|
12
|
+
## Example
|
13
|
+
|
14
|
+
The following could be in a "lib.init.rb" file or in a Rails app, "config/initializers/container.rb":
|
15
|
+
|
16
|
+
require "dim"
|
17
|
+
require "logger"
|
18
|
+
require 'game'
|
19
|
+
require 'event_handler'
|
20
|
+
require 'transmitter'
|
21
|
+
|
22
|
+
ServerContainer = Dim::Container.new
|
23
|
+
|
24
|
+
ServerContainer.register(:transmitter) { |c| Transmitter.new(c.logger) }
|
25
|
+
|
26
|
+
ServerContainer.register(:event_handler) do |c|
|
27
|
+
eh = EventHandler.new
|
28
|
+
eh.transmitter = c.transmitter
|
29
|
+
eh.logger = c.logger
|
30
|
+
eh
|
31
|
+
end
|
32
|
+
|
33
|
+
ServerContainer.register(:listening_host) { "0.0.0.0" }
|
34
|
+
ServerContainer.register(:listening_port) { "8080" }
|
35
|
+
|
36
|
+
ServerContainer.register(:game) do |c|
|
37
|
+
game = Game.new
|
38
|
+
game.logger = c.logger
|
39
|
+
game.event_handler = c.event_handler
|
40
|
+
game.host = c.listening_host
|
41
|
+
game.port = c.listening_port
|
42
|
+
game
|
43
|
+
end
|
44
|
+
|
45
|
+
ServerContainer.register(:root_dir) do |c|
|
46
|
+
Pathname.new(File.expand_path(File.dirname(__FILE__) + "/.."))
|
47
|
+
end
|
48
|
+
|
49
|
+
ServerContainer.register(:log_file_path) do |c|
|
50
|
+
"#{c.root_dir}/log/#{c.environment}.log"
|
51
|
+
end
|
52
|
+
|
53
|
+
ServerContainer.register(:logger) do |c|
|
54
|
+
Logger.new(c.log_file_path)
|
55
|
+
end
|
56
|
+
|
57
|
+
Using the above code elsewhere in the app, when you want a reference to the app's logger object:
|
58
|
+
|
59
|
+
ServerContainer.logger.info("I didn't have to setup my own logger")
|
60
|
+
|
61
|
+
Or if you wanted access to the game instance created during setup (which already is configured with everything it needs):
|
62
|
+
|
63
|
+
current_game = ServerContainer.game
|
64
|
+
|
65
|
+
If you don't like creating even the one dependency on the global constant ServerContainer, you could
|
66
|
+
inject ServerContainer itself into your objects like so:
|
67
|
+
|
68
|
+
World.new(GameContainer)
|
69
|
+
|
70
|
+
## More Background
|
71
|
+
|
72
|
+
Jim wrote a [nice article](http://onestepback.org/index.cgi/Tech/Ruby/DependencyInjectionInRuby.rdoc) explaining
|
73
|
+
the rationale for this code and how it works. Also check out [his slides](http://onestepback.org/articles/depinj/).
|
74
|
+
|
75
|
+
# License
|
76
|
+
|
77
|
+
DIM is available under the MIT license (see the file MIT-LICENSE for details).
|
data/dim.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
$:.unshift(File.dirname(__FILE__))
|
2
|
+
require 'lib/dim/version'
|
2
3
|
|
3
4
|
Gem::Specification.new do |s|
|
4
5
|
s.name = %q{dim}
|
@@ -6,16 +7,13 @@ Gem::Specification.new do |s|
|
|
6
7
|
s.authors = ["Jim Weirich", "Mike Subelsky"]
|
7
8
|
s.date = Time.now.utc.strftime("%Y-%m-%d")
|
8
9
|
s.email = %q{mike@subelsky.com}
|
9
|
-
s.extra_rdoc_files =
|
10
|
-
"README.md"
|
11
|
-
]
|
10
|
+
s.extra_rdoc_files = %w(README.markdown)
|
12
11
|
s.files = `git ls-files`.split("\n")
|
13
12
|
s.homepage = %q{http://github.com/subelsky/dim}
|
14
13
|
s.rdoc_options = ["--charset=UTF-8"]
|
15
14
|
s.require_paths = ["lib"]
|
16
|
-
s.rubygems_version = %q{1.5.0}
|
17
15
|
s.summary = %q{Minimalistic dependency injection framework}
|
18
|
-
s.description = %q{Minimalistic dependency injection framework}
|
16
|
+
s.description = %q{Minimalistic dependency injection framework keeps all of your object setup code in one place.}
|
19
17
|
s.test_files = `git ls-files spec`.split("\n")
|
20
18
|
s.add_development_dependency 'rspec'
|
21
19
|
s.add_development_dependency 'rspec-given'
|
data/lib/dim/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: dim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 1.0.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jim Weirich
|
@@ -11,8 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2011-
|
15
|
-
default_executable:
|
14
|
+
date: 2011-05-18 00:00:00 Z
|
16
15
|
dependencies:
|
17
16
|
- !ruby/object:Gem::Dependency
|
18
17
|
name: rspec
|
@@ -36,14 +35,14 @@ dependencies:
|
|
36
35
|
version: "0"
|
37
36
|
type: :development
|
38
37
|
version_requirements: *id002
|
39
|
-
description: Minimalistic dependency injection framework
|
38
|
+
description: Minimalistic dependency injection framework keeps all of your object setup code in one place.
|
40
39
|
email: mike@subelsky.com
|
41
40
|
executables: []
|
42
41
|
|
43
42
|
extensions: []
|
44
43
|
|
45
44
|
extra_rdoc_files:
|
46
|
-
- README.
|
45
|
+
- README.markdown
|
47
46
|
files:
|
48
47
|
- .gitignore
|
49
48
|
- .rspec
|
@@ -51,13 +50,12 @@ files:
|
|
51
50
|
- Gemfile
|
52
51
|
- Gemfile.lock
|
53
52
|
- MIT-LICENSE
|
54
|
-
- README.
|
53
|
+
- README.markdown
|
55
54
|
- Rakefile
|
56
55
|
- dim.gemspec
|
57
56
|
- lib/dim.rb
|
58
57
|
- lib/dim/version.rb
|
59
58
|
- spec/dim_spec.rb
|
60
|
-
has_rdoc: true
|
61
59
|
homepage: http://github.com/subelsky/dim
|
62
60
|
licenses: []
|
63
61
|
|
@@ -81,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
79
|
requirements: []
|
82
80
|
|
83
81
|
rubyforge_project:
|
84
|
-
rubygems_version: 1.
|
82
|
+
rubygems_version: 1.8.2
|
85
83
|
signing_key:
|
86
84
|
specification_version: 3
|
87
85
|
summary: Minimalistic dependency injection framework
|
data/README.md
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# DIM: Dependency Injection - Minimal
|
2
|
-
|
3
|
-
DIM is Jim Weirich's minimalistic dependency injection framework,
|
4
|
-
maintained in Gem form by [Mike Subelsky](http://subelsky.com).
|
5
|
-
For more background information, read Jim's [Dependency Injection](http://onestepback.org/articles/depinj/dim/dim_rb.html))
|
6
|
-
slides.
|
7
|
-
|
8
|
-
# License
|
9
|
-
|
10
|
-
DIM is available under the MIT license (see the file MIT-LICENSE for
|
11
|
-
details).
|
12
|
-
|
13
|
-
# More Information:
|
14
|
-
|
15
|
-
Read [this](http://onestepback.org/articles/depinj/appendixa.html) for
|
16
|
-
more information about using DIM.
|