smoke 0.0.3 → 0.5.9
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.markdown +101 -0
- data/Rakefile +53 -4
- data/VERSION.yml +4 -0
- data/examples/web_search_joined.rb +25 -0
- data/examples/yql_web_search.rb +11 -0
- data/lib/core_ext/hash.rb +20 -0
- data/lib/core_ext/string.rb +6 -0
- data/lib/smoke.rb +103 -3
- data/lib/smoke/cache.rb +56 -0
- data/lib/smoke/origin.rb +251 -0
- data/lib/smoke/request.rb +57 -0
- data/lib/smoke/source/data.rb +39 -0
- data/lib/smoke/source/feed.rb +24 -0
- data/lib/smoke/source/join.rb +33 -0
- data/lib/smoke/source/yql.rb +85 -0
- data/rdoc/classes/Smoke.html +260 -0
- data/rdoc/classes/Smoke/Origin.html +340 -0
- data/rdoc/classes/Smoke/Source/Data.html +126 -0
- data/rdoc/classes/Smoke/Source/Feed.html +117 -0
- data/rdoc/classes/Smoke/Source/YQL.html +223 -0
- data/rdoc/created.rid +1 -0
- data/rdoc/files/README_markdown.html +180 -0
- data/rdoc/files/lib/core_ext/hash_rb.html +49 -0
- data/rdoc/files/lib/smoke/origin_rb.html +49 -0
- data/rdoc/files/lib/smoke/request_rb.html +49 -0
- data/rdoc/files/lib/smoke/source/data_rb.html +49 -0
- data/rdoc/files/lib/smoke/source/feed_rb.html +49 -0
- data/rdoc/files/lib/smoke/source/join_rb.html +49 -0
- data/rdoc/files/lib/smoke/source/yql_rb.html +49 -0
- data/rdoc/files/lib/smoke_rb.html +65 -0
- data/rdoc/fr_class_index.html +21 -0
- data/rdoc/fr_file_index.html +28 -0
- data/rdoc/fr_method_index.html +4459 -0
- data/rdoc/index.html +15 -0
- data/rdoc/rdoc-style.css +319 -0
- data/spec/core_ext/hash_spec.rb +25 -0
- data/spec/smoke/cache_spec.rb +75 -0
- data/spec/smoke/origin_spec.rb +220 -0
- data/spec/smoke/request_spec.rb +49 -0
- data/spec/smoke/shared_spec.rb +182 -0
- data/spec/smoke/source/data_spec.rb +65 -0
- data/spec/smoke/source/feed_spec.rb +49 -0
- data/spec/smoke/source/join_spec.rb +53 -0
- data/spec/smoke/source/yql_spec.rb +111 -0
- data/spec/smoke_spec.rb +51 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/supports/amc_pacer.json.yql +10 -0
- data/spec/supports/datatables.yql +12 -0
- data/spec/supports/flickr-photo.json +7 -0
- data/spec/supports/gzip_response.txt +0 -0
- data/spec/supports/search-web.json.yql +12 -0
- data/spec/supports/search-web.xml.yql +83 -0
- data/spec/supports/slashdot.xml +98 -0
- data/spec/supports/test_source.rb +10 -0
- metadata +144 -67
- data/History.txt +0 -13
- data/License.txt +0 -21
- data/Manifest.txt +0 -44
- data/README.txt +0 -3
- data/bin/smoke +0 -41
- data/bin/smoked +0 -43
- data/config/hoe.rb +0 -70
- data/config/requirements.rb +0 -17
- data/contrib/processors/smoke/remote_port_status_check_processor.rb +0 -10
- data/contrib/processors/smoke/system_load_processor.rb +0 -52
- data/contrib/signals/smoke/remote_port_status_check.rb +0 -39
- data/contrib/signals/smoke/system_load.rb +0 -23
- data/lib/smoke/client.rb +0 -50
- data/lib/smoke/client/connection.rb +0 -44
- data/lib/smoke/client/signal_runner.rb +0 -40
- data/lib/smoke/client/version.rb +0 -11
- data/lib/smoke/server.rb +0 -18
- data/lib/smoke/server/signal_handler.rb +0 -64
- data/lib/smoke/server/signal_router.rb +0 -38
- data/lib/smoke/server/version.rb +0 -11
- data/lib/smoke/signal.rb +0 -19
- data/lib/smoke/signal_processor.rb +0 -29
- data/lib/smoke/version.rb +0 -9
- data/log/debug.log +0 -0
- data/log/development.log +0 -0
- data/log/production.log +0 -0
- data/log/server.log +0 -0
- data/log/test.log +0 -0
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/script/txt2html +0 -74
- data/setup.rb +0 -1585
- data/tasks/deployment.rake +0 -35
- data/tasks/environment.rake +0 -7
- data/tasks/website.rake +0 -17
- data/test/test_helper.rb +0 -2
- data/test/test_server.rb +0 -11
- data/website/index.html +0 -87
- data/website/index.txt +0 -29
- data/website/javascripts/rounded_corners_lite.inc.js +0 -285
- data/website/stylesheets/screen.css +0 -138
- data/website/template.rhtml +0 -48
@@ -0,0 +1,340 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
2
|
+
<html lang='en'>
|
3
|
+
<head>
|
4
|
+
<title>: Smoke::Origin [smoke]</title>
|
5
|
+
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
|
6
|
+
<link href='../../rdoc-style.css' media='screen' rel='stylesheet' type='text/css'>
|
7
|
+
<script type='text/javascript'>
|
8
|
+
//<![CDATA[
|
9
|
+
function popupCode(url) {
|
10
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
11
|
+
}
|
12
|
+
|
13
|
+
function toggleCode(id) {
|
14
|
+
var code = document.getElementById(id)
|
15
|
+
|
16
|
+
code.style.display = code.style.display != 'block' ? 'block' : 'none'
|
17
|
+
return true
|
18
|
+
}
|
19
|
+
|
20
|
+
// Make codeblocks hidden by default
|
21
|
+
document.writeln('<' + 'style type="text/css">.method .source pre { display: none }<\/style>')
|
22
|
+
//]]>
|
23
|
+
</script>
|
24
|
+
</head>
|
25
|
+
<body class='page'>
|
26
|
+
<div class='class' id='wrapper'>
|
27
|
+
<div class='header'>
|
28
|
+
<h1 class='name'>
|
29
|
+
<span class='type'>Class</span>
|
30
|
+
Smoke::Origin
|
31
|
+
</h1>
|
32
|
+
<ol class='paths'>
|
33
|
+
<li>
|
34
|
+
<a href="../../files/lib/smoke/origin_rb.html">lib/smoke/origin.rb</a>
|
35
|
+
</li>
|
36
|
+
</ol>
|
37
|
+
<div class='parent'>
|
38
|
+
Parent:
|
39
|
+
<strong>Object</strong>
|
40
|
+
</div>
|
41
|
+
</div>
|
42
|
+
<div id='content'>
|
43
|
+
<div id='text'>
|
44
|
+
<div id='method-list'>
|
45
|
+
<h2>Methods</h2>
|
46
|
+
<h3>public class</h3>
|
47
|
+
<ol>
|
48
|
+
<li><a href="#M000020">new</a></li>
|
49
|
+
</ol>
|
50
|
+
<h3>public instance</h3>
|
51
|
+
<ol>
|
52
|
+
<li><a href="#M000028">discard</a></li>
|
53
|
+
<li><a href="#M000023">emit</a></li>
|
54
|
+
<li><a href="#M000027">keep</a></li>
|
55
|
+
<li><a href="#M000025">method_missing</a></li>
|
56
|
+
<li><a href="#M000021">output</a></li>
|
57
|
+
<li><a href="#M000022">path</a></li>
|
58
|
+
<li><a href="#M000024">prepare</a></li>
|
59
|
+
<li><a href="#M000029">rename</a></li>
|
60
|
+
<li><a href="#M000026">sort</a></li>
|
61
|
+
<li><a href="#M000030">truncate</a></li>
|
62
|
+
</ol>
|
63
|
+
</div>
|
64
|
+
<div id='section'>
|
65
|
+
<div id='attribute-list'>
|
66
|
+
<h2 class='section-bar'>Attributes</h2>
|
67
|
+
<div class='name-list'>
|
68
|
+
<table>
|
69
|
+
<tr class='top-aligned-row context-row'>
|
70
|
+
<td class='context-item-name'>items</td>
|
71
|
+
<td class='context-item-value'>[R]</td>
|
72
|
+
<td class='context-item-desc'></td>
|
73
|
+
</tr>
|
74
|
+
<tr class='top-aligned-row context-row'>
|
75
|
+
<td class='context-item-name'>name</td>
|
76
|
+
<td class='context-item-value'>[RW]</td>
|
77
|
+
<td class='context-item-desc'></td>
|
78
|
+
</tr>
|
79
|
+
</table>
|
80
|
+
</div>
|
81
|
+
</div>
|
82
|
+
<div id='methods'>
|
83
|
+
<h2>Public class methods</h2>
|
84
|
+
<div class='public-class method' id='method-M000020'>
|
85
|
+
<a name='M000020'> </a>
|
86
|
+
<div class='synopsis'>
|
87
|
+
<span class='name'>new</span>
|
88
|
+
<span class='arguments'>(name, &block)</span>
|
89
|
+
</div>
|
90
|
+
<div class='source'>
|
91
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000020-source'); return false">
|
92
|
+
[show source]
|
93
|
+
</a>
|
94
|
+
<pre id='M000020-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 6</span>
 6: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">name</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
 7: <span class="ruby-identifier">raise</span> <span class="ruby-constant">StandardError</span>, <span class="ruby-value str">"Sources must have a name"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">name</span>
 8: <span class="ruby-ivar">@name</span> = <span class="ruby-identifier">name</span>
 9: <span class="ruby-ivar">@items</span>, <span class="ruby-ivar">@prepare</span>, <span class="ruby-ivar">@transformation</span> = [], [], []
