stone 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/History.txt +3 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +50 -0
  4. data/README.txt +52 -0
  5. data/Rakefile +22 -0
  6. data/bin/stone-gen +70 -0
  7. data/config/hoe.rb +70 -0
  8. data/config/requirements.rb +15 -0
  9. data/lib/stone/callbacks.rb +50 -0
  10. data/lib/stone/core_ext/string.rb +9 -0
  11. data/lib/stone/core_ext/symbol.rb +22 -0
  12. data/lib/stone/data_store.rb +80 -0
  13. data/lib/stone/query.rb +44 -0
  14. data/lib/stone/resource.rb +424 -0
  15. data/lib/stone/version.rb +9 -0
  16. data/lib/stone.rb +55 -0
  17. data/log/debug.log +0 -0
  18. data/sandbox_for_specs/datastore/.stone_metadata +2 -0
  19. data/sandbox_for_specs/datastore/authors/1.yml +12 -0
  20. data/sandbox_for_specs/datastore/authors/2.yml +12 -0
  21. data/sandbox_for_specs/datastore/authors/3.yml +12 -0
  22. data/sandbox_for_specs/datastore/authors/4.yml +12 -0
  23. data/sandbox_for_specs/datastore/authors/5.yml +12 -0
  24. data/sandbox_for_specs/datastore/posts/1.yml +8 -0
  25. data/sandbox_for_specs/datastore/posts/2.yml +8 -0
  26. data/sandbox_for_specs/sample_resources/author.rb +24 -0
  27. data/sandbox_for_specs/sample_resources/comment.rb +9 -0
  28. data/sandbox_for_specs/sample_resources/person.rb +6 -0
  29. data/sandbox_for_specs/sample_resources/post.rb +9 -0
  30. data/script/console +10 -0
  31. data/script/destroy +14 -0
  32. data/script/generate +14 -0
  33. data/script/txt2html +74 -0
  34. data/setup.rb +0 -0
  35. data/spec/callbacks_spec.rb +43 -0
  36. data/spec/query_spec.rb +19 -0
  37. data/spec/resource_spec.rb +190 -0
  38. data/spec/spec_helper.rb +7 -0
  39. data/spec/stone_spec.rb +12 -0
  40. data/spec/string_spec.rb +16 -0
  41. data/spec/symbol_spec.rb +16 -0
  42. data/tasks/deployment.rake +34 -0
  43. data/tasks/environment.rake +7 -0
  44. data/tasks/website.rake +17 -0
  45. data/website/images/stone.png +0 -0
  46. data/website/index.html +392 -0
  47. data/website/index.txt +245 -0
  48. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  49. data/website/stylesheets/screen.css +150 -0
  50. data/website/template.html.erb +48 -0
  51. metadata +143 -0
