dependo 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +62 -0
- data/Rakefile +33 -0
- data/doc/Dependo.html +151 -0
- data/doc/Dependo/Mixin.html +267 -0
- data/doc/Dependo/Registry.html +608 -0
- data/doc/_index.html +140 -0
- data/doc/class_list.html +53 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +328 -0
- data/doc/file.README.html +132 -0
- data/doc/file_list.html +55 -0
- data/doc/frames.html +28 -0
- data/doc/index.html +132 -0
- data/doc/js/app.js +214 -0
- data/doc/js/full_list.js +173 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +100 -0
- data/doc/top-level-namespace.html +112 -0
- data/lib/dependo.rb +54 -0
- data/spec/dependo_spec.rb +194 -0
- data/spec/spec_helper.rb +13 -0
- metadata +101 -0
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Dependo
|
2
|
+
|
3
|
+
Dependo is a very simple Dependency Injection framework for Ruby. Some say [you don't need dependency injection](http://weblog.jamisbuck.org/2008/11/9/legos-play-doh-and-programming) when you're using Ruby. Maybe they're right, but I've come across some places where I need it.
|
4
|
+
|
5
|
+
For example, in my apps using Sinatra and Sequel, I need to be able to log, using a single Logger instance, from both my Sinatra app and from within my Sequel models. I'm not about to pass that Logger around as a parameter anywhere, and I don't want to instantiate it in every class that needs to log.
|
6
|
+
|
7
|
+
So, injecting the Logger is the easiest, best solution.
|
8
|
+
|
9
|
+
## Requirements/Installation
|
10
|
+
|
11
|
+
Dependo doesn't depend on anything. In test, it relies on rspec and either rcov (Ruby 1.8) or simplecov (Ruby 1.9).
|
12
|
+
|
13
|
+
Install the gem: ```gem install dependo-(version).gem```
|
14
|
+
|
15
|
+
## Running the tests:
|
16
|
+
|
17
|
+
```rake spec```
|
18
|
+
|
19
|
+
## Building the gem:
|
20
|
+
|
21
|
+
```rake gem:build```
|
22
|
+
|
23
|
+
## Install gem with Rake:
|
24
|
+
|
25
|
+
```rake gem:install```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
### Register
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
Dependo::Registry[:log] = Logger.new(STDOUT)
|
33
|
+
```
|
34
|
+
|
35
|
+
### Include
|
36
|
+
|
37
|
+
This makes it easy to use your injected dependencies as instance methods:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
class MyThing
|
41
|
+
include Dependo::Mixin
|
42
|
+
end
|
43
|
+
|
44
|
+
thing = MyThing.new
|
45
|
+
thing.log.info "I'm logging!"
|
46
|
+
```
|
47
|
+
|
48
|
+
### Extend
|
49
|
+
|
50
|
+
This makes it easy to use your injected dependencies as class methods:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
class MyThing
|
54
|
+
extend Dependo::Mixin
|
55
|
+
end
|
56
|
+
|
57
|
+
MyThing.log.info "I'm logging!"
|
58
|
+
```
|
59
|
+
|
60
|
+
##License
|
61
|
+
|
62
|
+
See the LICENSE file. Licensed under the Apache 2.0 License
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require "#{File.dirname(__FILE__)}/lib/dependo"
|
4
|
+
|
5
|
+
task :default => :spec
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
desc 'Run all rspec tests with rcov (1.8 only)'
|
9
|
+
RSpec::Core::RakeTask.new(:rcov) do |t|
|
10
|
+
t.rcov_opts = %q[--exclude "spec,gems"]
|
11
|
+
t.rcov = true
|
12
|
+
end
|
13
|
+
|
14
|
+
namespace :gem do
|
15
|
+
task :build do
|
16
|
+
puts `yard`
|
17
|
+
puts `gem build dependo.gemspec`
|
18
|
+
end
|
19
|
+
|
20
|
+
task :install do
|
21
|
+
puts `gem install dependo-#{Dependo::VERSION}.gem`
|
22
|
+
end
|
23
|
+
|
24
|
+
task :uninstall do
|
25
|
+
puts `gem uninstall dependo`
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'Build yard documentation'
|
30
|
+
task :yard do
|
31
|
+
puts `yard`
|
32
|
+
`open doc/index.html`
|
33
|
+
end
|
data/doc/Dependo.html
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
<title>
|
7
|
+
Module: Dependo
|
8
|
+
|
9
|
+
— Documentation by YARD 0.8.2.1
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
19
|
+
relpath = '';
|
20
|
+
framesUrl = "frames.html#!" + escape(window.location.href);
|
21
|
+
</script>
|
22
|
+
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
25
|
+
|
26
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
27
|
+
|
28
|
+
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="header">
|
32
|
+
<div id="menu">
|
33
|
+
|
34
|
+
<a href="_index.html">Index (D)</a> »
|
35
|
+
|
36
|
+
|
37
|
+
<span class="title">Dependo</span>
|
38
|
+
|
39
|
+
|
40
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
41
|
+
</div>
|
42
|
+
|
43
|
+
<div id="search">
|
44
|
+
|
45
|
+
<a class="full_list_link" id="class_list_link"
|
46
|
+
href="class_list.html">
|
47
|
+
Class List
|
48
|
+
</a>
|
49
|
+
|
50
|
+
<a class="full_list_link" id="method_list_link"
|
51
|
+
href="method_list.html">
|
52
|
+
Method List
|
53
|
+
</a>
|
54
|
+
|
55
|
+
<a class="full_list_link" id="file_list_link"
|
56
|
+
href="file_list.html">
|
57
|
+
File List
|
58
|
+
</a>
|
59
|
+
|
60
|
+
</div>
|
61
|
+
<div class="clear"></div>
|
62
|
+
</div>
|
63
|
+
|
64
|
+
<iframe id="search_frame"></iframe>
|
65
|
+
|
66
|
+
<div id="content"><h1>Module: Dependo
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
</h1>
|
71
|
+
|
72
|
+
<dl class="box">
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
<dt class="r1 last">Defined in:</dt>
|
82
|
+
<dd class="r1 last">lib/dependo.rb</dd>
|
83
|
+
|
84
|
+
</dl>
|
85
|
+
<div class="clear"></div>
|
86
|
+
|
87
|
+
<h2>Overview</h2><div class="docstring">
|
88
|
+
<div class="discussion">
|
89
|
+
|
90
|
+
<p>Dependency Injection Framework</p>
|
91
|
+
|
92
|
+
|
93
|
+
</div>
|
94
|
+
</div>
|
95
|
+
<div class="tags">
|
96
|
+
|
97
|
+
|
98
|
+
</div><h2>Defined Under Namespace</h2>
|
99
|
+
<p class="children">
|
100
|
+
|
101
|
+
|
102
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Dependo/Mixin.html" title="Dependo::Mixin (module)">Mixin</a></span>
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Dependo/Registry.html" title="Dependo::Registry (class)">Registry</a></span>
|
107
|
+
|
108
|
+
|
109
|
+
</p>
|
110
|
+
|
111
|
+
<h2>Constant Summary</h2>
|
112
|
+
|
113
|
+
<dl class="constants">
|
114
|
+
|
115
|
+
<dt id="VERSION-constant" class="">VERSION =
|
116
|
+
<div class="docstring">
|
117
|
+
<div class="discussion">
|
118
|
+
|
119
|
+
<p>The gem version</p>
|
120
|
+
|
121
|
+
|
122
|
+
</div>
|
123
|
+
</div>
|
124
|
+
<div class="tags">
|
125
|
+
|
126
|
+
|
127
|
+
</div>
|
128
|
+
</dt>
|
129
|
+
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>0.1</span><span class='tstring_end'>"</span></span></pre></dd>
|
130
|
+
|
131
|
+
</dl>
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
</div>
|
143
|
+
|
144
|
+
<div id="footer">
|
145
|
+
Generated on Thu Oct 25 14:04:32 2012 by
|
146
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
147
|
+
0.8.2.1 (ruby-1.9.3).
|
148
|
+
</div>
|
149
|
+
|
150
|
+
</body>
|
151
|
+
</html>
|
@@ -0,0 +1,267 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
<title>
|
7
|
+
Module: Dependo::Mixin
|
8
|
+
|
9
|
+
— Documentation by YARD 0.8.2.1
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="../css/common.css" type="text/css" media="screen" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
19
|
+
relpath = '../';
|
20
|
+
framesUrl = "../frames.html#!" + escape(window.location.href);
|
21
|
+
</script>
|
22
|
+
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
|
25
|
+
|
26
|
+
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
|
27
|
+
|
28
|
+
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="header">
|
32
|
+
<div id="menu">
|
33
|
+
|
34
|
+
<a href="../_index.html">Index (M)</a> »
|
35
|
+
<span class='title'><span class='object_link'><a href="../Dependo.html" title="Dependo (module)">Dependo</a></span></span>
|
36
|
+
»
|
37
|
+
<span class="title">Mixin</span>
|
38
|
+
|
39
|
+
|
40
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
41
|
+
</div>
|
42
|
+
|
43
|
+
<div id="search">
|
44
|
+
|
45
|
+
<a class="full_list_link" id="class_list_link"
|
46
|
+
href="../class_list.html">
|
47
|
+
Class List
|
48
|
+
</a>
|
49
|
+
|
50
|
+
<a class="full_list_link" id="method_list_link"
|
51
|
+
href="../method_list.html">
|
52
|
+
Method List
|
53
|
+
</a>
|
54
|
+
|
55
|
+
<a class="full_list_link" id="file_list_link"
|
56
|
+
href="../file_list.html">
|
57
|
+
File List
|
58
|
+
</a>
|
59
|
+
|
60
|
+
</div>
|
61
|
+
<div class="clear"></div>
|
62
|
+
</div>
|
63
|
+
|
64
|
+
<iframe id="search_frame"></iframe>
|
65
|
+
|
66
|
+
<div id="content"><h1>Module: Dependo::Mixin
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
</h1>
|
71
|
+
|
72
|
+
<dl class="box">
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
<dt class="r1 last">Defined in:</dt>
|
82
|
+
<dd class="r1 last">lib/dependo.rb</dd>
|
83
|
+
|
84
|
+
</dl>
|
85
|
+
<div class="clear"></div>
|
86
|
+
|
87
|
+
<h2>Overview</h2><div class="docstring">
|
88
|
+
<div class="discussion">
|
89
|
+
|
90
|
+
<p>Allows dependencies to be injected into your classes. This can be done
|
91
|
+
using both "include" or "extend", depending on whether you need to use the
|
92
|
+
dependencies as instance methods or class methods. Note that you can also
|
93
|
+
do both.</p>
|
94
|
+
|
95
|
+
|
96
|
+
</div>
|
97
|
+
</div>
|
98
|
+
<div class="tags">
|
99
|
+
|
100
|
+
|
101
|
+
</div>
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
<h2>
|
110
|
+
Instance Method Summary
|
111
|
+
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
|
112
|
+
</h2>
|
113
|
+
|
114
|
+
<ul class="summary">
|
115
|
+
|
116
|
+
<li class="public ">
|
117
|
+
<span class="summary_signature">
|
118
|
+
|
119
|
+
<a href="#method_missing-instance_method" title="#method_missing (instance method)">- (Object) <strong>method_missing</strong>(key) </a>
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
</span>
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
<span class="summary_desc"><div class='inline'>
|
134
|
+
<p>The injected dependency in the Dependo::Registry with the given name.</p>
|
135
|
+
</div></span>
|
136
|
+
|
137
|
+
</li>
|
138
|
+
|
139
|
+
|
140
|
+
</ul>
|
141
|
+
|
142
|
+
|
143
|
+
<div id="method_missing_details" class="method_details_list">
|
144
|
+
<h2>Dynamic Method Handling</h2>
|
145
|
+
<p class="notice this">
|
146
|
+
This class handles dynamic methods through the <tt>method_missing</tt> method
|
147
|
+
|
148
|
+
</p>
|
149
|
+
|
150
|
+
<div class="method_details first">
|
151
|
+
<h3 class="signature first" id="method_missing-instance_method">
|
152
|
+
|
153
|
+
- (<tt>Object</tt>) <strong>method_missing</strong>(key)
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
</h3><div class="docstring">
|
160
|
+
<div class="discussion">
|
161
|
+
|
162
|
+
<p>The injected dependency in the Dependo::Registry with the given name</p>
|
163
|
+
|
164
|
+
|
165
|
+
</div>
|
166
|
+
</div>
|
167
|
+
<div class="tags">
|
168
|
+
<p class="tag_title">Parameters:</p>
|
169
|
+
<ul class="param">
|
170
|
+
|
171
|
+
<li>
|
172
|
+
|
173
|
+
<span class='name'>key</span>
|
174
|
+
|
175
|
+
|
176
|
+
<span class='type'>(<tt>symbol</tt>)</span>
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
—
|
181
|
+
<div class='inline'>
|
182
|
+
<p>the name of the method that didn't exist on your object or class</p>
|
183
|
+
</div>
|
184
|
+
|
185
|
+
</li>
|
186
|
+
|
187
|
+
</ul>
|
188
|
+
|
189
|
+
<p class="tag_title">Returns:</p>
|
190
|
+
<ul class="return">
|
191
|
+
|
192
|
+
<li>
|
193
|
+
|
194
|
+
|
195
|
+
<span class='type'></span>
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
|
200
|
+
<div class='inline'>
|
201
|
+
<p>the injected dependency in the Dependo::Registry with the given name</p>
|
202
|
+
</div>
|
203
|
+
|
204
|
+
</li>
|
205
|
+
|
206
|
+
</ul>
|
207
|
+
<p class="tag_title">Raises:</p>
|
208
|
+
<ul class="raise">
|
209
|
+
|
210
|
+
<li>
|
211
|
+
|
212
|
+
|
213
|
+
<span class='type'></span>
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
<div class='inline'>
|
219
|
+
<p>NoMethodError if the name is not registered</p>
|
220
|
+
</div>
|
221
|
+
|
222
|
+
</li>
|
223
|
+
|
224
|
+
</ul>
|
225
|
+
|
226
|
+
</div><table class="source_code">
|
227
|
+
<tr>
|
228
|
+
<td>
|
229
|
+
<pre class="lines">
|
230
|
+
|
231
|
+
|
232
|
+
46
|
233
|
+
47
|
234
|
+
48
|
235
|
+
49
|
236
|
+
50
|
237
|
+
51
|
238
|
+
52</pre>
|
239
|
+
</td>
|
240
|
+
<td>
|
241
|
+
<pre class="code"><span class="info file"># File 'lib/dependo.rb', line 46</span>
|
242
|
+
|
243
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_method_missing'>method_missing</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
|
244
|
+
<span class='kw'>if</span> <span class='const'>Dependo</span><span class='op'>::</span><span class='const'>Registry</span><span class='period'>.</span><span class='id identifier rubyid_has_key?'>has_key?</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
|
245
|
+
<span class='const'>Dependo</span><span class='op'>::</span><span class='const'>Registry</span><span class='lbracket'>[</span><span class='id identifier rubyid_key'>key</span><span class='rbracket'>]</span>
|
246
|
+
<span class='kw'>else</span>
|
247
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>NoMethodError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>undefined method '</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rbrace'>}</span><span class='tstring_content'>' for </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rbrace'>}</span><span class='tstring_end'>"</span></span>
|
248
|
+
<span class='kw'>end</span>
|
249
|
+
<span class='kw'>end</span></pre>
|
250
|
+
</td>
|
251
|
+
</tr>
|
252
|
+
</table>
|
253
|
+
</div>
|
254
|
+
|
255
|
+
</div>
|
256
|
+
|
257
|
+
|
258
|
+
</div>
|
259
|
+
|
260
|
+
<div id="footer">
|
261
|
+
Generated on Thu Oct 25 14:04:32 2012 by
|
262
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
263
|
+
0.8.2.1 (ruby-1.9.3).
|
264
|
+
</div>
|
265
|
+
|
266
|
+
</body>
|
267
|
+
</html>
|