10: 
11: <span class="ruby-identifier">activate!</span>
12: <span class="ruby-identifier">instance_eval</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
13: <span class="ruby-keyword kw">end</span></pre>
|
95
|
+
</div>
|
96
|
+
</div>
|
97
|
+
<h2>Public instance methods</h2>
|
98
|
+
<div class='public-instance method' id='method-M000028'>
|
99
|
+
<a name='M000028'> </a>
|
100
|
+
<div class='synopsis'>
|
101
|
+
<span class='name'>discard</span>
|
102
|
+
<span class='arguments'>(key, matcher)</span>
|
103
|
+
</div>
|
104
|
+
<div class='description'>
|
105
|
+
<p>
|
106
|
+
Discard items that do not match the regex
|
107
|
+
</p>
|
108
|
+
<p>
|
109
|
+
Usage (chained):
|
110
|
+
</p>
|
111
|
+
<pre>Smoke[:ruby].discard(:title, /tuesday/i)</pre>
|
112
|
+
<p>
|
113
|
+
Usage (block, during initialization):
|
114
|
+
</p>
|
115
|
+
<pre>Smoke.yql(:ruby) do
 ...
 discard(:title, /tuesday/i)
end</pre>
|
116
|
+
</div>
|
117
|
+
<div class='source'>
|
118
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000028-source'); return false">
|
119
|
+
[show source]
|
120
|
+
</a>
|
121
|
+
<pre id='M000028-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 140</span>
140: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">discard</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">matcher</span>)
141: <span class="ruby-ivar">@items</span>.<span class="ruby-identifier">reject!</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> (<span class="ruby-identifier">i</span>[<span class="ruby-identifier">key</span>] <span class="ruby-operator">=~</span> <span class="ruby-identifier">matcher</span>) <span class="ruby-operator">?</span> <span class="ruby-keyword kw">true</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">false</span> }
142: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>
143: <span class="ruby-keyword kw">end</span></pre>
|
122
|
+
</div>
|
123
|
+
</div>
|
124
|
+
<div class='public-instance method' id='method-M000023'>
|
125
|
+
<a name='M000023'> </a>
|
126
|
+
<div class='synopsis'>
|
127
|
+
<span class='name'>emit</span>
|
128
|
+
<span class='arguments'>(&block)</span>
|
129
|
+
</div>
|
130
|
+
<div class='description'>
|
131
|
+
<p>
|
132
|
+
Transform each item
|
133
|
+
</p>
|
134
|
+
<p>
|
135
|
+
Usage:
|
136
|
+
</p>
|
137
|
+
<pre>emit do
 rename(:href => :link)
