codeine 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/flexible.rb +6 -4
- data/examples/simple.rb +3 -1
- data/lib/codeine.rb +8 -0
- data/lib/codeine/container.rb +4 -0
- data/lib/codeine/version.rb +1 -1
- data/readme.markdown +31 -22
- data/spec/container_spec.rb +9 -0
- metadata +4 -4
data/examples/flexible.rb
CHANGED
@@ -21,11 +21,13 @@ module BarModule
|
|
21
21
|
end
|
22
22
|
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
Codeine.configure(FooModule) do |c|
|
25
|
+
c.register(:logger){"the fancy logger for FooModule"}
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
Codeine.configure(BarModule) do |c|
|
29
|
+
c.register(:logger){"the simple logger for BarModule"}
|
30
|
+
end
|
29
31
|
|
30
32
|
|
31
33
|
FooModule::A.new
|
data/examples/simple.rb
CHANGED
data/lib/codeine.rb
CHANGED
data/lib/codeine/container.rb
CHANGED
data/lib/codeine/version.rb
CHANGED
data/readme.markdown
CHANGED
@@ -3,44 +3,53 @@ Codeine
|
|
3
3
|
|
4
4
|
A simple dependency injector for ruby projects.
|
5
5
|
|
6
|
-
Despite how flexible ruby is, and
|
6
|
+
Despite how flexible ruby is, and the insistence of [some seriously smart people](http://weblog.jamisbuck.org/2008/11/9/legos-play-doh-and-programming), I frequently run into the need on larger projects to centrally manage my dependencies. I end up building something like Codeine for each one, so I decided to build it one more time and re-use it.
|
7
|
+
|
8
|
+
It turns out I agree with basically [everything Alexey Petrushin wrote here](http://ruby-lang.info/blog/you-underestimate-the-power-of-ioc-3fh)
|
9
|
+
|
7
10
|
|
8
11
|
Usage
|
9
12
|
-----
|
10
13
|
|
11
14
|
Codeine can operate as either a global or module-local dependency container. Using it globally is the least flexible, but presents the simplest syntax.
|
12
15
|
|
13
|
-
|
14
|
-
|
16
|
+
```ruby
|
17
|
+
require 'codeine'
|
18
|
+
Codeine.register(:logger){Logger.new}
|
15
19
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
class Foo
|
21
|
+
codeine_inject :logger
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
logger.log "Initialized..."
|
25
|
+
end
|
26
|
+
end
|
27
|
+
```
|
23
28
|
|
24
29
|
|
25
30
|
For library code, and for larger projects, it's probably a better idea to segregate the containers.
|
26
31
|
|
27
|
-
|
32
|
+
```ruby
|
33
|
+
require 'codeine'
|
28
34
|
|
29
35
|
|
30
|
-
|
31
|
-
|
32
|
-
|
36
|
+
module ProjectA
|
37
|
+
class Foo
|
38
|
+
codeine_inject :logger
|
33
39
|
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
40
|
+
def initialize
|
41
|
+
logger.log "Initialized..."
|
38
42
|
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
Codeine.configure(ProjectA) do
|
47
|
+
c.register(:logger){Logger.new}
|
48
|
+
end
|
39
49
|
|
40
|
-
|
41
|
-
|
50
|
+
foo = ProjectA::Foo.new
|
51
|
+
```
|
42
52
|
|
43
|
-
|
53
|
+
The container bound to the ProjectA module will only service injection requests from classes/modules that reside within it
|
44
54
|
|
45
55
|
|
46
|
-
The the container bound to the ProjectA module will only service injection requests from classes/modules that reside within it
|
data/spec/container_spec.rb
CHANGED
@@ -52,4 +52,13 @@ describe Codeine::Container do
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
+
describe "#configure" do
|
56
|
+
it "should accept a block and yield self" do
|
57
|
+
container.configure do |c|
|
58
|
+
c.register(:foo) {"bar"}
|
59
|
+
end
|
60
|
+
container.get(:foo).should == "bar"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
55
64
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codeine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-10-
|
12
|
+
date: 2011-10-10 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &16349240 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *16349240
|
25
25
|
description: A really simple, partitionable, ruby-flavored dependency injector
|
26
26
|
email:
|
27
27
|
- tim.ariyeh@gmail.com
|