needle-extras 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,180 @@
1
+ <html>
2
+ <head>
3
+ <title>Needle-Extras Manual :: Chapter 2: AttrInject</title>
4
+ <link type="text/css" rel="stylesheet" href="manual.css" />
5
+ </head>
6
+
7
+ <body>
8
+ <div id="banner">
9
+ <table border='0' cellpadding='0' cellspacing='0' width='100%'>
10
+ <tr><td valign='top' align='left'>
11
+ <div class="title">
12
+ <span class="product">Needle-Extras&mdash;</span><br />
13
+ <span class="tagline">for all your needle needs</span>
14
+ </div>
15
+ </td><td valign='middle' align='right'>
16
+ <div class="info">
17
+ Needle-Extras Version: <strong>1.0.0</strong><br />
18
+ Manual Last Updated: <strong>2004-11-18 19:20 GMT</strong>
19
+ </div>
20
+ </td></tr>
21
+ </table>
22
+ </div>
23
+
24
+ <table border='0' width='100%' cellpadding='0' cellspacing='0'>
25
+ <tr><td valign='top'>
26
+
27
+ <div id="navigation">
28
+ <h1>Needle-Extras Manual</h1>
29
+
30
+ <h2>Chapters</h2>
31
+ <ol type="I">
32
+
33
+ <li>
34
+ <a href="chapter-1.html">
35
+ Introduction
36
+ </a>
37
+
38
+ <ol type="1">
39
+
40
+ <li><a href="chapter-1.html#s1">What is Needle-Extras?</a></li>
41
+
42
+ <li><a href="chapter-1.html#s2">How Do I Use It?</a></li>
43
+
44
+ <li><a href="chapter-1.html#s3">License Information</a></li>
45
+
46
+ <li><a href="chapter-1.html#s4">Support</a></li>
47
+
48
+ </ol>
49
+ </li>
50
+
51
+ <li><strong>
52
+ <a href="chapter-2.html">
53
+ AttrInject
54
+ </a>
55
+ </strong> <big>&larr;</big>
56
+ <ol type="1">
57
+
58
+ <li><a href="chapter-2.html#s1">Overview</a></li>
59
+
60
+ <li><a href="chapter-2.html#s2">Usage</a></li>
61
+
62
+ </ol>
63
+ </li>
64
+
65
+ <li>
66
+ <a href="chapter-3.html">
67
+ Multicast
68
+ </a>
69
+
70
+ <ol type="1">
71
+
72
+ <li><a href="chapter-3.html#s1">Overview</a></li>
73
+
74
+ <li><a href="chapter-3.html#s2">Usage</a></li>
75
+
76
+ </ol>
77
+ </li>
78
+
79
+ <li>
80
+ <a href="chapter-4.html">
81
+ RequireLibrary
82
+ </a>
83
+
84
+ <ol type="1">
85
+
86
+ <li><a href="chapter-4.html#s1">Overview</a></li>
87
+
88
+ <li><a href="chapter-4.html#s2">Usage</a></li>
89
+
90
+ </ol>
91
+ </li>
92
+
93
+ </ol>
94
+
95
+ <h2>Other Documentation</h2>
96
+
97
+ <ul>
98
+ <li><a href="http://needle.rubyforge.org/extras/api/index.html">Needle-Extras API</a></li>
99
+ </ul>
100
+
101
+ <div class="license">
102
+ <a href="http://creativecommons.org/licenses/by-sa/2.0/"><img alt="Creative Commons License" border="0" src="http://creativecommons.org/images/public/somerights" /></a><br />
103
+ This manual is licensed under a <a href="http://creativecommons.org/licenses/by-sa/2.0/">Creative Commons License</a>.
104
+ </div>
105
+ </div>
106
+
107
+ </td><td valign='top' width="100%">
108
+
109
+ <div id="content">
110
+
111
+ <h1>2. AttrInject</h1>
112
+
113
+
114
+
115
+ <h2>
116
+ <a name="s1"></a>
117
+ 2.1. Overview
118
+ </h2>
119
+
120
+
121
+
122
+ <div class="section">
123
+ <p>AttrInject is an implementation of dependency injection that uses declared interfaces to determine dependencies. It is based on an implementation by Christian Neukirchen at <a href="http://rafb.net/paste/results/sexpfu84.html">http://rafb.net/paste/results/sexpfu84.html</a>.</p>
124
+ </div>
125
+
126
+
127
+
128
+ <h2>
129
+ <a name="s2"></a>
130
+ 2.2. Usage
131
+ </h2>
132
+
133
+
134
+
135
+ <div class="section">
136
+ <p>AttrInject is very straightforward to use. Just require the AttrInject library in every service implementation and use the new <code>attr_inject</code> macro to specify which other services the class depends on:</p>
137
+
138
+
139
+ <pre>
140
+ require 'needle/extras/attr-inject'
141
+
142
+ class Foo
143
+ attr_inject :bar
144
+ attr_inject :baz, :blah
145
+
146
+ def frobnicate
147
+ @bar + @baz / @blah
148
+ end
149
+ end
150
+ </pre>
151
+ <p>The <code>attr_inject</code> macro does not create any accessors&#8212;it only declares the dependencies that the corresponding service has. Then, when you register the service, you specify one of the <code>inject</code> service models:</p>
152
+
153
+
154
+ <pre>
155
+ require 'needle'
156
+ require 'needle/extras'
157
+ ...
158
+ reg.require_library 'needle/extras'
159
+ reg.define do |b|
160
+ b.bar { 5 }
161
+ b.baz { 10 }
162
+ b.blah { Math::PI }
163
+
164
+ b.foo( :model =&gt; :singleton_inject ) { Foo.new }
165
+ end
166
+ </pre>
167
+ <p>The <code>singleton_inject</code> service model is just like <code>singleton</code>, but it will also automatically inject all of the declared dependencies into the new service. Thus, invoking <code>#frobnicate</code> on the <code>foo</code> service would compute and return (in this case) <code>5 + 10 / PI</code>.</p>
168
+
169
+ <p>This approach has the benefit of reducing the amount of initialization code you have to write. On the other hand, it more tightly couples your implementation code to Needle itself.</p>
170
+ </div>
171
+
172
+
173
+
174
+
175
+ </div>
176
+
177
+ </td></tr>
178
+ </table>
179
+ </body>
180
+ </html>
@@ -0,0 +1,168 @@
1
+ <html>
2
+ <head>
3
+ <title>Needle-Extras Manual :: Chapter 3: Multicast</title>
4
+ <link type="text/css" rel="stylesheet" href="manual.css" />
5
+ </head>
6
+
7
+ <body>
8
+ <div id="banner">
9
+ <table border='0' cellpadding='0' cellspacing='0' width='100%'>
10
+ <tr><td valign='top' align='left'>
11
+ <div class="title">
12
+ <span class="product">Needle-Extras&mdash;</span><br />
13
+ <span class="tagline">for all your needle needs</span>
14
+ </div>
15
+ </td><td valign='middle' align='right'>
16
+ <div class="info">
17
+ Needle-Extras Version: <strong>1.0.0</strong><br />
18
+ Manual Last Updated: <strong>2004-11-18 19:20 GMT</strong>
19
+ </div>
20
+ </td></tr>
21
+ </table>
22
+ </div>
23
+
24
+ <table border='0' width='100%' cellpadding='0' cellspacing='0'>
25
+ <tr><td valign='top'>
26
+
27
+ <div id="navigation">
28
+ <h1>Needle-Extras Manual</h1>
29
+
30
+ <h2>Chapters</h2>
31
+ <ol type="I">
32
+
33
+ <li>
34
+ <a href="chapter-1.html">
35
+ Introduction
36
+ </a>
37
+
38
+ <ol type="1">
39
+
40
+ <li><a href="chapter-1.html#s1">What is Needle-Extras?</a></li>
41
+
42
+ <li><a href="chapter-1.html#s2">How Do I Use It?</a></li>
43
+
44
+ <li><a href="chapter-1.html#s3">License Information</a></li>
45
+
46
+ <li><a href="chapter-1.html#s4">Support</a></li>
47
+
48
+ </ol>
49
+ </li>
50
+
51
+ <li>
52
+ <a href="chapter-2.html">
53
+ AttrInject
54
+ </a>
55
+
56
+ <ol type="1">
57
+
58
+ <li><a href="chapter-2.html#s1">Overview</a></li>
59
+
60
+ <li><a href="chapter-2.html#s2">Usage</a></li>
61
+
62
+ </ol>
63
+ </li>
64
+
65
+ <li><strong>
66
+ <a href="chapter-3.html">
67
+ Multicast
68
+ </a>
69
+ </strong> <big>&larr;</big>
70
+ <ol type="1">
71
+
72
+ <li><a href="chapter-3.html#s1">Overview</a></li>
73
+
74
+ <li><a href="chapter-3.html#s2">Usage</a></li>
75
+
76
+ </ol>
77
+ </li>
78
+
79
+ <li>
80
+ <a href="chapter-4.html">
81
+ RequireLibrary
82
+ </a>
83
+
84
+ <ol type="1">
85
+
86
+ <li><a href="chapter-4.html#s1">Overview</a></li>
87
+
88
+ <li><a href="chapter-4.html#s2">Usage</a></li>
89
+
90
+ </ol>
91
+ </li>
92
+
93
+ </ol>
94
+
95
+ <h2>Other Documentation</h2>
96
+
97
+ <ul>
98
+ <li><a href="http://needle.rubyforge.org/extras/api/index.html">Needle-Extras API</a></li>
99
+ </ul>
100
+
101
+ <div class="license">
102
+ <a href="http://creativecommons.org/licenses/by-sa/2.0/"><img alt="Creative Commons License" border="0" src="http://creativecommons.org/images/public/somerights" /></a><br />
103
+ This manual is licensed under a <a href="http://creativecommons.org/licenses/by-sa/2.0/">Creative Commons License</a>.
104
+ </div>
105
+ </div>
106
+
107
+ </td><td valign='top' width="100%">
108
+
109
+ <div id="content">
110
+
111
+ <h1>3. Multicast</h1>
112
+
113
+
114
+
115
+ <h2>
116
+ <a name="s1"></a>
117
+ 3.1. Overview
118
+ </h2>
119
+
120
+
121
+
122
+ <div class="section">
123
+ <p>The multicast service allows you to easily broadcast messages to a specified set of objects. It is, in essence, a kind of observer pattern, with t he observers being given to the multicaster when it is created. Events are then sent to the observers by invoking methods on the multicaster.</p>
124
+ </div>
125
+
126
+
127
+
128
+ <h2>
129
+ <a name="s2"></a>
130
+ 3.2. Usage
131
+ </h2>
132
+
133
+
134
+
135
+ <div class="section">
136
+ <p>The multicast service is parameterized. Just send it a list of objects (i.e., other services) that you want multicasted to, and it will return a new multicaster object.</p>
137
+
138
+
139
+ <pre>
140
+ reg = Needle::Registry.define do |b|
141
+ b.require 'needle/extras/multicast', 'Needle::Extras::Multicast'
142
+
143
+ b.foo { "hello" }
144
+ b.bar { [ 1, 2, 3 ] }
145
+ b.baz { "test" }
146
+
147
+ b.multicaster { |c,| c.multicast c.foo, c.bar, c.baz }
148
+ end
149
+ </pre>
150
+ <p>Once you&#8217;ve registered your service, you can send messages to the observing services by sending messages to the multicaster:</p>
151
+
152
+
153
+ <pre>
154
+ m = reg.multicaster
155
+ p m.length #-&gt; [ 5, 3, 4 ]
156
+ </pre>
157
+ <p>The multicaster will return an array of the return values of all of the observing services. Thus, in the above example, an array of the lengths of each of the <code>foo</code>, <code>bar</code>, and <code>baz</code> services is returned.</p>
158
+ </div>
159
+
160
+
161
+
162
+
163
+ </div>
164
+
165
+ </td></tr>
166
+ </table>
167
+ </body>
168
+ </html>
@@ -0,0 +1,184 @@
1
+ <html>
2
+ <head>
3
+ <title>Needle-Extras Manual :: Chapter 4: RequireLibrary</title>
4
+ <link type="text/css" rel="stylesheet" href="manual.css" />
5
+ </head>
6
+
7
+ <body>
8
+ <div id="banner">
9
+ <table border='0' cellpadding='0' cellspacing='0' width='100%'>
10
+ <tr><td valign='top' align='left'>
11
+ <div class="title">
12
+ <span class="product">Needle-Extras&mdash;</span><br />
13
+ <span class="tagline">for all your needle needs</span>
14
+ </div>
15
+ </td><td valign='middle' align='right'>
16
+ <div class="info">
17
+ Needle-Extras Version: <strong>1.0.0</strong><br />
18
+ Manual Last Updated: <strong>2004-11-18 19:20 GMT</strong>
19
+ </div>
20
+ </td></tr>
21
+ </table>
22
+ </div>
23
+
24
+ <table border='0' width='100%' cellpadding='0' cellspacing='0'>
25
+ <tr><td valign='top'>
26
+
27
+ <div id="navigation">
28
+ <h1>Needle-Extras Manual</h1>
29
+
30
+ <h2>Chapters</h2>
31
+ <ol type="I">
32
+
33
+ <li>
34
+ <a href="chapter-1.html">
35
+ Introduction
36
+ </a>
37
+
38
+ <ol type="1">
39
+
40
+ <li><a href="chapter-1.html#s1">What is Needle-Extras?</a></li>
41
+
42
+ <li><a href="chapter-1.html#s2">How Do I Use It?</a></li>
43
+
44
+ <li><a href="chapter-1.html#s3">License Information</a></li>
45
+
46
+ <li><a href="chapter-1.html#s4">Support</a></li>
47
+
48
+ </ol>
49
+ </li>
50
+
51
+ <li>
52
+ <a href="chapter-2.html">
53
+ AttrInject
54
+ </a>
55
+
56
+ <ol type="1">
57
+
58
+ <li><a href="chapter-2.html#s1">Overview</a></li>
59
+
60
+ <li><a href="chapter-2.html#s2">Usage</a></li>
61
+
62
+ </ol>
63
+ </li>
64
+
65
+ <li>
66
+ <a href="chapter-3.html">
67
+ Multicast
68
+ </a>
69
+
70
+ <ol type="1">
71
+
72
+ <li><a href="chapter-3.html#s1">Overview</a></li>
73
+
74
+ <li><a href="chapter-3.html#s2">Usage</a></li>
75
+
76
+ </ol>
77
+ </li>
78
+
79
+ <li><strong>
80
+ <a href="chapter-4.html">
81
+ RequireLibrary
82
+ </a>
83
+ </strong> <big>&larr;</big>
84
+ <ol type="1">
85
+
86
+ <li><a href="chapter-4.html#s1">Overview</a></li>
87
+
88
+ <li><a href="chapter-4.html#s2">Usage</a></li>
89
+
90
+ </ol>
91
+ </li>
92
+
93
+ </ol>
94
+
95
+ <h2>Other Documentation</h2>
96
+
97
+ <ul>
98
+ <li><a href="http://needle.rubyforge.org/extras/api/index.html">Needle-Extras API</a></li>
99
+ </ul>
100
+
101
+ <div class="license">
102
+ <a href="http://creativecommons.org/licenses/by-sa/2.0/"><img alt="Creative Commons License" border="0" src="http://creativecommons.org/images/public/somerights" /></a><br />
103
+ This manual is licensed under a <a href="http://creativecommons.org/licenses/by-sa/2.0/">Creative Commons License</a>.
104
+ </div>
105
+ </div>
106
+
107
+ </td><td valign='top' width="100%">
108
+
109
+ <div id="content">
110
+
111
+ <h1>4. RequireLibrary</h1>
112
+
113
+
114
+
115
+ <h2>
116
+ <a name="s1"></a>
117
+ 4.1. Overview
118
+ </h2>
119
+
120
+
121
+
122
+ <div class="section">
123
+ <p>RequireLibrary is not a service&#8212;it is a mini-framework for registering service libraries with Needle so that they can be imported into other projects with a minimum of headache.</p>
124
+
125
+ <p>Currently, Needle supports <code>Container#require</code> as the library import mechanism. This requires you to specify both the file containing the service registration method, as well as the Module that contains the method.</p>
126
+
127
+ <p>RequireLibrary takes some of the duplication out of the process by allowing application developers to register a callback hook with Needle, which will be invoked when the new <code>Container#require_library</code> method is invoked.</p>
128
+ </div>
129
+
130
+
131
+
132
+ <h2>
133
+ <a name="s2"></a>
134
+ 4.2. Usage
135
+ </h2>
136
+
137
+
138
+
139
+ <div class="section">
140
+ <p>For developers of service libraries, RequireLibrary provides a hook for registering their libraries with Needle:</p>
141
+
142
+
143
+ <pre>
144
+ module Foo
145
+ module Bar
146
+
147
+ def register_services( container )
148
+ ...
149
+ end
150
+ module_function :register_services
151
+
152
+ if defined?(Needle.register_library)
153
+ Needle.register_library( 'foo/bar', self )
154
+ end
155
+
156
+ end
157
+ end
158
+ </pre>
159
+ <p>The <code>#register_services</code> method is Needle&#8217;s standard callback for registering a library&#8217;s services with the given container.</p>
160
+
161
+ <p>The next lines, though, check to see if <code>Needle.register_library</code> is defined. This allows the library to be used even when Needle-Extras is not loaded, or even installed. If the method exists, it is invoked with the <code>require</code> path of the file, and the module reference that contains the <code>#register_services</code> method.</p>
162
+
163
+ <p>Then, consumers of the library can load it using RequireLibrary as follows:</p>
164
+
165
+
166
+ <pre>
167
+ require 'needle'
168
+
169
+ reg = Needle::Registry.new
170
+ reg.require_library 'foo/bar'
171
+ ...
172
+ </pre>
173
+ <p>The call to <code>Container#require_library</code> invokes <code>Kernel#require</code>, and then looks to see if there is a hook registered for the <code>'foo/bar'</code> path. If there is, the hook is invoked, which (by default) invokes the <code>#register_services</code> method, passing the current container as the parameter.</p>
174
+ </div>
175
+
176
+
177
+
178
+
179
+ </div>
180
+
181
+ </td></tr>
182
+ </table>
183
+ </body>
184
+ </html>