end</pre>
|
138
|
+
</div>
|
139
|
+
<div class='source'>
|
140
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000023-source'); return false">
|
141
|
+
[show source]
|
142
|
+
</a>
|
143
|
+
<pre id='M000023-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 72</span>
72: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">emit</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
73: <span class="ruby-ivar">@transformation</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">block</span>
74: <span class="ruby-keyword kw">end</span></pre>
|
144
|
+
</div>
|
145
|
+
</div>
|
146
|
+
<div class='public-instance method' id='method-M000027'>
|
147
|
+
<a name='M000027'> </a>
|
148
|
+
<div class='synopsis'>
|
149
|
+
<span class='name'>keep</span>
|
150
|
+
<span class='arguments'>(key, matcher)</span>
|
151
|
+
</div>
|
152
|
+
<div class='description'>
|
153
|
+
<p>
|
154
|
+
Keep items that match the regex
|
155
|
+
</p>
|
156
|
+
<p>
|
157
|
+
Usage (chained):
|
158
|
+
</p>
|
159
|
+
<pre>Smoke[:ruby].keep(:title, /tuesday/i)</pre>
|
160
|
+
<p>
|
161
|
+
Usage (block, during initialization):
|
162
|
+
</p>
|
163
|
+
<pre>Smoke.yql(:ruby) do
 ...
 keep(:title, /tuesday/i)
