solid_callback 1.0.0 → 2.0.1
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.
- checksums.yaml +4 -4
- data/Gemfile +5 -0
- data/Gemfile.lock +2 -2
- data/README.md +6 -6
- data/doc/SolidCallback/Core.html +655 -0
- data/doc/SolidCallback/Error.html +124 -0
- data/doc/SolidCallback/Hooks.html +453 -0
- data/doc/SolidCallback/MethodWrapper.html +105 -0
- data/doc/SolidCallback.html +253 -0
- data/doc/_index.html +167 -0
- data/doc/class_list.html +54 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +503 -0
- data/doc/file.README.html +297 -0
- data/doc/file_list.html +59 -0
- data/doc/frames.html +22 -0
- data/doc/index.html +297 -0
- data/doc/js/app.js +344 -0
- data/doc/js/full_list.js +242 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +150 -0
- data/doc/top-level-namespace.html +110 -0
- data/lib/solid_callback/version.rb +1 -1
- metadata +24 -9
data/doc/index.html
ADDED
@@ -0,0 +1,297 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
File: README
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.37
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
pathId = "README";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index</a> »
|
40
|
+
<span class="title">File: README</span>
|
41
|
+
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<div id="search">
|
45
|
+
|
46
|
+
<a class="full_list_link" id="class_list_link"
|
47
|
+
href="class_list.html">
|
48
|
+
|
49
|
+
<svg width="24" height="24">
|
50
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
51
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
52
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
</svg>
|
54
|
+
</a>
|
55
|
+
|
56
|
+
</div>
|
57
|
+
<div class="clear"></div>
|
58
|
+
</div>
|
59
|
+
|
60
|
+
<div id="content"><div id='filecontents'>
|
61
|
+
<h1 id="label-SolidCallback">SolidCallback</h1>
|
62
|
+
|
63
|
+
<p><a href="https://badge.fury.io/rb/solid_callback"><img src="https://badge.fury.io/rb/solid_callback.svg"></a> <a href="https://github.com/gklsan/solid_callback/actions/workflows/ruby.yml"><img src="https://github.com/gklsan/solid_callback/actions/workflows/ruby.yml/badge.svg"></a> <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg"></a></p>
|
64
|
+
|
65
|
+
<p>SolidCallback adds powerful method interception capabilities to your Ruby classes with near-zero overhead. Clean, flexible, and unobtrusive.</p>
|
66
|
+
|
67
|
+
<h2 id="label-Features">Features</h2>
|
68
|
+
<ul><li>
|
69
|
+
<p>🔄 <strong>Method Lifecycle Hooks</strong>: <code>before_call</code>, <code>after_call</code>, and <code>around_call</code> - intercept methods without modifying their code</p>
|
70
|
+
</li><li>
|
71
|
+
<p>🧩 <strong>Zero-coupling</strong>: Keep your business logic and cross-cutting concerns separate</p>
|
72
|
+
</li><li>
|
73
|
+
<p>🔍 <strong>Selective targeting</strong>: Apply callbacks to specific methods or all methods</p>
|
74
|
+
</li><li>
|
75
|
+
<p>⚡ <strong>Performance-focused</strong>: Minimal overhead through efficient method wrapping</p>
|
76
|
+
</li><li>
|
77
|
+
<p>🔒 <strong>Thread-safe</strong>: Safely use in concurrent applications</p>
|
78
|
+
</li><li>
|
79
|
+
<p>📝 <strong>Conditional execution</strong>: Run callbacks only when specific conditions are met</p>
|
80
|
+
</li></ul>
|
81
|
+
|
82
|
+
<h2 id="label-Installation">Installation</h2>
|
83
|
+
|
84
|
+
<p>Add this line to your application’s Gemfile:</p>
|
85
|
+
|
86
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>solid_callback</span><span class='tstring_end'>'</span></span>
|
87
|
+
</code></pre>
|
88
|
+
|
89
|
+
<p>And then execute:</p>
|
90
|
+
|
91
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_install'>install</span>
|
92
|
+
</code></pre>
|
93
|
+
|
94
|
+
<p>Or install it yourself:</p>
|
95
|
+
|
96
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='id identifier rubyid_install'>install</span> <span class='id identifier rubyid_solid_callback'>solid_callback</span>
|
97
|
+
</code></pre>
|
98
|
+
|
99
|
+
<h2 id="label-Usage">Usage</h2>
|
100
|
+
|
101
|
+
<h3 id="label-Basic+Example">Basic Example</h3>
|
102
|
+
|
103
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>solid_callback</span><span class='tstring_end'>'</span></span>
|
104
|
+
|
105
|
+
<span class='kw'>class</span> <span class='const'>UserService</span>
|
106
|
+
<span class='id identifier rubyid_include'>include</span> <span class='const'><span class='object_link'><a href="SolidCallback.html" title="SolidCallback (module)">SolidCallback</a></span></span>
|
107
|
+
|
108
|
+
<span class='id identifier rubyid_before_call'>before_call</span> <span class='symbol'>:authenticate</span>
|
109
|
+
<span class='id identifier rubyid_after_call'>after_call</span> <span class='symbol'>:log_activity</span>
|
110
|
+
<span class='id identifier rubyid_around_call'>around_call</span> <span class='symbol'>:measure_performance</span>
|
111
|
+
|
112
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_find_user'>find_user</span><span class='lparen'>(</span><span class='id identifier rubyid_id'>id</span><span class='rparen'>)</span>
|
113
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Finding user with ID: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_id'>id</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
114
|
+
<span class='lbrace'>{</span> <span class='label'>id:</span> <span class='id identifier rubyid_id'>id</span><span class='comma'>,</span> <span class='label'>name:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>User </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_id'>id</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
|
115
|
+
<span class='kw'>end</span>
|
116
|
+
|
117
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_update_user'>update_user</span><span class='lparen'>(</span><span class='id identifier rubyid_id'>id</span><span class='comma'>,</span> <span class='id identifier rubyid_attributes'>attributes</span><span class='rparen'>)</span>
|
118
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Updating user </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_id'>id</span><span class='embexpr_end'>}</span><span class='tstring_content'> with </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_attributes'>attributes</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
119
|
+
<span class='lbrace'>{</span> <span class='label'>id:</span> <span class='id identifier rubyid_id'>id</span><span class='comma'>,</span> <span class='label'>updated:</span> <span class='kw'>true</span> <span class='rbrace'>}</span>
|
120
|
+
<span class='kw'>end</span>
|
121
|
+
|
122
|
+
<span class='id identifier rubyid_private'>private</span>
|
123
|
+
|
124
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_authenticate'>authenticate</span>
|
125
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>🔐 Authenticating request</span><span class='tstring_end'>"</span></span>
|
126
|
+
<span class='kw'>end</span>
|
127
|
+
|
128
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_log_activity'>log_activity</span>
|
129
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>📝 Logging activity</span><span class='tstring_end'>"</span></span>
|
130
|
+
<span class='kw'>end</span>
|
131
|
+
|
132
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_measure_performance'>measure_performance</span>
|
133
|
+
<span class='id identifier rubyid_start_time'>start_time</span> <span class='op'>=</span> <span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_now'>now</span>
|
134
|
+
<span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='kw'>yield</span> <span class='comment'># Execute the original method
|
135
|
+
</span> <span class='id identifier rubyid_duration'>duration</span> <span class='op'>=</span> <span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_now'>now</span> <span class='op'>-</span> <span class='id identifier rubyid_start_time'>start_time</span>
|
136
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>⏱️ Method took </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_duration'>duration</span><span class='embexpr_end'>}</span><span class='tstring_content'> seconds</span><span class='tstring_end'>"</span></span>
|
137
|
+
<span class='id identifier rubyid_result'>result</span> <span class='comment'># Return the original result
|
138
|
+
</span> <span class='kw'>end</span>
|
139
|
+
<span class='kw'>end</span>
|
140
|
+
|
141
|
+
<span class='id identifier rubyid_service'>service</span> <span class='op'>=</span> <span class='const'>UserService</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
142
|
+
<span class='id identifier rubyid_service'>service</span><span class='period'>.</span><span class='id identifier rubyid_find_user'>find_user</span><span class='lparen'>(</span><span class='int'>42</span><span class='rparen'>)</span>
|
143
|
+
</code></pre>
|
144
|
+
|
145
|
+
<h3 id="label-Advanced+Usage">Advanced Usage</h3>
|
146
|
+
|
147
|
+
<p>Apply callbacks to specific methods:</p>
|
148
|
+
|
149
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>PaymentProcessor</span>
|
150
|
+
<span class='id identifier rubyid_include'>include</span> <span class='const'><span class='object_link'><a href="SolidCallback.html" title="SolidCallback (module)">SolidCallback</a></span></span>
|
151
|
+
|
152
|
+
<span class='id identifier rubyid_before_call'>before_call</span> <span class='symbol'>:validate_amount</span><span class='comma'>,</span> <span class='label'>only:</span> <span class='lbracket'>[</span><span class='symbol'>:charge</span><span class='comma'>,</span> <span class='symbol'>:refund</span><span class='rbracket'>]</span>
|
153
|
+
<span class='id identifier rubyid_after_call'>after_call</span> <span class='symbol'>:send_receipt</span><span class='comma'>,</span> <span class='label'>only:</span> <span class='lbracket'>[</span><span class='symbol'>:charge</span><span class='rbracket'>]</span>
|
154
|
+
<span class='id identifier rubyid_after_call'>after_call</span> <span class='symbol'>:notify_fraud_department</span><span class='comma'>,</span> <span class='label'>only:</span> <span class='lbracket'>[</span><span class='symbol'>:flag_suspicious</span><span class='rbracket'>]</span>
|
155
|
+
<span class='id identifier rubyid_around_call'>around_call</span> <span class='symbol'>:transaction</span><span class='comma'>,</span> <span class='label'>only:</span> <span class='lbracket'>[</span><span class='symbol'>:charge</span><span class='comma'>,</span> <span class='symbol'>:refund</span><span class='rbracket'>]</span>
|
156
|
+
|
157
|
+
<span class='comment'># Rest of class...
|
158
|
+
</span><span class='kw'>end</span>
|
159
|
+
</code></pre>
|
160
|
+
|
161
|
+
<p>Use conditional callbacks:</p>
|
162
|
+
|
163
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>DocumentProcessor</span>
|
164
|
+
<span class='id identifier rubyid_include'>include</span> <span class='const'><span class='object_link'><a href="SolidCallback.html" title="SolidCallback (module)">SolidCallback</a></span></span>
|
165
|
+
|
166
|
+
<span class='id identifier rubyid_attr_reader'>attr_reader</span> <span class='symbol'>:document_size</span>
|
167
|
+
|
168
|
+
<span class='id identifier rubyid_before_call'>before_call</span> <span class='symbol'>:check_permissions</span>
|
169
|
+
<span class='id identifier rubyid_before_call'>before_call</span> <span class='symbol'>:backup_document</span><span class='comma'>,</span> <span class='label'>if:</span> <span class='symbol'>:large_document?</span>
|
170
|
+
<span class='id identifier rubyid_around_call'>around_call</span> <span class='symbol'>:with_retry</span><span class='comma'>,</span> <span class='label'>unless:</span> <span class='symbol'>:read_only?</span>
|
171
|
+
|
172
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_process_document'>process_document</span><span class='lparen'>(</span><span class='id identifier rubyid_doc'>doc</span><span class='rparen'>)</span>
|
173
|
+
<span class='comment'># Implementation...
|
174
|
+
</span> <span class='kw'>end</span>
|
175
|
+
|
176
|
+
<span class='id identifier rubyid_private'>private</span>
|
177
|
+
|
178
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_large_document?'>large_document?</span>
|
179
|
+
<span class='ivar'>@document_size</span> <span class='op'>></span> <span class='int'>10_000</span>
|
180
|
+
<span class='kw'>end</span>
|
181
|
+
|
182
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_read_only?'>read_only?</span>
|
183
|
+
<span class='comment'># Some condition
|
184
|
+
</span> <span class='kw'>end</span>
|
185
|
+
<span class='kw'>end</span>
|
186
|
+
</code></pre>
|
187
|
+
|
188
|
+
<p>You can even use procs for conditions:</p>
|
189
|
+
|
190
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_before_call'>before_call</span> <span class='symbol'>:notify_admin</span><span class='comma'>,</span> <span class='label'>if:</span> <span class='tlambda'>-></span> <span class='tlambeg'>{</span> <span class='const'>Rails</span><span class='period'>.</span><span class='id identifier rubyid_env'>env</span><span class='period'>.</span><span class='id identifier rubyid_production?'>production?</span> <span class='rbrace'>}</span>
|
191
|
+
</code></pre>
|
192
|
+
|
193
|
+
<h3 id="label-Skipping+Callbacks">Skipping Callbacks</h3>
|
194
|
+
|
195
|
+
<p>Skip callbacks for specific methods:</p>
|
196
|
+
|
197
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>ApiService</span>
|
198
|
+
<span class='id identifier rubyid_include'>include</span> <span class='const'><span class='object_link'><a href="SolidCallback.html" title="SolidCallback (module)">SolidCallback</a></span></span>
|
199
|
+
|
200
|
+
<span class='id identifier rubyid_before_call'>before_call</span> <span class='symbol'>:rate_limit</span>
|
201
|
+
|
202
|
+
<span class='id identifier rubyid_skip_callbacks_for'>skip_callbacks_for</span> <span class='symbol'>:health_check</span>
|
203
|
+
|
204
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_get_data'>get_data</span>
|
205
|
+
<span class='comment'># Implementation...
|
206
|
+
</span> <span class='kw'>end</span>
|
207
|
+
|
208
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_health_check'>health_check</span>
|
209
|
+
<span class='comment'># This method won't trigger the rate_limit callback
|
210
|
+
</span> <span class='lbrace'>{</span> <span class='label'>status:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>ok</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
|
211
|
+
<span class='kw'>end</span>
|
212
|
+
<span class='kw'>end</span>
|
213
|
+
</code></pre>
|
214
|
+
|
215
|
+
<h2 id="label-Callback+Options">Callback Options</h2>
|
216
|
+
|
217
|
+
<p>Each callback method accepts the following options:</p>
|
218
|
+
|
219
|
+
<table role="table">
|
220
|
+
<thead>
|
221
|
+
<tr>
|
222
|
+
<th>Option</th>
|
223
|
+
<th>Description</th>
|
224
|
+
</tr>
|
225
|
+
</thead>
|
226
|
+
<tbody>
|
227
|
+
<tr>
|
228
|
+
<td>‘only`</td>
|
229
|
+
<td>Array of method names to which the callback applies</td>
|
230
|
+
</tr>
|
231
|
+
<tr>
|
232
|
+
<td>‘except`</td>
|
233
|
+
<td>Array of method names to which the callback does not apply</td>
|
234
|
+
</tr>
|
235
|
+
<tr>
|
236
|
+
<td>‘if`</td>
|
237
|
+
<td>Symbol (method name) or Proc that must return true for the callback to run</td>
|
238
|
+
</tr>
|
239
|
+
<tr>
|
240
|
+
<td>‘unless`</td>
|
241
|
+
<td>Symbol (method name) or Proc that must return false for the callback to run</td>
|
242
|
+
</tr>
|
243
|
+
</tbody>
|
244
|
+
</table>
|
245
|
+
|
246
|
+
<h2 id="label-How+It+Works">How It Works</h2>
|
247
|
+
|
248
|
+
<p>Callbacker uses Ruby’s metaprogramming to wrap your methods with callback functionality:</p>
|
249
|
+
<ol><li>
|
250
|
+
<p>When included, it extends your class with callback registration methods</p>
|
251
|
+
</li><li>
|
252
|
+
<p>When a callback is registered, it stores the configuration</p>
|
253
|
+
</li><li>
|
254
|
+
<p>When a method is defined, it wraps the method with callback handling code</p>
|
255
|
+
</li><li>
|
256
|
+
<p>When the method is called, it executes the callbacks in the proper order</p>
|
257
|
+
</li></ol>
|
258
|
+
|
259
|
+
<h2 id="label-F0-9F-93-9A+Use+Cases">📚 Use Cases</h2>
|
260
|
+
<ul><li>
|
261
|
+
<p>Authentication & Authorization</p>
|
262
|
+
</li><li>
|
263
|
+
<p>Logging & Monitoring</p>
|
264
|
+
</li><li>
|
265
|
+
<p>Caching</p>
|
266
|
+
</li><li>
|
267
|
+
<p>Performance measurement</p>
|
268
|
+
</li><li>
|
269
|
+
<p>Error handling</p>
|
270
|
+
</li><li>
|
271
|
+
<p>Background job retries</p>
|
272
|
+
</li><li>
|
273
|
+
<p>Transaction management</p>
|
274
|
+
</li><li>
|
275
|
+
<p>Input validation</p>
|
276
|
+
</li><li>
|
277
|
+
<p>Data transformation</p>
|
278
|
+
</li></ul>
|
279
|
+
|
280
|
+
<h2 id="label-F0-9F-A4-9D+Contributing">🤝 Contributing</h2>
|
281
|
+
|
282
|
+
<p>Bug reports and pull requests are welcome on GitHub at <a href="https://github.com/gklsan/solid_callback/issues">github.com/gklsan/solid_callback/issues</a>.</p>
|
283
|
+
|
284
|
+
<h2 id="label-F0-9F-93-84+License">📄 License</h2>
|
285
|
+
|
286
|
+
<p>The gem is available as open source under the terms of the <a href="https://opensource.org/licenses/MIT">MIT License</a>.</p>
|
287
|
+
</div></div>
|
288
|
+
|
289
|
+
<div id="footer">
|
290
|
+
Generated on Wed Mar 12 18:55:58 2025 by
|
291
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
292
|
+
0.9.37 (ruby-3.3.0).
|
293
|
+
</div>
|
294
|
+
|
295
|
+
</div>
|
296
|
+
</body>
|
297
|
+
</html>
|
data/doc/js/app.js
ADDED
@@ -0,0 +1,344 @@
|
|
1
|
+
(function () {
|
2
|
+
var localStorage = {},
|
3
|
+
sessionStorage = {};
|
4
|
+
try {
|
5
|
+
localStorage = window.localStorage;
|
6
|
+
} catch (e) {}
|
7
|
+
try {
|
8
|
+
sessionStorage = window.sessionStorage;
|
9
|
+
} catch (e) {}
|
10
|
+
|
11
|
+
function createSourceLinks() {
|
12
|
+
$(".method_details_list .source_code").before(
|
13
|
+
"<span class='showSource'>[<a href='#' class='toggleSource'>View source</a>]</span>"
|
14
|
+
);
|
15
|
+
$(".toggleSource").toggle(
|
16
|
+
function () {
|
17
|
+
$(this).parent().nextAll(".source_code").slideDown(100);
|
18
|
+
$(this).text("Hide source");
|
19
|
+
},
|
20
|
+
function () {
|
21
|
+
$(this).parent().nextAll(".source_code").slideUp(100);
|
22
|
+
$(this).text("View source");
|
23
|
+
}
|
24
|
+
);
|
25
|
+
}
|
26
|
+
|
27
|
+
function createDefineLinks() {
|
28
|
+
var tHeight = 0;
|
29
|
+
$(".defines").after(" <a href='#' class='toggleDefines'>more...</a>");
|
30
|
+
$(".toggleDefines").toggle(
|
31
|
+
function () {
|
32
|
+
tHeight = $(this).parent().prev().height();
|
33
|
+
$(this).prev().css("display", "inline");
|
34
|
+
$(this).parent().prev().height($(this).parent().height());
|
35
|
+
$(this).text("(less)");
|
36
|
+
},
|
37
|
+
function () {
|
38
|
+
$(this).prev().hide();
|
39
|
+
$(this).parent().prev().height(tHeight);
|
40
|
+
$(this).text("more...");
|
41
|
+
}
|
42
|
+
);
|
43
|
+
}
|
44
|
+
|
45
|
+
function createFullTreeLinks() {
|
46
|
+
var tHeight = 0;
|
47
|
+
$(".inheritanceTree").toggle(
|
48
|
+
function () {
|
49
|
+
tHeight = $(this).parent().prev().height();
|
50
|
+
$(this).parent().toggleClass("showAll");
|
51
|
+
$(this).text("(hide)");
|
52
|
+
$(this).parent().prev().height($(this).parent().height());
|
53
|
+
},
|
54
|
+
function () {
|
55
|
+
$(this).parent().toggleClass("showAll");
|
56
|
+
$(this).parent().prev().height(tHeight);
|
57
|
+
$(this).text("show all");
|
58
|
+
}
|
59
|
+
);
|
60
|
+
}
|
61
|
+
|
62
|
+
function searchFrameButtons() {
|
63
|
+
$(".full_list_link").click(function () {
|
64
|
+
toggleSearchFrame(this, $(this).attr("href"));
|
65
|
+
return false;
|
66
|
+
});
|
67
|
+
window.addEventListener("message", function (e) {
|
68
|
+
if (e.data === "navEscape") {
|
69
|
+
$("#nav").slideUp(100);
|
70
|
+
$("#search a").removeClass("active inactive");
|
71
|
+
$(window).focus();
|
72
|
+
}
|
73
|
+
});
|
74
|
+
|
75
|
+
$(window).resize(function () {
|
76
|
+
if ($("#search:visible").length === 0) {
|
77
|
+
$("#nav").removeAttr("style");
|
78
|
+
$("#search a").removeClass("active inactive");
|
79
|
+
$(window).focus();
|
80
|
+
}
|
81
|
+
});
|
82
|
+
}
|
83
|
+
|
84
|
+
function toggleSearchFrame(id, link) {
|
85
|
+
var frame = $("#nav");
|
86
|
+
$("#search a").removeClass("active").addClass("inactive");
|
87
|
+
if (frame.attr("src") === link && frame.css("display") !== "none") {
|
88
|
+
frame.slideUp(100);
|
89
|
+
$("#search a").removeClass("active inactive");
|
90
|
+
} else {
|
91
|
+
$(id).addClass("active").removeClass("inactive");
|
92
|
+
if (frame.attr("src") !== link) frame.attr("src", link);
|
93
|
+
frame.slideDown(100);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
function linkSummaries() {
|
98
|
+
$(".summary_signature").click(function () {
|
99
|
+
document.location = $(this).find("a").attr("href");
|
100
|
+
});
|
101
|
+
}
|
102
|
+
|
103
|
+
function summaryToggle() {
|
104
|
+
$(".summary_toggle").click(function (e) {
|
105
|
+
e.preventDefault();
|
106
|
+
localStorage.summaryCollapsed = $(this).text();
|
107
|
+
$(".summary_toggle").each(function () {
|
108
|
+
$(this).text($(this).text() == "collapse" ? "expand" : "collapse");
|
109
|
+
var next = $(this).parent().parent().nextAll("ul.summary").first();
|
110
|
+
if (next.hasClass("compact")) {
|
111
|
+
next.toggle();
|
112
|
+
next.nextAll("ul.summary").first().toggle();
|
113
|
+
} else if (next.hasClass("summary")) {
|
114
|
+
var list = $('<ul class="summary compact" />');
|
115
|
+
list.html(next.html());
|
116
|
+
list.find(".summary_desc, .note").remove();
|
117
|
+
list.find("a").each(function () {
|
118
|
+
$(this).html($(this).find("strong").html());
|
119
|
+
$(this).parent().html($(this)[0].outerHTML);
|
120
|
+
});
|
121
|
+
next.before(list);
|
122
|
+
next.toggle();
|
123
|
+
}
|
124
|
+
});
|
125
|
+
return false;
|
126
|
+
});
|
127
|
+
if (localStorage.summaryCollapsed == "collapse") {
|
128
|
+
$(".summary_toggle").first().click();
|
129
|
+
} else {
|
130
|
+
localStorage.summaryCollapsed = "expand";
|
131
|
+
}
|
132
|
+
}
|
133
|
+
|
134
|
+
function constantSummaryToggle() {
|
135
|
+
$(".constants_summary_toggle").click(function (e) {
|
136
|
+
e.preventDefault();
|
137
|
+
localStorage.summaryCollapsed = $(this).text();
|
138
|
+
$(".constants_summary_toggle").each(function () {
|
139
|
+
$(this).text($(this).text() == "collapse" ? "expand" : "collapse");
|
140
|
+
var next = $(this).parent().parent().nextAll("dl.constants").first();
|
141
|
+
if (next.hasClass("compact")) {
|
142
|
+
next.toggle();
|
143
|
+
next.nextAll("dl.constants").first().toggle();
|
144
|
+
} else if (next.hasClass("constants")) {
|
145
|
+
var list = $('<dl class="constants compact" />');
|
146
|
+
list.html(next.html());
|
147
|
+
list.find("dt").each(function () {
|
148
|
+
$(this).addClass("summary_signature");
|
149
|
+
$(this).text($(this).text().split("=")[0]);
|
150
|
+
if ($(this).has(".deprecated").length) {
|
151
|
+
$(this).addClass("deprecated");
|
152
|
+
}
|
153
|
+
});
|
154
|
+
// Add the value of the constant as "Tooltip" to the summary object
|
155
|
+
list.find("pre.code").each(function () {
|
156
|
+
console.log($(this).parent());
|
157
|
+
var dt_element = $(this).parent().prev();
|
158
|
+
var tooltip = $(this).text();
|
159
|
+
if (dt_element.hasClass("deprecated")) {
|
160
|
+
tooltip = "Deprecated. " + tooltip;
|
161
|
+
}
|
162
|
+
dt_element.attr("title", tooltip);
|
163
|
+
});
|
164
|
+
list.find(".docstring, .tags, dd").remove();
|
165
|
+
next.before(list);
|
166
|
+
next.toggle();
|
167
|
+
}
|
168
|
+
});
|
169
|
+
return false;
|
170
|
+
});
|
171
|
+
if (localStorage.summaryCollapsed == "collapse") {
|
172
|
+
$(".constants_summary_toggle").first().click();
|
173
|
+
} else {
|
174
|
+
localStorage.summaryCollapsed = "expand";
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
function generateTOC() {
|
179
|
+
if ($("#filecontents").length === 0) return;
|
180
|
+
var _toc = $('<ol class="top"></ol>');
|
181
|
+
var show = false;
|
182
|
+
var toc = _toc;
|
183
|
+
var counter = 0;
|
184
|
+
var tags = ["h2", "h3", "h4", "h5", "h6"];
|
185
|
+
var i;
|
186
|
+
var curli;
|
187
|
+
if ($("#filecontents h1").length > 1) tags.unshift("h1");
|
188
|
+
for (i = 0; i < tags.length; i++) {
|
189
|
+
tags[i] = "#filecontents " + tags[i];
|
190
|
+
}
|
191
|
+
var lastTag = parseInt(tags[0][1], 10);
|
192
|
+
$(tags.join(", ")).each(function () {
|
193
|
+
if ($(this).parents(".method_details .docstring").length != 0) return;
|
194
|
+
if (this.id == "filecontents") return;
|
195
|
+
show = true;
|
196
|
+
var thisTag = parseInt(this.tagName[1], 10);
|
197
|
+
if (this.id.length === 0) {
|
198
|
+
var proposedId = $(this).attr("toc-id");
|
199
|
+
if (typeof proposedId != "undefined") this.id = proposedId;
|
200
|
+
else {
|
201
|
+
var proposedId = $(this)
|
202
|
+
.text()
|
203
|
+
.replace(/[^a-z0-9-]/gi, "_");
|
204
|
+
if ($("#" + proposedId).length > 0) {
|
205
|
+
proposedId += counter;
|
206
|
+
counter++;
|
207
|
+
}
|
208
|
+
this.id = proposedId;
|
209
|
+
}
|
210
|
+
}
|
211
|
+
if (thisTag > lastTag) {
|
212
|
+
for (i = 0; i < thisTag - lastTag; i++) {
|
213
|
+
if (typeof curli == "undefined") {
|
214
|
+
curli = $("<li/>");
|
215
|
+
toc.append(curli);
|
216
|
+
}
|
217
|
+
toc = $("<ol/>");
|
218
|
+
curli.append(toc);
|
219
|
+
curli = undefined;
|
220
|
+
}
|
221
|
+
}
|
222
|
+
if (thisTag < lastTag) {
|
223
|
+
for (i = 0; i < lastTag - thisTag; i++) {
|
224
|
+
toc = toc.parent();
|
225
|
+
toc = toc.parent();
|
226
|
+
}
|
227
|
+
}
|
228
|
+
var title = $(this).attr("toc-title");
|
229
|
+
if (typeof title == "undefined") title = $(this).text();
|
230
|
+
curli = $('<li><a href="#' + this.id + '">' + title + "</a></li>");
|
231
|
+
toc.append(curli);
|
232
|
+
lastTag = thisTag;
|
233
|
+
});
|
234
|
+
if (!show) return;
|
235
|
+
html =
|
236
|
+
'<div id="toc"><p class="title hide_toc"><a href="#"><strong>Table of Contents</strong></a></p></div>';
|
237
|
+
$("#content").prepend(html);
|
238
|
+
$("#toc").append(_toc);
|
239
|
+
$("#toc .hide_toc").toggle(
|
240
|
+
function () {
|
241
|
+
$("#toc .top").slideUp("fast");
|
242
|
+
$("#toc").toggleClass("hidden");
|
243
|
+
$("#toc .title small").toggle();
|
244
|
+
},
|
245
|
+
function () {
|
246
|
+
$("#toc .top").slideDown("fast");
|
247
|
+
$("#toc").toggleClass("hidden");
|
248
|
+
$("#toc .title small").toggle();
|
249
|
+
}
|
250
|
+
);
|
251
|
+
}
|
252
|
+
|
253
|
+
function navResizeFn(e) {
|
254
|
+
if (e.which !== 1) {
|
255
|
+
navResizeFnStop();
|
256
|
+
return;
|
257
|
+
}
|
258
|
+
|
259
|
+
sessionStorage.navWidth = e.pageX.toString();
|
260
|
+
$(".nav_wrap").css("width", e.pageX);
|
261
|
+
$(".nav_wrap").css("-ms-flex", "inherit");
|
262
|
+
}
|
263
|
+
|
264
|
+
function navResizeFnStop() {
|
265
|
+
$(window).unbind("mousemove", navResizeFn);
|
266
|
+
window.removeEventListener("message", navMessageFn, false);
|
267
|
+
}
|
268
|
+
|
269
|
+
function navMessageFn(e) {
|
270
|
+
if (e.data.action === "mousemove") navResizeFn(e.data.event);
|
271
|
+
if (e.data.action === "mouseup") navResizeFnStop();
|
272
|
+
}
|
273
|
+
|
274
|
+
function navResizer() {
|
275
|
+
$("#resizer").mousedown(function (e) {
|
276
|
+
e.preventDefault();
|
277
|
+
$(window).mousemove(navResizeFn);
|
278
|
+
window.addEventListener("message", navMessageFn, false);
|
279
|
+
});
|
280
|
+
$(window).mouseup(navResizeFnStop);
|
281
|
+
|
282
|
+
if (sessionStorage.navWidth) {
|
283
|
+
navResizeFn({ which: 1, pageX: parseInt(sessionStorage.navWidth, 10) });
|
284
|
+
}
|
285
|
+
}
|
286
|
+
|
287
|
+
function navExpander() {
|
288
|
+
if (typeof pathId === "undefined") return;
|
289
|
+
var done = false,
|
290
|
+
timer = setTimeout(postMessage, 500);
|
291
|
+
function postMessage() {
|
292
|
+
if (done) return;
|
293
|
+
clearTimeout(timer);
|
294
|
+
var opts = { action: "expand", path: pathId };
|
295
|
+
document.getElementById("nav").contentWindow.postMessage(opts, "*");
|
296
|
+
done = true;
|
297
|
+
}
|
298
|
+
|
299
|
+
window.addEventListener(
|
300
|
+
"message",
|
301
|
+
function (event) {
|
302
|
+
if (event.data === "navReady") postMessage();
|
303
|
+
return false;
|
304
|
+
},
|
305
|
+
false
|
306
|
+
);
|
307
|
+
}
|
308
|
+
|
309
|
+
function mainFocus() {
|
310
|
+
var hash = window.location.hash;
|
311
|
+
if (hash !== "" && $(hash)[0]) {
|
312
|
+
$(hash)[0].scrollIntoView();
|
313
|
+
}
|
314
|
+
|
315
|
+
setTimeout(function () {
|
316
|
+
$("#main").focus();
|
317
|
+
}, 10);
|
318
|
+
}
|
319
|
+
|
320
|
+
function navigationChange() {
|
321
|
+
// This works around the broken anchor navigation with the YARD template.
|
322
|
+
window.onpopstate = function () {
|
323
|
+
var hash = window.location.hash;
|
324
|
+
if (hash !== "" && $(hash)[0]) {
|
325
|
+
$(hash)[0].scrollIntoView();
|
326
|
+
}
|
327
|
+
};
|
328
|
+
}
|
329
|
+
|
330
|
+
$(document).ready(function () {
|
331
|
+
navResizer();
|
332
|
+
navExpander();
|
333
|
+
createSourceLinks();
|
334
|
+
createDefineLinks();
|
335
|
+
createFullTreeLinks();
|
336
|
+
searchFrameButtons();
|
337
|
+
linkSummaries();
|
338
|
+
summaryToggle();
|
339
|
+
constantSummaryToggle();
|
340
|
+
generateTOC();
|
341
|
+
mainFocus();
|
342
|
+
navigationChange();
|
343
|
+
});
|
344
|
+
})();
|