@@ -0,0 +1,392 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
+ <title>
8
+ Stone: Dead-Simple Data Persistence
9
+ </title>
10
+ <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
+ <style>
12
+
13
+ </style>
14
+ <script type="text/javascript">
15
+ window.onload = function() {
16
+ settings = {
17
+ tl: { radius: 10 },
18
+ tr: { radius: 10 },
19
+ bl: { radius: 10 },
20
+ br: { radius: 10 },
21
+ antiAlias: true,
22
+ autoPad: true,
23
+ validTags: ["div"]
24
+ }
25
+ var versionBox = new curvyCorners(settings, document.getElementById("version"));
26
+ versionBox.applyCornersToAll();
27
+ }
28
+ </script>
29
+ </head>
30
+ <body>
31
+ <div id="main">
32
+
33
+ <h1>Stone: Dead-Simple Data Persistence</h1>
34
+ <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/stone"; return false'>
35
+ <p>Get Version</p>
36
+ <a href="http://rubyforge.org/projects/stone" class="numbers">0.1.0</a>
37
+ </div>
38
+ <h1>&#x2192; &#8216;stone&#8217;</h1>
39
+
40
+
41
+ <p><img src="images/stone.png" alt="" /></p>
42
+
43
+
44
+ <h2>Sections</h2>
45
+
46
+
47
+ <p><a href="#what">What</a></p>
48
+
49
+
50
+ <p><a href="#installing">Installing</a></p>
51
+
52
+
53
+ <a href="#running">Getting Up and Running</a>
54
+ <ul>
55
+ <li><a href="#rails">Rails</a></li>
56
+ <li><a href="#merb">Merb</a></li>
57
+ <li><a href="#everywhere">Everywhere Else</a></li>
58
+ </ul>
59
+
60
+
61
+ <a href="#usage">Usage</a>
62
+ <ul>
63
+ <li><a href="#models">Models</a></li>
64
+ <li><a href="#gppd">Get, Post, Put, and Delete</a></li>
65
+ </ul>
66
+
67
+
68
+ <p><a href="#word">A Word About Finding Stuff</a></p>
69
+
70
+
71
+ <p><a href="#license">License</a></p>
72
+
73
+
74
+ <p><a href="#contrib">Contributing</a></p>
75
+
76
+
77
+ <a href="#contact">Contact</a>
78
+ <br /><br />
79
+ <h2 id="what">What</h2>
80
+
81
+
82
+ <p>For small applications, a database can be overkill for storing your data in a consistent and
83
+ organized manner. Therefore, Stone was built to provide plug-and-play data persistence for
84
+ any application or framework. It is fast, and it is easy&#8230; therefore it is good.</p>
85
+
86
+
87
+ <h2 id="installing">Installing</h2>
88
+
89
+
90
+ <pre>sudo gem install stone</pre>
91
+
92
+ <h2 id="running">Up and Running</h2>
93
+
94
+
95
+ <h3 id="rails">Rails</h3>
96
+
97
+
98
+ <ul>
99
+ <li>Create a new file in <code>config/initializers</code> called <code>stone.rb</code></li>
100
+ </ul>
101
+
102
+
103
+ <ul>
104
+ <li>Add the following code to your new file:
105
+ <pre class='syntax'>
106
+ <span class="ident">require</span> <span class="punct">'</span><span class="string">stone</span><span class="punct">'</span>
107
+
108
+ <span class="constant">Stone</span><span class="punct">.</span><span class="ident">start</span><span class="punct">(</span><span class="constant">Dir</span><span class="punct">.</span><span class="ident">pwd</span><span class="punct">,</span> <span class="constant">Dir</span><span class="punct">.</span><span class="ident">glob</span><span class="punct">(</span><span class="constant">File</span><span class="punct">.</span><span class="ident">join</span><span class="punct">(</span><span class="constant">Dir</span><span class="punct">.</span><span class="ident">pwd</span><span class="punct">,&quot;</span><span class="string">app/models/*</span><span class="punct">&quot;)),</span> <span class="symbol">:rails</span><span class="punct">)</span>
109
+ </pre></li>
110
+ </ul>
111
+
112
+
113
+ <ul>
114
+ <li>Open your <code>environment.rb</code> file and look for the following lines:
115
+ <pre class='syntax'>
116
+ <span class="comment"># Skip frameworks you're not going to use (only works if using vendor/rails).</span>
117
+ <span class="comment"># To use Rails without a database, you must remove the Active Record framework</span>
118
+ <span class="comment"># config.frameworks -= [ :active_record, :active_resource, :action_mailer ]</span>
119
+ </pre></li>
120
+ </ul>
121
+
122
+
123
+ <ul>
124
+ <li>Uncomment the last of those lines, and leave only active_record,
125
+ so that it looks like this:
126
+ <pre class='syntax'>
127
+ <span class="comment"># Skip frameworks you're not going to use (only works if using vendor/rails).</span>
128
+ <span class="comment"># To use Rails without a database, you must remove the Active Record framework</span>
129
+ <span class="ident">config</span><span class="punct">.</span><span class="ident">frameworks</span> <span class="punct">-=</span> <span class="punct">[</span> <span class="symbol">:active_record</span> <span class="punct">]</span>
130
+ </pre></li>
131
+ </ul>
132
+
133
+
134
+ <ul>
135
+ <li>Create some models! We&#8217;ll use an Author as an example:
136
+ <pre class='syntax'>
137
+ stone-gen model Author name:string
138
+ </pre></li>
139
+ </ul>
140
+
141
+
142
+ <h3 id="merb">Merb</h3>
143
+
144
+
145
+ <ul>
146
+ <li>Add the following code to your <code>init.rb</code> file:
147
+ <pre class='syntax'>
148
+ <span class="ident">dependency</span> <span class="punct">'</span><span class="string">stone</span><span class="punct">'</span>
149
+
150
+ <span class="comment"># add this in the Merb::BootLoader.after_app_loads block</span>
151
+ <span class="comment"># at the bottom of init.rb</span>
152
+ <span class="constant">Stone</span><span class="punct">.</span><span class="ident">start</span><span class="punct">(</span><span class="constant">Dir</span><span class="punct">.</span><span class="ident">pwd</span><span class="punct">,</span> <span class="constant">Dir</span><span class="punct">.</span><span class="ident">glob</span><span class="punct">(</span><span class="constant">File</span><span class="punct">.</span><span class="ident">join</span><span class="punct">(</span><span class="constant">Dir</span><span class="punct">.</span><span class="ident">pwd</span><span class="punct">,&quot;</span><span class="string">app/models/*</span><span class="punct">&quot;)),</span> <span class="symbol">:merb</span><span class="punct">)</span>
153
+ </pre></li>
154
+ </ul>
155
+
156
+
157
+ <ul>
158
+ <li>Create some models! We&#8217;ll use an Author as an example:
159
+ <pre class='syntax'>
160
+ stone-gen model Author name:string
161
+ </pre></li>
162
+ </ul>
163
+
164
+
165
+ <h3 id="everywhere">Everywhere Else</h3>
166
+
167
+
168
+ <p>Stone was designed to provide easy data storage management for <strong>any</strong>
169
+ app, not just web ones.</p>
170
+
171
+
172
+ <ul>
173
+ <li>Wherever you load your app, add the following:
174
+ <pre class='syntax'>
175
+ <span class="ident">require</span> <span class="punct">'</span><span class="string">stone</span><span class="punct">'</span>
176
+
177
+ <span class="comment"># replace path/to/models/ with wherever your models/resources may be</span>
178
+ <span class="constant">Stone</span><span class="punct">.</span><span class="ident">start</span><span class="punct">(</span><span class="constant">Dir</span><span class="punct">.</span><span class="ident">pwd</span><span class="punct">,</span> <span class="constant">Dir</span><span class="punct">.</span><span class="ident">glob</span><span class="punct">(</span><span class="constant">File</span><span class="punct">.</span><span class="ident">join</span><span class="punct">(</span><span class="constant">Dir</span><span class="punct">.</span><span class="ident">pwd</span><span class="punct">,&quot;</span><span class="string">path/to/models/*</span><span class="punct">&quot;)))</span>
179
+ </pre></li>
180
+ </ul>
181
+
182
+
183
+ <ul>
184
+ <li>Create some models! See <a href="#models">Models</a>.</li>
185
+ </ul>
186
+
187
+
188
+ <p>That&#8217;s it! Remember, there are no databases to install with Stone. Instead,
189
+ your data gets persisted to files within <code>myapp/datastore/</code>.</p>
190
+
191
+
192
+ <h2 id="usage">Usage</h2>
193
+
194
+
195
+ <h3 id="models">Model Files</h3>
196
+
197
+
198
+ <p>Models are really easy to create. Here is an example:
199
+ <pre class='syntax'>
200
+ <span class="keyword">class </span><span class="class">Person</span>
201
+ <span class="ident">include</span> <span class="constant">Stone</span><span class="punct">::</span><span class="constant">Resource</span> <span class="comment"># gives you access to persistence methods</span>
202
+
203
+ <span class="comment"># defines an attribute called &quot;name&quot; of type String</span>
204
+ <span class="ident">field</span> <span class="symbol">:name</span><span class="punct">,</span> <span class="constant">String</span>
205
+
206
+ <span class="comment"># defines an attribute called &quot;email&quot; of type String. </span>
207
+ <span class="comment"># Since :unique =&gt; true is set, &quot;email&quot; must be unique.</span>
208
+ <span class="ident">field</span> <span class="symbol">:email</span><span class="punct">,</span> <span class="constant">String</span><span class="punct">,</span> <span class="symbol">:unique</span> <span class="punct">=&gt;</span> <span class="constant">true</span>
209
+
210
+ <span class="comment"># Notifies Stone of a relationship between People and Jewels.</span>
211
+ <span class="comment"># This allows for @person.jewels retrieval.</span>
212
+ <span class="ident">has_many</span> <span class="symbol">:jewels</span>
213
+
214
+ <span class="comment"># both name and email must be present or errors will be added</span>
215
+ <span class="ident">validates_presence_of</span> <span class="symbol">:name</span><span class="punct">,</span> <span class="symbol">:email</span>
216
+ <span class="keyword">end</span>
217
+
218
+ </pre></p>
219
+
220
+
221
+ <p>For more validation methods, see <a href="http://validatable.rubyforge.org/classes/Validatable/Macros.html">here</a>.</p>
222
+
223
+
224
+ <h3 id="gppd">Get, Post, Put, and Delete</h3>
225
+
226
+
227
+ <ul>
228
+ <li>Getting
229
+ <pre class='syntax'>
230
+ <span class="constant">Author</span><span class="punct">.</span><span class="ident">get</span><span class="punct">(</span><span class="ident">some_id</span><span class="punct">)</span> <span class="comment"># gets Author with some_id</span>
231
+ <span class="constant">Author</span><span class="punct">[</span><span class="ident">some_id</span><span class="punct">]</span> <span class="comment"># same as get()</span>
232
+
233
+ <span class="comment"># brings back first author whose name is &quot;Nick DeMonner&quot;</span>
234
+ <span class="constant">Author</span><span class="punct">.</span><span class="ident">first</span><span class="punct">(</span><span class="symbol">:name</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">Nick DeMonner</span><span class="punct">&quot;)</span>
235
+
236
+ <span class="comment"># brings back first author whose name contains &quot;Nick&quot;</span>
237
+ <span class="constant">Author</span><span class="punct">.</span><span class="ident">first</span><span class="punct">(</span><span class="symbol">:name</span><span class="punct">.</span><span class="ident">includes</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">Nick</span><span class="punct">')</span>
238
+
239
+ <span class="comment"># brings back all authors whose email contains &quot;gmail.com&quot;, and who </span>
240
+ <span class="comment"># were created before today</span>
241
+ <span class="constant">Author</span><span class="punct">.</span><span class="ident">all</span><span class="punct">(</span><span class="symbol">:email</span><span class="punct">.</span><span class="ident">includes</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">gmail.com</span><span class="punct">&quot;,</span> <span class="symbol">:created_at</span><span class="punct">.</span><span class="ident">lt</span> <span class="punct">=&gt;</span> <span class="constant">DateTime</span><span class="punct">.</span><span class="ident">now</span><span class="punct">)</span>
242
+ </pre></li>
243
+ </ul>
244
+
245
+
246
+ <ul>
247
+ <li>Posting
248
+ <pre class='syntax'>
249
+ <span class="ident">author</span> <span class="punct">=</span> <span class="constant">Author</span><span class="punct">.</span><span class="ident">new</span>
250
+ <span class="ident">author</span><span class="punct">.</span><span class="ident">name</span> <span class="punct">=</span> <span class="punct">&quot;</span><span class="string">Nick DeMonner</span><span class="punct">&quot;</span>
251
+ <span class="ident">author</span><span class="punct">.</span><span class="ident">save</span> <span class="comment"># calls Author.post after validations</span>
252
+ </pre></li>
253
+ </ul>
254
+
255
+
256
+ <ul>
257
+ <li>Putting
258
+ <pre class='syntax'>
259
+ <span class="ident">author</span> <span class="punct">=</span> <span class="constant">Author</span><span class="punct">[</span><span class="ident">some_id</span><span class="punct">]</span> <span class="comment"># gets Author with id of some_id</span>
260
+
261
+ <span class="comment"># updates name and calls Resource.save (which in turn calls Resource.put </span>
262
+ <span class="comment"># because this resource is being updated, not created)</span>
263
+ <span class="ident">author</span><span class="punct">.</span><span class="ident">update_attributes</span><span class="punct">(</span><span class="symbol">:name</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">Bob Bobberson</span><span class="punct">&quot;)</span>
264
+ </pre></li>
265
+ </ul>
266
+
267
+
268
+ <ul>
269
+ <li>Deleting
270
+ <pre class='syntax'>
271
+ <span class="constant">Author</span><span class="punct">.</span><span class="ident">delete</span><span class="punct">(</span><span class="ident">some_id</span><span class="punct">)</span> <span class="comment"># deletes Author at some_id</span>
272
+ </pre></li>
273
+ </ul>
274
+
275
+
276
+ <h3 id="word">A Word About Finding Stuff</h3>
277
+
278
+
279
+ <p>Stone uses a series of unique methods (à la DataMapper) to finding objects.
280
+ You may use the following methods when searching:</p>
281
+
282
+
283
+ <ul>
284
+ <li>Matches all objects whose <code>field</code> is greater
285
+ than <code>thing</code>
286
+ <pre class='syntax'>
287
+ <span class="symbol">:field</span><span class="punct">.</span><span class="ident">gt</span> <span class="punct">=&gt;</span> <span class="ident">thing</span>
288
+ </pre></li>
289
+ </ul>
290
+
291
+
292
+ <ul>
293
+ <li>Matches all objects whose <code>field</code> is greater than
294
+ or equal to <code>thing</code>
295
+ <pre class='syntax'>
296
+ <span class="symbol">:field</span><span class="punct">.</span><span class="ident">gte</span> <span class="punct">=&gt;</span> <span class="ident">thing</span>
297
+ </pre></li>
298
+ </ul>
299
+
300
+
301
+ <ul>
302
+ <li>Matches all objects whose <code>field</code> is less than <code>thing</code>
303
+ <pre class='syntax'>
304
+ <span class="symbol">:field</span><span class="punct">.</span><span class="ident">lt</span> <span class="punct">=&gt;</span> <span class="ident">thing</span>
305
+ </pre></li>
306
+ </ul>
307
+
308
+
309
+ <ul>
310
+ <li>Matches all objects whose <code>field</code> is less than or
311
+ equal to <code>thing</code>
312
+ <pre class='syntax'>
313
+ <span class="symbol">:field</span><span class="punct">.</span><span class="ident">lte</span> <span class="punct">=&gt;</span> <span class="ident">thing</span>
314
+ </pre></li>
315
+ </ul>
316
+
317
+
318
+ <ul>
319
+ <li>Matches all objects whose <code>field</code> includes <code>thing</code>
320
+ <pre class='syntax'>
321
+ <span class="symbol">:field</span><span class="punct">.</span><span class="ident">includes</span> <span class="punct">=&gt;</span> <span class="ident">thing</span>
322
+ </pre></li>
323
+ </ul>
324
+
325
+
326
+ <ul>
327
+ <li>Matches all objects whose <code>field</code> is equal to <code>thing</code>
328
+ <pre class='syntax'>
329
+ <span class="symbol">:field</span><span class="punct">.</span><span class="ident">equals</span> <span class="punct">=&gt;</span> <span class="ident">thing</span>
330
+ </pre></li>
331
+ </ul>
332
+
333
+
334
+ <ul>
335
+ <li>Matches all objects whose <code>field</code> Regexp matches <code>thing</code>
336
+ <pre class='syntax'>
337
+ <span class="symbol">:field</span><span class="punct">.</span><span class="ident">matches</span> <span class="punct">=&gt;</span> <span class="ident">regexp</span>
338
+ </pre></li>
339
+ </ul>
340
+
341
+
342
+ <ul>
343
+ <li>Matches all objects whose <code>field</code> does not equal <code>thing</code>
344
+ <pre class='syntax'>
345
+ <span class="symbol">:field</span><span class="punct">.</span><span class="ident">not</span> <span class="punct">=&gt;</span> <span class="ident">thing</span>
346
+ </pre></li>
347
+ </ul>
348
+
349
+
350
+ <h2 id="license">License</h2>
351
+
352
+
353
+ <p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
354
+
355
+
356
+ <h2 id="contrib">Contributing</h2>
357
+
358
+
359
+ <p><span class="caps">PLEASE</span>. Stone is extremely immature at this point&#8212;&#8220;stable&#8221; is
360
+ the watchword for the moment.</p>
361
+
362
+
363
+ <ul>
364
+ <li>You can grab the source using Git:
365
+ <pre class='syntax'>
366
+ git clone git://github.com/ndemonner/stone.git
367
+ </pre></li>
368
+ </ul>
369
+
370
+
371
+ <p>The code is pretty well specced out, so make sure you don&#8217;t break anything
372
+ by running <code>rake ok</code> every once in a while.</p>
373
+
374
+
375
+ <p>Please add specs for any new functionality you might add, and hit me up to
376
+ commit. =D</p>
377
+
378
+
379
+ <h2 id="contact">Contact</h2>
380
+
381
+
382
+ <p>Comments are welcome. Join me in the <span class="caps">IRC</span> channel #stone on freenode.</p>
383
+ <p class="coda">
384
+ Nick DeMonner, 14th April 2008<br>
385
+ Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
386
+ </p>
387
+ </div>
388
+
389
+ <!-- insert site tracking codes here, like Google Urchin -->
390
+
391
+ </body>
392
+ </html>
data/website/index.txt ADDED
@@ -0,0 +1,245 @@
1
+ h1. Stone: Dead-Simple Data Persistence
2
+
3
+ h1. &#x2192; 'stone'
4
+
5
+ !images/stone.png!
6
+
7
+ h2. Sections
8
+
9
+ "What":#what
10
+
11
+ "Installing":#installing
12
+
13
+ "Getting Up and Running":#running
14
+ * "Rails":#rails
15
+ * "Merb":#merb
16
+ * "Everywhere Else":#everywhere
17
+
18
+ "Usage":#usage
19
+ * "Models":#models
20
+ * "Get, Post, Put, and Delete":#gppd
21
+
22
+ "A Word About Finding Stuff":#word
23
+
24
+ "License":#license
25
+
26
+ "Contributing":#contrib
27
+
28
+ "Contact":#contact
29
+ <br /><br />
30
+ h2(#what). What
31
+
32
+ For small applications, a database can be overkill for storing your data in a consistent and
33
+ organized manner. Therefore, Stone was built to provide plug-and-play data persistence for
34
+ any application or framework. It is fast, and it is easy... therefore it is good.
35
+
36
+ h2(#installing). Installing
37
+
38
+ <pre>sudo gem install stone</pre>
39
+
40
+ h2(#running). Up and Running
41
+
42
+ h3(#rails). Rails
43
+
44
+ * Create a new file in <code>config/initializers</code> called <code>stone.rb</code>
45
+
46
+ * Add the following code to your new file:
47
+ <pre syntax="ruby">
48
+ require 'stone'
49
+
50
+ Stone.start(Dir.pwd, Dir.glob(File.join(Dir.pwd,"app/models/*")), :rails)
51
+ </pre>
52
+
53
+ * Open your <code>environment.rb</code> file and look for the following lines:
54
+ <pre syntax="ruby">
55
+ # Skip frameworks you're not going to use (only works if using vendor/rails).
56
+ # To use Rails without a database, you must remove the Active Record framework
57
+ # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
58
+ </pre>
59
+
60
+ ** Uncomment the last of those lines, and leave only active_record,
61
+ so that it looks like this:
62
+ <pre syntax="ruby">
63
+ # Skip frameworks you're not going to use (only works if using vendor/rails).
64
+ # To use Rails without a database, you must remove the Active Record framework
65
+ config.frameworks -= [ :active_record ]
66
+ </pre>
67
+
68
+ * Create some models! We'll use an Author as an example:
69
+ <pre syntax="none">
70
+ stone-gen model Author name:string
71
+ </pre>
72
+
73
+ h3(#merb). Merb
74
+
75
+ * Add the following code to your <code>init.rb</code> file:
76
+ <pre syntax="ruby">
77
+ dependency 'stone'
78
+
79
+ # add this in the Merb::BootLoader.after_app_loads block
80
+ # at the bottom of init.rb
81
+ Stone.start(Dir.pwd, Dir.glob(File.join(Dir.pwd,"app/models/*")), :merb)
82
+ </pre>
83
+
84
+ * Create some models! We'll use an Author as an example:
85
+ <pre syntax="none">
86
+ stone-gen model Author name:string
87
+ </pre>
88
+
89
+ h3(#everywhere). Everywhere Else
90
+
91
+ Stone was designed to provide easy data storage management for <strong>any</strong>
92
+ app, not just web ones.
93
+
94
+ * Wherever you load your app, add the following:
95
+ <pre syntax="ruby">
96
+ require 'stone'
97
+
98
+ # replace path/to/models/ with wherever your models/resources may be
99
+ Stone.start(Dir.pwd, Dir.glob(File.join(Dir.pwd,"path/to/models/*")))
100
+ </pre>
101
+
102
+ * Create some models! See "Models":#models.
103
+
104
+ That's it! Remember, there are no databases to install with Stone. Instead,
105
+ your data gets persisted to files within <code>myapp/datastore/</code>.
106
+
107
+ h2(#usage). Usage
108
+
109
+ h3(#models). Model Files
110
+
111
+ Models are really easy to create. Here is an example:
112
+ <pre syntax="ruby">
113
+ class Person
114
+ include Stone::Resource # gives you access to persistence methods
115
+
116
+ # defines an attribute called "name" of type String
117
+ field :name, String
118
+
119
+ # defines an attribute called "email" of type String.
120
+ # Since :unique => true is set, "email" must be unique.
121
+ field :email, String, :unique => true
122
+
123
+ # Notifies Stone of a relationship between People and Jewels.
124
+ # This allows for @person.jewels retrieval.
125
+ has_many :jewels
126
+
127
+ # both name and email must be present or errors will be added
128
+ validates_presence_of :name, :email
129
+ end
130
+
131
+ </pre>
132
+
133
+ For more validation methods, see "here":http://validatable.rubyforge.org/classes/Validatable/Macros.html.
134
+
135
+ h3(#gppd). Get, Post, Put, and Delete
136
+
137
+ * Getting
138
+ <pre syntax="ruby">
139
+ Author.get(some_id) # gets Author with some_id
140
+ Author[some_id] # same as get()
141
+
142
+ # brings back first author whose name is "Nick DeMonner"
143
+ Author.first(:name => "Nick DeMonner")
144
+
145
+ # brings back first author whose name contains "Nick"
146
+ Author.first(:name.includes => 'Nick')
147
+
148
+ # brings back all authors whose email contains "gmail.com", and who
149
+ # were created before today
150
+ Author.all(:email.includes => "gmail.com", :created_at.lt => DateTime.now)
151
+ </pre>
152
+
153
+ * Posting
154
+ <pre syntax="ruby">
155
+ author = Author.new
156
+ author.name = "Nick DeMonner"
157
+ author.save # calls Author.post after validations
158
+ </pre>
159
+
160
+ * Putting
161
+ <pre syntax="ruby">
162
+ author = Author[some_id] # gets Author with id of some_id
163
+
164
+ # updates name and calls Resource.save (which in turn calls Resource.put
165
+ # because this resource is being updated, not created)
166
+ author.update_attributes(:name => "Bob Bobberson")
167
+ </pre>
168
+
169
+ * Deleting
170
+ <pre syntax="ruby">
171
+ Author.delete(some_id) # deletes Author at some_id
172
+ </pre>
173
+
174
+ h3(#word). A Word About Finding Stuff
175
+
176
+ Stone uses a series of unique methods (à la DataMapper) to finding objects.
177
+ You may use the following methods when searching:
178
+
179
+
180
+ * Matches all objects whose <code>field</code> is greater
181
+ than <code>thing</code>
182
+ <pre syntax="ruby">
183
+ :field.gt => thing
184
+ </pre>
185
+
186
+ * Matches all objects whose <code>field</code> is greater than
187
+ or equal to <code>thing</code>
188
+ <pre syntax="ruby">
189
+ :field.gte => thing
190
+ </pre>
191
+
192
+ * Matches all objects whose <code>field</code> is less than <code>thing</code>
193
+ <pre syntax="ruby">
194
+ :field.lt => thing
195
+ </pre>
196
+
197
+ * Matches all objects whose <code>field</code> is less than or
198
+ equal to <code>thing</code>
199
+ <pre syntax="ruby">
200
+ :field.lte => thing
201
+ </pre>
202
+
203
+ * Matches all objects whose <code>field</code> includes <code>thing</code>
204
+ <pre syntax="ruby">
205
+ :field.includes => thing
206
+ </pre>
207
+
208
+ * Matches all objects whose <code>field</code> is equal to <code>thing</code>
209
+ <pre syntax="ruby">
210
+ :field.equals => thing
211
+ </pre>
212
+
213
+ * Matches all objects whose <code>field</code> Regexp matches <code>thing</code>
214
+ <pre syntax="ruby">
215
+ :field.matches => regexp
216
+ </pre>
217
+
218
+ * Matches all objects whose <code>field</code> does not equal <code>thing</code>
219
+ <pre syntax="ruby">
220
+ :field.not => thing
221
+ </pre>
222
+
223
+ h2(#license). License
224
+
225
+ This code is free to use under the terms of the MIT license.
226
+
227
+ h2(#contrib). Contributing
228
+
229
+ PLEASE. Stone is extremely immature at this point -- "stable" is
230
+ the watchword for the moment.
231
+
232
+ * You can grab the source using Git:
233
+ <pre syntax="none">
234
+ git clone git://github.com/ndemonner/stone.git
235
+ </pre>
236
+
237
+ The code is pretty well specced out, so make sure you don't break anything
238
+ by running <code>rake ok</code> every once in a while.
239
+
240
+ Please add specs for any new functionality you might add, and hit me up to
241
+ commit. =D
242
+
243
+ h2(#contact). Contact
244
+
245
+ Comments are welcome. Join me in the IRC channel #stone on freenode.