end</pre>
|
164
|
+
</div>
|
165
|
+
<div class='source'>
|
166
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000027-source'); return false">
|
167
|
+
[show source]
|
168
|
+
</a>
|
169
|
+
<pre id='M000027-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 126</span>
126: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">keep</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">matcher</span>)
127: <span class="ruby-ivar">@items</span>.<span class="ruby-identifier">reject!</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> (<span class="ruby-identifier">i</span>[<span class="ruby-identifier">key</span>] <span class="ruby-operator">=~</span> <span class="ruby-identifier">matcher</span>) <span class="ruby-operator">?</span> <span class="ruby-keyword kw">false</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">true</span> }
128: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>
129: <span class="ruby-keyword kw">end</span></pre>
|
170
|
+
</div>
|
171
|
+
</div>
|
172
|
+
<div class='public-instance method' id='method-M000025'>
|
173
|
+
<a name='M000025'> </a>
|
174
|
+
<div class='synopsis'>
|
175
|
+
<span class='name'>method_missing</span>
|
176
|
+
<span class='arguments'>(symbol, *args, &block)</span>
|
177
|
+
</div>
|
178
|
+
<div class='source'>
|
179
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000025-source'); return false">
|
180
|
+
[show source]
|
181
|
+
</a>
|
182
|
+
<pre id='M000025-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 96</span>
 96: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">method_missing</span>(<span class="ruby-identifier">symbol</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
 97: <span class="ruby-identifier">ivar</span> = <span class="ruby-node">"@#{symbol}"</span>
 98: 
 99: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">empty?</span>
