baccigalupi-aqua 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardoc +0 -0
- data/Aqua.gemspec +20 -5
- data/README.rdoc +8 -4
- data/VERSION +1 -1
- data/doc/Aqua.html +1 -1
- data/doc/Aqua/Config.html +1 -1
- data/doc/Aqua/Config/ClassMethods.html +1 -1
- data/doc/Aqua/From.html +5 -5
- data/doc/Aqua/ObjectNotFound.html +1 -1
- data/doc/Aqua/Pack.html +1 -1
- data/doc/Aqua/Pack/ClassMethods.html +1 -1
- data/doc/Aqua/Pack/InstanceMethods.html +1 -1
- data/doc/Aqua/Query.html +1 -1
- data/doc/Aqua/Query/ClassMethods.html +1 -1
- data/doc/Aqua/Query/InstanceMethods.html +1 -1
- data/doc/Aqua/Storage.html +1 -1
- data/doc/Aqua/Store.html +1 -1
- data/doc/Aqua/Store/CouchDB.html +33 -33
- data/doc/Aqua/Store/CouchDB/Attachments.html +974 -0
- data/doc/Aqua/Store/CouchDB/Conflict.html +1 -1
- data/doc/Aqua/Store/CouchDB/Database.html +3 -3
- data/doc/Aqua/Store/CouchDB/DesignDocument.html +487 -0
- data/doc/Aqua/Store/CouchDB/RequestFailed.html +1 -1
- data/doc/Aqua/Store/CouchDB/RequestTimeout.html +1 -1
- data/doc/Aqua/Store/CouchDB/ResourceNotFound.html +1 -1
- data/doc/Aqua/Store/CouchDB/Server.html +1 -1
- data/doc/Aqua/Store/CouchDB/ServerBrokeConnection.html +1 -1
- data/doc/Aqua/Store/CouchDB/StorageMethods.html +1 -1
- data/doc/Aqua/Store/CouchDB/StorageMethods/ClassMethods.html +1 -1
- data/doc/Aqua/Store/CouchDB/StorageMethods/InstanceMethods.html +102 -2
- data/doc/Aqua/Stub.html +1 -1
- data/doc/Aqua/Tank.html +1 -1
- data/doc/Aqua/TempStub.html +1 -1
- data/doc/Aqua/To.html +10 -10
- data/doc/Aqua/Unpack.html +1 -1
- data/doc/Aqua/Unpack/ClassMethods.html +1 -1
- data/doc/Aqua/Unpack/InstanceMethods.html +1 -1
- data/doc/Array.html +13 -13
- data/doc/Bignum.html +5 -5
- data/doc/Date.html +5 -5
- data/doc/FalseClass.html +5 -5
- data/doc/Fixnum.html +5 -5
- data/doc/Float.html +5 -5
- data/doc/Hash.html +16 -16
- data/doc/OpenStruct.html +5 -5
- data/doc/README.rdoc.html +18 -10
- data/doc/Range.html +102 -0
- data/doc/Rational.html +9 -9
- data/doc/RestAPI.html +3 -3
- data/doc/RestClientAdapter.html +2 -2
- data/doc/Set.html +205 -0
- data/doc/Time.html +5 -5
- data/doc/TrueClass.html +5 -5
- data/doc/all-methods.html +126 -0
- data/doc/all-namespaces.html +8 -0
- data/doc/top-level-namespace.html +1 -1
- data/lib/aqua/object/pack.rb +1 -1
- data/lib/aqua/store/couch_db/attachments.rb +152 -0
- data/lib/aqua/store/couch_db/couch_db.rb +2 -0
- data/lib/aqua/store/couch_db/database.rb +1 -1
- data/lib/aqua/store/couch_db/design_document.rb +57 -0
- data/lib/aqua/store/couch_db/http_client/adapter/rest_client.rb +1 -1
- data/lib/aqua/store/couch_db/http_client/rest_api.rb +2 -2
- data/lib/aqua/store/couch_db/storage_methods.rb +12 -2
- data/lib/aqua/support/initializers.rb +12 -3
- data/lib/aqua/support/set.rb +27 -0
- data/spec/object/object_fixtures/sugar.rb +4 -0
- data/spec/object/pack_spec.rb +6 -0
- data/spec/object/unpack_spec.rb +18 -1
- data/spec/store/couchdb/attachments_spec.rb +127 -0
- data/spec/store/couchdb/design_document_spec.rb +43 -0
- data/spec/store/couchdb/{document_fixture.rb → fixtures_and_data/document_fixture.rb} +0 -0
- data/spec/store/couchdb/fixtures_and_data/image_attach.png +0 -0
- data/spec/store/couchdb/storage_methods_spec.rb +12 -4
- data/utils/custom.css +14 -0
- metadata +19 -4
data/doc/Time.html
CHANGED
@@ -68,12 +68,12 @@
|
|
68
68
|
<pre class="lines">
|
69
69
|
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
59
|
72
|
+
60
|
73
|
+
61</pre>
|
74
74
|
</td>
|
75
75
|
<td>
|
76
|
-
<pre class="code"><span class="info file"># File 'lib/aqua/support/initializers.rb', line
|
76
|
+
<pre class="code"><span class="info file"># File 'lib/aqua/support/initializers.rb', line 59</span>
|
77
77
|
|
78
78
|
<span class='def def kw'>def</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='aqua_init identifier id'>aqua_init</span><span class='lparen token'>(</span> <span class='init identifier id'>init</span> <span class='rparen token'>)</span>
|
79
79
|
<span class='parse identifier id'>parse</span><span class='lparen token'>(</span> <span class='init identifier id'>init</span> <span class='rparen token'>)</span>
|
@@ -93,7 +93,7 @@
|
|
93
93
|
</div>
|
94
94
|
</div>
|
95
95
|
<div id="yard_info">
|
96
|
-
Generated on
|
96
|
+
Generated on Monday, August 31 2009 at 03:23:22 PM by
|
97
97
|
<abbr class="yard" title="Yay! A Ruby Documentation Tool"><a href="http://yard.soen.ca">YARD</a></abbr>
|
98
98
|
0.2.3.5 (ruby-1.8.6).
|
99
99
|
</div>
|
data/doc/TrueClass.html
CHANGED
@@ -68,12 +68,12 @@
|
|
68
68
|
<pre class="lines">
|
69
69
|
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
41
|
72
|
+
42
|
73
|
+
43</pre>
|
74
74
|
</td>
|
75
75
|
<td>
|
76
|
-
<pre class="code"><span class="info file"># File 'lib/aqua/support/initializers.rb', line
|
76
|
+
<pre class="code"><span class="info file"># File 'lib/aqua/support/initializers.rb', line 41</span>
|
77
77
|
|
78
78
|
<span class='def def kw'>def</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='aqua_init identifier id'>aqua_init</span><span class='lparen token'>(</span> <span class='init identifier id'>init</span> <span class='rparen token'>)</span>
|
79
79
|
<span class='true true kw'>true</span>
|
@@ -93,7 +93,7 @@
|
|
93
93
|
</div>
|
94
94
|
</div>
|
95
95
|
<div id="yard_info">
|
96
|
-
Generated on
|
96
|
+
Generated on Monday, August 31 2009 at 03:23:17 PM by
|
97
97
|
<abbr class="yard" title="Yay! A Ruby Documentation Tool"><a href="http://yard.soen.ca">YARD</a></abbr>
|
98
98
|
0.2.3.5 (ruby-1.8.6).
|
99
99
|
</div>
|
data/doc/all-methods.html
CHANGED
@@ -211,6 +211,69 @@
|
|
211
211
|
|
212
212
|
</li>
|
213
213
|
|
214
|
+
<li nowrap="nowrap" class="">
|
215
|
+
<a href="Aqua/Store/CouchDB/Attachments.html#add-instance_method" title="#add">#add</a>
|
216
|
+
|
217
|
+
<em>(class Attachments)</em>
|
218
|
+
|
219
|
+
</li>
|
220
|
+
|
221
|
+
<li nowrap="nowrap" class="">
|
222
|
+
<a href="Aqua/Store/CouchDB/Attachments.html#add%21-instance_method" title="#add!">#add!</a>
|
223
|
+
|
224
|
+
<em>(class Attachments)</em>
|
225
|
+
|
226
|
+
</li>
|
227
|
+
|
228
|
+
<li nowrap="nowrap" class="">
|
229
|
+
<a href="Aqua/Store/CouchDB/Attachments.html#delete%21-instance_method" title="#delete!">#delete!</a>
|
230
|
+
|
231
|
+
<em>(class Attachments)</em>
|
232
|
+
|
233
|
+
</li>
|
234
|
+
|
235
|
+
<li nowrap="nowrap" class="">
|
236
|
+
<a href="Aqua/Store/CouchDB/Attachments.html#get-instance_method" title="#get">#get</a>
|
237
|
+
|
238
|
+
<em>(class Attachments)</em>
|
239
|
+
|
240
|
+
</li>
|
241
|
+
|
242
|
+
<li nowrap="nowrap" class="">
|
243
|
+
<a href="Aqua/Store/CouchDB/Attachments.html#get%21-instance_method" title="#get!">#get!</a>
|
244
|
+
|
245
|
+
<em>(class Attachments)</em>
|
246
|
+
|
247
|
+
</li>
|
248
|
+
|
249
|
+
<li nowrap="nowrap" class="">
|
250
|
+
<a href="Aqua/Store/CouchDB/Attachments.html#initialize-instance_method" title="#initialize">#initialize</a>
|
251
|
+
|
252
|
+
<em>(class Attachments)</em>
|
253
|
+
|
254
|
+
</li>
|
255
|
+
|
256
|
+
<li nowrap="nowrap" class="">
|
257
|
+
<a href="Aqua/Store/CouchDB/Attachments.html#update_doc_rev-instance_method" title="#update_doc_rev">#update_doc_rev</a>
|
258
|
+
|
259
|
+
<em>(class Attachments)</em>
|
260
|
+
|
261
|
+
</li>
|
262
|
+
|
263
|
+
<li nowrap="nowrap" class="">
|
264
|
+
<a href="Aqua/Store/CouchDB/Attachments.html#uri_for-instance_method" title="#uri_for">#uri_for</a>
|
265
|
+
|
266
|
+
<em>(class Attachments)</em>
|
267
|
+
|
268
|
+
</li>
|
269
|
+
|
270
|
+
<li nowrap="nowrap" class="">
|
271
|
+
<a href="Aqua/Store/CouchDB/Attachments.html#validate_hash-class_method" title="validate_hash">validate_hash</a>
|
272
|
+
|
273
|
+
<em>(class Attachments)</em>
|
274
|
+
|
275
|
+
</li>
|
276
|
+
|
214
277
|
<li nowrap="nowrap" class="">
|
215
278
|
<a href="Aqua/Store/CouchDB/Database.html#add_to_bulk_cache-instance_method" title="#add_to_bulk_cache">#add_to_bulk_cache</a>
|
216
279
|
|
@@ -295,6 +358,41 @@
|
|
295
358
|
|
296
359
|
</li>
|
297
360
|
|
361
|
+
<li nowrap="nowrap" class="">
|
362
|
+
<a href="Aqua/Store/CouchDB/DesignDocument.html#initialize-instance_method" title="#initialize">#initialize</a>
|
363
|
+
|
364
|
+
<em>(class DesignDocument)</em>
|
365
|
+
|
366
|
+
</li>
|
367
|
+
|
368
|
+
<li nowrap="nowrap" class="">
|
369
|
+
<a href="Aqua/Store/CouchDB/DesignDocument.html#name-instance_method" title="#name">#name</a>
|
370
|
+
|
371
|
+
<em>(class DesignDocument)</em>
|
372
|
+
|
373
|
+
</li>
|
374
|
+
|
375
|
+
<li nowrap="nowrap" class="">
|
376
|
+
<a href="Aqua/Store/CouchDB/DesignDocument.html#name%3D-instance_method" title="#name=">#name=</a>
|
377
|
+
|
378
|
+
<em>(class DesignDocument)</em>
|
379
|
+
|
380
|
+
</li>
|
381
|
+
|
382
|
+
<li nowrap="nowrap" class="">
|
383
|
+
<a href="Aqua/Store/CouchDB/DesignDocument.html#update_version-instance_method" title="#update_version">#update_version</a>
|
384
|
+
|
385
|
+
<em>(class DesignDocument)</em>
|
386
|
+
|
387
|
+
</li>
|
388
|
+
|
389
|
+
<li nowrap="nowrap" class="">
|
390
|
+
<a href="Aqua/Store/CouchDB/DesignDocument.html#uri-instance_method" title="#uri">#uri</a>
|
391
|
+
|
392
|
+
<em>(class DesignDocument)</em>
|
393
|
+
|
394
|
+
</li>
|
395
|
+
|
298
396
|
<li nowrap="nowrap" class="">
|
299
397
|
<a href="Aqua/Store/CouchDB/Server.html#database-instance_method" title="#database">#database</a>
|
300
398
|
|
@@ -407,6 +505,13 @@
|
|
407
505
|
|
408
506
|
</li>
|
409
507
|
|
508
|
+
<li nowrap="nowrap" class="">
|
509
|
+
<a href="Aqua/Store/CouchDB/StorageMethods/InstanceMethods.html#attachments-instance_method" title="#attachments">#attachments</a>
|
510
|
+
|
511
|
+
<em>(module InstanceMethods)</em>
|
512
|
+
|
513
|
+
</li>
|
514
|
+
|
410
515
|
<li nowrap="nowrap" class="">
|
411
516
|
<a href="Aqua/Store/CouchDB/StorageMethods/InstanceMethods.html#commit-instance_method" title="#commit">#commit</a>
|
412
517
|
|
@@ -806,6 +911,13 @@
|
|
806
911
|
|
807
912
|
</li>
|
808
913
|
|
914
|
+
<li nowrap="nowrap" class="">
|
915
|
+
<a href="Range.html#aqua_init-class_method" title="aqua_init">aqua_init</a>
|
916
|
+
|
917
|
+
<em>(class Range)</em>
|
918
|
+
|
919
|
+
</li>
|
920
|
+
|
809
921
|
<li nowrap="nowrap" class="">
|
810
922
|
<a href="Rational.html#to_aqua_init-instance_method" title="#to_aqua_init">#to_aqua_init</a>
|
811
923
|
|
@@ -911,6 +1023,20 @@
|
|
911
1023
|
|
912
1024
|
</li>
|
913
1025
|
|
1026
|
+
<li nowrap="nowrap" class="">
|
1027
|
+
<a href="Set.html#to_aqua-instance_method" title="#to_aqua">#to_aqua</a>
|
1028
|
+
|
1029
|
+
<em>(class Set)</em>
|
1030
|
+
|
1031
|
+
</li>
|
1032
|
+
|
1033
|
+
<li nowrap="nowrap" class="">
|
1034
|
+
<a href="Set.html#to_aqua_init-instance_method" title="#to_aqua_init">#to_aqua_init</a>
|
1035
|
+
|
1036
|
+
<em>(class Set)</em>
|
1037
|
+
|
1038
|
+
</li>
|
1039
|
+
|
914
1040
|
<li nowrap="nowrap" class="">
|
915
1041
|
<a href="Time.html#aqua_init-class_method" title="aqua_init">aqua_init</a>
|
916
1042
|
|
data/doc/all-namespaces.html
CHANGED
@@ -44,10 +44,14 @@
|
|
44
44
|
|
45
45
|
<li class=""><a href="Aqua/Store/CouchDB.html" title="Aqua::Store::CouchDB">Aqua::Store::CouchDB</a> <em>(module)</em></li>
|
46
46
|
|
47
|
+
<li class=""><a href="Aqua/Store/CouchDB/Attachments.html" title="Aqua::Store::CouchDB::Attachments">Aqua::Store::CouchDB::Attachments</a> <em>(class)</em></li>
|
48
|
+
|
47
49
|
<li class=""><a href="Aqua/Store/CouchDB/Conflict.html" title="Aqua::Store::CouchDB::Conflict">Aqua::Store::CouchDB::Conflict</a> <em>(class)</em></li>
|
48
50
|
|
49
51
|
<li class=""><a href="Aqua/Store/CouchDB/Database.html" title="Aqua::Store::CouchDB::Database">Aqua::Store::CouchDB::Database</a> <em>(class)</em></li>
|
50
52
|
|
53
|
+
<li class=""><a href="Aqua/Store/CouchDB/DesignDocument.html" title="Aqua::Store::CouchDB::DesignDocument">Aqua::Store::CouchDB::DesignDocument</a> <em>(class)</em></li>
|
54
|
+
|
51
55
|
<li class=""><a href="Aqua/Store/CouchDB/RequestFailed.html" title="Aqua::Store::CouchDB::RequestFailed">Aqua::Store::CouchDB::RequestFailed</a> <em>(class)</em></li>
|
52
56
|
|
53
57
|
<li class=""><a href="Aqua/Store/CouchDB/RequestTimeout.html" title="Aqua::Store::CouchDB::RequestTimeout">Aqua::Store::CouchDB::RequestTimeout</a> <em>(class)</em></li>
|
@@ -94,12 +98,16 @@
|
|
94
98
|
|
95
99
|
<li class=""><a href="OpenStruct.html" title="OpenStruct">OpenStruct</a> <em>(class)</em></li>
|
96
100
|
|
101
|
+
<li class=""><a href="Range.html" title="Range">Range</a> <em>(class)</em></li>
|
102
|
+
|
97
103
|
<li class=""><a href="Rational.html" title="Rational">Rational</a> <em>(class)</em></li>
|
98
104
|
|
99
105
|
<li class=""><a href="RestAPI.html" title="RestAPI">RestAPI</a> <em>(module)</em></li>
|
100
106
|
|
101
107
|
<li class=""><a href="RestClientAdapter.html" title="RestClientAdapter">RestClientAdapter</a> <em>(module)</em></li>
|
102
108
|
|
109
|
+
<li class=""><a href="Set.html" title="Set">Set</a> <em>(class)</em></li>
|
110
|
+
|
103
111
|
<li class=""><a href="Time.html" title="Time">Time</a> <em>(class)</em></li>
|
104
112
|
|
105
113
|
<li class=""><a href="TrueClass.html" title="TrueClass">TrueClass</a> <em>(class)</em></li>
|
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
</div>
|
18
18
|
<div id="yard_info">
|
19
|
-
Generated on
|
19
|
+
Generated on Monday, August 31 2009 at 03:23:22 PM by
|
20
20
|
<abbr class="yard" title="Yay! A Ruby Documentation Tool"><a href="http://yard.soen.ca">YARD</a></abbr>
|
21
21
|
0.2.3.5 (ruby-1.8.6).
|
22
22
|
</div>
|
data/lib/aqua/object/pack.rb
CHANGED
@@ -212,7 +212,7 @@ module Aqua::Pack
|
|
212
212
|
index = self.__pack[:stubs].length
|
213
213
|
stub = { :class => obj.class.to_s, :id => obj }
|
214
214
|
# deal with cached methods
|
215
|
-
if obj._embed_me.keys && stub_methods = obj._embed_me[:stub]
|
215
|
+
if obj._embed_me && obj._embed_me.keys && stub_methods = obj._embed_me[:stub]
|
216
216
|
stub[:methods] = {}
|
217
217
|
if stub_methods.class == Symbol || stub_methods.class == String
|
218
218
|
stub_method = stub_methods.to_sym
|
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'mime/types'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
module Aqua
|
5
|
+
module Store
|
6
|
+
module CouchDB
|
7
|
+
# Attachments is a Hash-like container with keys that are attacment names and values that are file-type
|
8
|
+
# objects. Initializing and adding to the collection assures the types of both keys and values. The
|
9
|
+
# collection implements a lazy-loading scheme, such that when an attachment is requested and not found,
|
10
|
+
# it will try to load it from CouchDB.
|
11
|
+
class Attachments < Mash
|
12
|
+
attr_reader :document
|
13
|
+
attr_reader :stub
|
14
|
+
|
15
|
+
# Creates a new attachment collection with keys that are attachment names and values that are
|
16
|
+
# file-type objects. The collection manages both the key and the value types.
|
17
|
+
#
|
18
|
+
# @param [String] Document uri; used to save and retrieve attachments directly
|
19
|
+
# @param [Hash] Initialization values
|
20
|
+
#
|
21
|
+
# @api public
|
22
|
+
def initialize( doc, hash={} )
|
23
|
+
raise ArgumentError, "must be initialized with a document" unless doc.respond_to?( :retrieve )
|
24
|
+
@document = doc
|
25
|
+
self.class.validate_hash( hash ) unless hash.empty?
|
26
|
+
super( hash )
|
27
|
+
end
|
28
|
+
|
29
|
+
# Adds an attachment to the collection, checking for type. Does not add directly to the database.
|
30
|
+
#
|
31
|
+
# @param [String, Symbol] Name of the attachment as a string or symbol
|
32
|
+
# @param [File] The attachment
|
33
|
+
#
|
34
|
+
# @api public
|
35
|
+
def add( name, file )
|
36
|
+
self.class.validate_hash( name => file )
|
37
|
+
self[name] = file
|
38
|
+
end
|
39
|
+
|
40
|
+
# Adds an attachment to the collection and to the database. Document doesn't have to be saved,
|
41
|
+
# but it does need to have an id.
|
42
|
+
#
|
43
|
+
# @param [String, Symbol] Name of the attachment as a string or symbol
|
44
|
+
# @param [File] The attachment
|
45
|
+
#
|
46
|
+
# @api public
|
47
|
+
def add!( name, file )
|
48
|
+
add( name, file )
|
49
|
+
content_type = MIME::Types.type_for(file.path)
|
50
|
+
content_type = content_type.empty? ? 'text\/plain' : content_type
|
51
|
+
data = {
|
52
|
+
'content-type' => content_type,
|
53
|
+
'data' => Base64.encode64( file.read ).gsub(/\s/,'')
|
54
|
+
}
|
55
|
+
response = CouchDB.put( uri_for( name ), data )
|
56
|
+
update_doc_rev( response )
|
57
|
+
file
|
58
|
+
end
|
59
|
+
|
60
|
+
# Deletes an attachment from the collection, and from the database. Use #delete (from Hash) to just
|
61
|
+
# delete the attachment from the collection.
|
62
|
+
#
|
63
|
+
# @param [String, Symbol] Name of the attachment as a string or symbol
|
64
|
+
# @return [File, nil] File at that location or nil if no file found
|
65
|
+
#
|
66
|
+
# @api public
|
67
|
+
def delete!( name )
|
68
|
+
if self[name]
|
69
|
+
file = delete( name )
|
70
|
+
unless document.new?
|
71
|
+
CouchDB.delete( uri_for( name ) )
|
72
|
+
end
|
73
|
+
file
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Gets an attachment from the collection first. If not found, it will be requested from the database.
|
78
|
+
#
|
79
|
+
# @param [String, Symbol] Name of the attachment
|
80
|
+
# @return [File, nil] File for that name, or nil if not found in hash or in database
|
81
|
+
#
|
82
|
+
# @api public
|
83
|
+
def get( name, stream=false )
|
84
|
+
file = self[name]
|
85
|
+
unless file
|
86
|
+
file = get!( name, stream )
|
87
|
+
end
|
88
|
+
file
|
89
|
+
end
|
90
|
+
|
91
|
+
# Gets an attachment from the database. Stores it in the hash.
|
92
|
+
#
|
93
|
+
# @param [String, Symbol] Name of the attachment
|
94
|
+
# @param [true, false] Stream boolean flag indicating whether the data should be converted to
|
95
|
+
# a file or kept as a stream
|
96
|
+
# @return [File, nil] File for that name, or nil if not found in the database
|
97
|
+
# @raise Any error encountered on retrieval of the attachment, json, http_client, Aqua etc
|
98
|
+
#
|
99
|
+
# @todo make this more memory favorable, maybe streaming/saving in a max number of bytes
|
100
|
+
# @api public
|
101
|
+
def get!( name, stream=false )
|
102
|
+
file = nil
|
103
|
+
response = CouchDB.get( uri_for( name, false ) ) rescue nil
|
104
|
+
data = Base64.decode64( response['data'] ) if response
|
105
|
+
if data
|
106
|
+
file = Tempfile.new( CGI.escape( name.to_s ) )
|
107
|
+
file.binmode if file.respond_to?( :binmode )
|
108
|
+
file.write( data )
|
109
|
+
file.rewind
|
110
|
+
self[name] = file
|
111
|
+
end
|
112
|
+
stream ? file.read : file
|
113
|
+
end
|
114
|
+
|
115
|
+
# Constructs the standalone attachment uri for PUT and DELETE actions.
|
116
|
+
#
|
117
|
+
# @param [String] Name of the attachment as a string or symbol
|
118
|
+
#
|
119
|
+
# @api private
|
120
|
+
def uri_for( name, include_rev = true )
|
121
|
+
raise ArgumentError, 'Document must have id in order to save an attachment' if document.id.nil? || document.id.empty?
|
122
|
+
document.uri + "/#{CGI.escape( name.to_s )}" + ( document.rev && include_rev ? "?rev=#{document.rev}" : "" )
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
# Validates and throws an error on a hash, insisting that the key is a string or symbol,
|
127
|
+
# and the value is a file.
|
128
|
+
#
|
129
|
+
# @param [Hash]
|
130
|
+
#
|
131
|
+
# @api private
|
132
|
+
def self.validate_hash( hash )
|
133
|
+
hash.each do |name, file|
|
134
|
+
raise ArgumentError, "Attachment name, #{name.inspect}, must be a Symbol or a String" unless [Symbol, String ].include?( name.class )
|
135
|
+
raise ArgumentError, "Attachment file, #{file.inspect}, must be a File-like object" unless file.respond_to?( :read )
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# Goes into the document and updates it's rev to match the returned rev. That way #new? will return false
|
140
|
+
# when an attachment is created before the document is saved. It also means that future attempts to save
|
141
|
+
# the doc won't fail with a conflict.
|
142
|
+
#
|
143
|
+
# @param [Hash] response from the put request
|
144
|
+
# @api private
|
145
|
+
def update_doc_rev( response )
|
146
|
+
document[:_rev] = response['rev']
|
147
|
+
end
|
148
|
+
|
149
|
+
end # Attachments
|
150
|
+
end # CouchDB
|
151
|
+
end # Store
|
152
|
+
end # Aqua
|
@@ -1,7 +1,9 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/http_client/rest_api'
|
2
2
|
require File.dirname(__FILE__) + '/server'
|
3
3
|
require File.dirname(__FILE__) + '/database'
|
4
|
+
require File.dirname(__FILE__) + '/attachments'
|
4
5
|
require File.dirname(__FILE__) + '/storage_methods'
|
6
|
+
require File.dirname(__FILE__) + '/design_document'
|
5
7
|
|
6
8
|
module Aqua
|
7
9
|
module Store
|
@@ -146,7 +146,7 @@ module Aqua
|
|
146
146
|
CouchDB.delete( uri )
|
147
147
|
end
|
148
148
|
|
149
|
-
# # Query the <tt>
|
149
|
+
# # Query the <tt>documents</tt> view. Accepts all the same arguments as view.
|
150
150
|
def documents(params = {})
|
151
151
|
keys = params.delete(:keys)
|
152
152
|
url = CouchDB.paramify_url( "#{uri}/_all_docs", params )
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Design documents are responsible for saving views. It is also the place that Aqua will
|
2
|
+
# be saving the Class code. There will be one design document per class. There may be additional
|
3
|
+
# design documents created without being tied to a class. Don't know yet.
|
4
|
+
module Aqua
|
5
|
+
module Store
|
6
|
+
module CouchDB
|
7
|
+
class DesignDocument < Mash
|
8
|
+
|
9
|
+
# the DesignDocument is essentially a special type of Document.
|
10
|
+
include Aqua::Store::CouchDB::StorageMethods
|
11
|
+
|
12
|
+
# In the design document the name is the same as the id. That way initialization can
|
13
|
+
# include a name parameter, which will change the id, and therefore the address of the
|
14
|
+
# document. This method returns the id.
|
15
|
+
# @return [String] id for document
|
16
|
+
# @api public
|
17
|
+
def name
|
18
|
+
id
|
19
|
+
end
|
20
|
+
|
21
|
+
# Sets the id and is an alias for id=.
|
22
|
+
# @param [String] Unique identifier
|
23
|
+
# @return [String] Escaped identifier
|
24
|
+
# @api public
|
25
|
+
def name=( n )
|
26
|
+
self.id = ( n )
|
27
|
+
end
|
28
|
+
|
29
|
+
alias :document_initialize :initialize
|
30
|
+
|
31
|
+
def initialize( hash={} )
|
32
|
+
hash = Mash.new( hash ) unless hash.empty?
|
33
|
+
self.id = hash.delete(:name) if hash[:name]
|
34
|
+
document_initialize( hash )
|
35
|
+
end
|
36
|
+
|
37
|
+
# couchdb database url for the design document
|
38
|
+
# @return [String] representing CouchDB uri for document
|
39
|
+
# @api public
|
40
|
+
def uri
|
41
|
+
raise ArgumentError, 'DesignDocument must have a name' if name.nil? || name.empty?
|
42
|
+
database.uri + '/_design/' + name
|
43
|
+
end
|
44
|
+
|
45
|
+
# Updates the id and rev after a design document is successfully saved. The _design/
|
46
|
+
# portion of the id has to be stripped.
|
47
|
+
# @param [Hash] Result returned by CouchDB document save
|
48
|
+
# @api private
|
49
|
+
def update_version( result )
|
50
|
+
self.id = result['id'].gsub(/\A_design\//, '')
|
51
|
+
self.rev = result['rev']
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|