100: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-identifier">ivar</span>) <span class="ruby-operator">||</span> <span class="ruby-keyword kw">super</span> 
101: <span class="ruby-keyword kw">else</span>
102: <span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-identifier">ivar</span>, <span class="ruby-identifier">args</span>.<span class="ruby-identifier">pop</span>)
103: <span class="ruby-keyword kw">end</span>
104: 
105: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>
106: <span class="ruby-keyword kw">end</span></pre>
|
183
|
+
</div>
|
184
|
+
</div>
|
185
|
+
<div class='public-instance method' id='method-M000021'>
|
186
|
+
<a name='M000021'> </a>
|
187
|
+
<div class='synopsis'>
|
188
|
+
<span class='name'>output</span>
|
189
|
+
<span class='arguments'>(type = :ruby)</span>
|
190
|
+
</div>
|
191
|
+
<div class='description'>
|
192
|
+
<p>
|
193
|
+
Output your items in a range of formats (:ruby, :json and :yaml currently)
|
194
|
+
Ruby is the default format and will automagically yielded from your source
|
195
|
+
</p>
|
196
|
+
<p>
|
197
|
+
Usage
|
198
|
+
</p>
|
199
|
+
<pre>output(:json)
=> "[{title: \"Ray\"}, {title: \"Peace\"}]"</pre>
|
200
|
+
</div>
|
201
|
+
<div class='source'>
|
202
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000021-source'); return false">
|
203
|
+
[show source]
|
204
|
+
</a>
|
205
|
+
<pre id='M000021-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 22</span>
22: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">output</span>(<span class="ruby-identifier">type</span> = <span class="ruby-identifier">:ruby</span>)
23: <span class="ruby-identifier">prepare!</span>
24: <span class="ruby-identifier">dispatch</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">:dispatch</span>
25: <span class="ruby-identifier">output</span> = (<span class="ruby-ivar">@items</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>) <span class="ruby-operator">?</span> <span class="ruby-ivar">@items</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">:</span> <span class="ruby-ivar">@items</span>
26: 
27: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">type</span>
28: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:json</span>
29: <span class="ruby-keyword kw">return</span> <span class="ruby-operator">::</span><span class="ruby-constant">JSON</span>.<span class="ruby-identifier">generate</span>(<span class="ruby-identifier">output</span>)
30: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:yaml</span>
31: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">YAML</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-identifier">output</span>)
32: <span class="ruby-keyword kw">else</span>
33: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">output</span>
34: <span class="ruby-keyword kw">end</span> 
35: <span class="ruby-keyword kw">end</span></pre>
|
206
|
+
</div>
|
207
|
+
</div>
|
208
|
+
<div class='public-instance method' id='method-M000022'>
|
209
|
+
<a name='M000022'> </a>
|
210
|
+
<div class='synopsis'>
|
211
|
+
<span class='name'>path</span>
|
212
|
+
<span class='arguments'>(*path)</span>
|
213
|
+
</div>
|
214
|
+
<div class='description'>
|
215
|
+
<p>
|
216
|
+
Path allows you to traverse the tree of a the items returned to only give
|
217
|
+
you access to what you’re interested in.
|
218
|
+
</p>
|
219
|
+
<p>
|
220
|
+
Usage: path :down, :to, :the, :data
|
221
|
+
</p>
|
222
|
+
<p>
|
223
|
+
Will traverse through a tree as follows:
|
224
|
+
</p>
|
225
|
+
<pre>{
 :down => {
 :to => {
 :the => {
 :data => []
 }
 }
 }
}</pre>
|
226
|
+
<p>
|
227
|
+
You will need to help smoke find an array of items that you’re
|
228
|
+
interested in.
|
229
|
+
</p>
|
230
|
+
</div>
|
231
|
+
<div class='source'>
|
232
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000022-source'); return false">
|
233
|
+
[show source]
|
234
|
+
</a>
|
235
|
+
<pre id='M000022-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 62</span>
62: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">path</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">path</span>)
63: <span class="ruby-ivar">@path</span> = <span class="ruby-identifier">path</span>
64: <span class="ruby-keyword kw">end</span></pre>
|
236
|
+
</div>
|
237
|
+
</div>
|
238
|
+
<div class='public-instance method' id='method-M000024'>
|
239
|
+
<a name='M000024'> </a>
|
240
|
+
<div class='synopsis'>
|
241
|
+
<span class='name'>prepare</span>
|
242
|
+
<span class='arguments'>(&block)</span>
|
243
|
+
</div>
|
244
|
+
<div class='description'>
|
245
|
+
<p>
|
246
|
+
Prepare is used when you’d like to provision for arguments /
|
247
|
+
variables to be set after the source definition. Eg, create a source
|
248
|
+
definition for twitter, omitting the “username”. Set the
|
249
|
+
username using chaining later.
|
250
|
+
</p>
|
251
|
+
<p>
|
252
|
+
Usage:
|
253
|
+
</p>
|
254
|
+
<pre># Definition
Smoke.feed :twitter do
 prepare do
 url "http://twitter.com/#{username}/rss"
 end
end

# End use
Smoke[:twitter].username(:benschwarz).output</pre>
|
255
|
+
</div>
|
256
|
+
<div class='source'>
|
257
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000024-source'); return false">
|
258
|
+
[show source]
|
259
|
+
</a>
|
260
|
+
<pre id='M000024-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 91</span>
91: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">prepare</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
92: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">"requires a block"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">block_given?</span>
93: <span class="ruby-ivar">@prepare</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">block</span>
94: <span class="ruby-keyword kw">end</span></pre>
|
261
|
+
</div>
|
262
|
+
</div>
|
263
|
+
<div class='public-instance method' id='method-M000029'>
|
264
|
+
<a name='M000029'> </a>
|
265
|
+
<div class='synopsis'>
|
266
|
+
<span class='name'>rename</span>
|
267
|
+
<span class='arguments'>(*args)</span>
|
268
|
+
</div>
|
269
|
+
<div class='description'>
|
270
|
+
<p>
|
271
|
+
Rename one or many keys at a time Suggested that you run it within an each
|
272
|
+
block, but it makes no difference other than readability
|
273
|
+
</p>
|
274
|
+
<p>
|
275
|
+
Usage
|
276
|
+
</p>
|
277
|
+
<pre># Renames all items with a key of href to link
rename(:href => :link)</pre>
|
278
|
+
<p>
|
279
|
+
or
|
280
|
+
</p>
|
281
|
+
<pre>rename(:href => :link, :description => :excerpt)</pre>
|
282
|
+
</div>
|
283
|
+
<div class='source'>
|
284
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000029-source'); return false">
|
285
|
+
[show source]
|
286
|
+
</a>
|
287
|
+
<pre id='M000029-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 154</span>
154: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">rename</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
155: <span class="ruby-ivar">@items</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">item</span><span class="ruby-operator">|</span> <span class="ruby-identifier">item</span>.<span class="ruby-identifier">rename</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>) }
156: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>
157: <span class="ruby-keyword kw">end</span></pre>
|
288
|
+
</div>
|
289
|
+
</div>
|
290
|
+
<div class='public-instance method' id='method-M000026'>
|
291
|
+
<a name='M000026'> </a>
|
292
|
+
<div class='synopsis'>
|
293
|
+
<span class='name'>sort</span>
|
294
|
+
<span class='arguments'>(key)</span>
|
295
|
+
</div>
|
296
|
+
<div class='description'>
|
297
|
+
<p>
|
298
|
+
Re-sort items by a particular key
|
299
|
+
</p>
|
300
|
+
</div>
|
301
|
+
<div class='source'>
|
302
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000026-source'); return false">
|
303
|
+
[show source]
|
304
|
+
</a>
|
305
|
+
<pre id='M000026-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 109</span>
109: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sort</span>(<span class="ruby-identifier">key</span>)
110: <span class="ruby-ivar">@items</span> = <span class="ruby-ivar">@items</span>.<span class="ruby-identifier">sort_by</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">i</span>[<span class="ruby-identifier">key</span>] }
111: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">NoMethodError</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
112: <span class="ruby-constant">Smoke</span>.<span class="ruby-identifier">log</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">"You're trying to sort by \"#{key}\" but it does not exist in your item set"</span>
113: <span class="ruby-keyword kw">ensure</span>
114: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>
115: <span class="ruby-keyword kw">end</span></pre>
|
306
|
+
</div>
|
307
|
+
</div>
|
308
|
+
<div class='public-instance method' id='method-M000030'>
|
309
|
+
<a name='M000030'> </a>
|
310
|
+
<div class='synopsis'>
|
311
|
+
<span class='name'>truncate</span>
|
312
|
+
<span class='arguments'>(length)</span>
|
313
|
+
</div>
|
314
|
+
<div class='description'>
|
315
|
+
<p>
|
316
|
+
Truncate your result set to this many objects
|
317
|
+
</p>
|
318
|
+
<p>
|
319
|
+
Usage
|
320
|
+
</p>
|
321
|
+
<pre>truncate(3).output
=> [{title => "Canon"}, {:title => "Nikon"}, {:title => "Pentax"}]</pre>
|
322
|
+
</div>
|
323
|
+
<div class='source'>
|
324
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000030-source'); return false">
|
325
|
+
[show source]
|
326
|
+
</a>
|
327
|
+
<pre id='M000030-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 165</span>
165: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">truncate</span>(<span class="ruby-identifier">length</span>)
166: <span class="ruby-ivar">@items</span> = <span class="ruby-ivar">@items</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span>(<span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>)]
167: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>
168: <span class="ruby-keyword kw">end</span></pre>
|
328
|
+
</div>
|
329
|
+
</div>
|
330
|
+
</div>
|
331
|
+
</div>
|
332
|
+
</div>
|
333
|
+
</div>
|
334
|
+
<div id='footer-push'></div>
|
335
|
+
</div>
|
336
|
+
<div id='footer'>
|
337
|
+
<a href="http://github.com/mislav/hanna/tree/master"><strong>Hanna</strong> RDoc template</a>
|
338
|
+
</div>
|
339
|
+
</body>
|
340
|
+
</html>
|
@@ -0,0 +1,126 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
2
|
+
<html lang='en'>
|
3
|
+
<head>
|
4
|
+
<title>: Smoke::Source::Data [smoke]</title>
|
5
|
+
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
|
6
|
+
<link href='../../../rdoc-style.css' media='screen' rel='stylesheet' type='text/css'>
|
7
|
+
<script type='text/javascript'>
|
8
|
+
//<![CDATA[
|
9
|
+
function popupCode(url) {
|
10
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
11
|
+
}
|
12
|
+
|
13
|
+
function toggleCode(id) {
|
14
|
+
var code = document.getElementById(id)
|
15
|
+
|
16
|
+
code.style.display = code.style.display != 'block' ? 'block' : 'none'
|
17
|
+
return true
|
18
|
+
}
|
19
|
+
|
20
|
+
// Make codeblocks hidden by default
|
21
|
+
document.writeln('<' + 'style type="text/css">.method .source pre { display: none }<\/style>')
|
22
|
+
//]]>
|
23
|
+
</script>
|
24
|
+
</head>
|
25
|
+
<body class='page'>
|
26
|
+
<div class='class' id='wrapper'>
|
27
|
+
<div class='header'>
|
28
|
+
<h1 class='name'>
|
29
|
+
<span class='type'>Class</span>
|
30
|
+
Smoke::Source::Data
|
31
|
+
</h1>
|
32
|
+
<ol class='paths'>
|
33
|
+
<li>
|
34
|
+
<a href="../../../files/lib/smoke/source/data_rb.html">lib/smoke/source/data.rb</a>
|
35
|
+
</li>
|
36
|
+
</ol>
|
37
|
+
<div class='parent'>
|
38
|
+
Parent:
|
39
|
+
<strong><a href="../Origin.html">Smoke::Origin</a></strong>
|
40
|
+
</div>
|
41
|
+
</div>
|
42
|
+
<div id='content'>
|
43
|
+
<div id='text'>
|
44
|
+
<div id='description'>
|
45
|
+
<p>
|
46
|
+
The “Data” source allows you to query datasources that are
|
47
|
+
“complete” urls and rely on the automagic object parsing that
|
48
|
+
smoke provides.
|
49
|
+
</p>
|
50
|
+
<p>
|
51
|
+
For example, you may use this source to query a complete restful api call
|
52
|
+
unpackage the xml response and get a clean ruby object.
|
53
|
+
</p>
|
54
|
+
<p>
|
55
|
+
<a href="Data.html">Data</a> can take as many urls as you’d like to
|
56
|
+
throw at it.
|
57
|
+
</p>
|
58
|
+
<p>
|
59
|
+
Usage:
|
60
|
+
</p>
|
61
|
+
<pre>Smoke.data(:ruby) do
 url "http://api.flickr.com/services/rest/?user_id=36821533%40N00&tags=benschwarz-site&nojsoncallback=1&method=flickr.photos.search&format=json&api_key=your_api_key_here
 path :photos, :photo
end</pre>
|
62
|
+
</div>
|
63
|
+
<div id='method-list'>
|
64
|
+
<h2>Methods</h2>
|
65
|
+
<h3>public instance</h3>
|
66
|
+
<ol>
|
67
|
+
<li><a href="#M000012">url</a></li>
|
68
|
+
</ol>
|
69
|
+
<h3>protected instance</h3>
|
70
|
+
<ol>
|
71
|
+
<li><a href="#M000013">dispatch</a></li>
|
72
|
+
</ol>
|
73
|
+
</div>
|
74
|
+
<div id='section'>
|
75
|
+
<div id='attribute-list'>
|
76
|
+
<h2 class='section-bar'>Attributes</h2>
|
77
|
+
<div class='name-list'>
|
78
|
+
<table>
|
79
|
+
<tr class='top-aligned-row context-row'>
|
80
|
+
<td class='context-item-name'>request</td>
|
81
|
+
<td class='context-item-value'>[R]</td>
|
82
|
+
<td class='context-item-desc'></td>
|
83
|
+
</tr>
|
84
|
+
</table>
|
85
|
+
</div>
|
86
|
+
</div>
|
87
|
+
<div id='methods'>
|
88
|
+
<h2>Public instance methods</h2>
|
89
|
+
<div class='public-instance method' id='method-M000012'>
|
90
|
+
<a name='M000012'> </a>
|
91
|
+
<div class='synopsis'>
|
92
|
+
<span class='name'>url</span>
|
93
|
+
<span class='arguments'>(source_url)</span>
|
94
|
+
</div>
|
95
|
+
<div class='source'>
|
96
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000012-source'); return false">
|
97
|
+
[show source]
|
98
|
+
</a>
|
99
|
+
<pre id='M000012-source'> <span class="ruby-comment cmt"># File lib/smoke/source/data.rb, line 24</span>
24: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">url</span>(<span class="ruby-identifier">source_url</span>)
25: <span class="ruby-ivar">@url</span> = <span class="ruby-identifier">source_url</span>
26: <span class="ruby-keyword kw">end</span></pre>
|
100
|
+
</div>
|
101
|
+
</div>
|
102
|
+
<h2>Protected instance methods</h2>
|
103
|
+
<div class='protected-instance method' id='method-M000013'>
|
104
|
+
<a name='M000013'> </a>
|
105
|
+
<div class='synopsis'>
|
106
|
+
<span class='name'>dispatch</span>
|
107
|
+
<span class='arguments'>()</span>
|
108
|
+
</div>
|
109
|
+
<div class='source'>
|
110
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000013-source'); return false">
|
111
|
+
[show source]
|
112
|
+
</a>
|
113
|
+
<pre id='M000013-source'> <span class="ruby-comment cmt"># File lib/smoke/source/data.rb, line 29</span>
29: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dispatch</span>
30: <span class="ruby-ivar">@request</span> = <span class="ruby-constant">Smoke</span><span class="ruby-operator">::</span><span class="ruby-constant">Request</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@url</span>)
31: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">items</span> = (<span class="ruby-ivar">@path</span>.<span class="ruby-identifier">nil?</span>) <span class="ruby-operator">?</span> <span class="ruby-ivar">@request</span>.<span class="ruby-identifier">body</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">drill</span>(<span class="ruby-ivar">@request</span>.<span class="ruby-identifier">body</span>, <span class="ruby-operator">*</span><span class="ruby-ivar">@path</span>)
32: <span class="ruby-keyword kw">end</span></pre>
|
114
|
+
</div>
|
115
|
+
</div>
|
116
|
+
</div>
|
117
|
+
</div>
|
118
|
+
</div>
|
119
|
+
</div>
|
120
|
+
<div id='footer-push'></div>
|
121
|
+
</div>
|
122
|
+
<div id='footer'>
|
123
|
+
<a href="http://github.com/mislav/hanna/tree/master"><strong>Hanna</strong> RDoc template</a>
|
124
|
+
</div>
|
125
|
+
</body>
|
126
|
+
</html>
|