mattly-couchrest 0.12.2 → 0.12.6
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.
- data/Rakefile +1 -4
- data/examples/word_count/word_count_views.rb +26 -0
- data/lib/couchrest.rb +1 -2
- data/lib/couchrest/core/database.rb +22 -8
- data/lib/couchrest/core/model.rb +7 -1
- data/spec/couchrest/core/database_spec.rb +31 -0
- metadata +5 -14
- data/bin/couchdir +0 -20
data/Rakefile
CHANGED
|
@@ -25,16 +25,13 @@ spec = Gem::Specification.new do |s|
|
|
|
25
25
|
s.has_rdoc = true
|
|
26
26
|
s.authors = ["J. Chris Anderson"]
|
|
27
27
|
s.files = %w( LICENSE README.md Rakefile THANKS.md ) +
|
|
28
|
-
Dir["{
|
|
28
|
+
Dir["{examples,lib,spec,utils}/**/*"] -
|
|
29
29
|
Dir["spec/tmp"]
|
|
30
30
|
s.extra_rdoc_files = %w( README.md LICENSE THANKS.md )
|
|
31
31
|
s.require_path = "lib"
|
|
32
|
-
s.bindir = 'bin'
|
|
33
|
-
s.executables << 'couchdir'
|
|
34
32
|
s.add_dependency("json", ">= 1.1.2")
|
|
35
33
|
s.add_dependency("rest-client", ">= 0.5")
|
|
36
34
|
s.add_dependency("mime-types", ">= 1.15")
|
|
37
|
-
s.add_dependency("extlib", ">= 0.9.6")
|
|
38
35
|
end
|
|
39
36
|
|
|
40
37
|
desc "create .gemspec file (useful for github)"
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'couchrest'
|
|
3
|
+
|
|
4
|
+
couch = CouchRest.new("http://127.0.0.1:5984")
|
|
5
|
+
db = couch.database('word-count-example')
|
|
6
|
+
|
|
7
|
+
word_count = {
|
|
8
|
+
:map => 'function(doc){
|
|
9
|
+
var words = doc.text.split(/\W/);
|
|
10
|
+
words.forEach(function(word){
|
|
11
|
+
if (word.length > 0) emit([word,doc.title],1);
|
|
12
|
+
});
|
|
13
|
+
}',
|
|
14
|
+
:reduce => 'function(key,combine){
|
|
15
|
+
return sum(combine);
|
|
16
|
+
}'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
db.delete db.get("_design/word_count") rescue nil
|
|
20
|
+
|
|
21
|
+
db.save({
|
|
22
|
+
"_id" => "_design/word_count",
|
|
23
|
+
:views => {
|
|
24
|
+
:words => word_count
|
|
25
|
+
}
|
|
26
|
+
})
|
data/lib/couchrest.rb
CHANGED
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
require "rubygems"
|
|
16
16
|
require 'json'
|
|
17
17
|
require 'rest_client'
|
|
18
|
-
# require 'extlib'
|
|
19
18
|
|
|
20
19
|
$:.unshift File.dirname(__FILE__) unless
|
|
21
20
|
$:.include?(File.dirname(__FILE__)) ||
|
|
@@ -26,7 +25,7 @@ require 'couchrest/monkeypatches'
|
|
|
26
25
|
|
|
27
26
|
# = CouchDB, close to the metal
|
|
28
27
|
module CouchRest
|
|
29
|
-
VERSION = '0.12.
|
|
28
|
+
VERSION = '0.12.6'
|
|
30
29
|
|
|
31
30
|
autoload :Server, 'couchrest/core/server'
|
|
32
31
|
autoload :Database, 'couchrest/core/database'
|
|
@@ -50,7 +50,7 @@ module CouchRest
|
|
|
50
50
|
def slow_view funcs, params = {}
|
|
51
51
|
keys = params.delete(:keys)
|
|
52
52
|
funcs = funcs.merge({:keys => keys}) if keys
|
|
53
|
-
url = CouchRest.paramify_url "#{@root}/
|
|
53
|
+
url = CouchRest.paramify_url "#{@root}/_temp_view", params
|
|
54
54
|
JSON.parse(RestClient.post(url, funcs.to_json, {"Content-Type" => 'application/json'}))
|
|
55
55
|
end
|
|
56
56
|
|
|
@@ -149,16 +149,18 @@ module CouchRest
|
|
|
149
149
|
# missing ids, supply one from the uuid cache.
|
|
150
150
|
#
|
|
151
151
|
# If called with no arguments, bulk saves the cache of documents to be bulk saved.
|
|
152
|
-
def bulk_save
|
|
152
|
+
def bulk_save(docs = nil, use_uuids = true)
|
|
153
153
|
if docs.nil?
|
|
154
154
|
docs = @bulk_save_cache
|
|
155
155
|
@bulk_save_cache = []
|
|
156
156
|
end
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
157
|
+
if (use_uuids)
|
|
158
|
+
ids, noids = docs.partition{|d|d['_id']}
|
|
159
|
+
uuid_count = [noids.length, @server.uuid_batch_count].max
|
|
160
|
+
noids.each do |doc|
|
|
161
|
+
nextid = @server.next_uuid(uuid_count) rescue nil
|
|
162
|
+
doc['_id'] = nextid if nextid
|
|
163
|
+
end
|
|
162
164
|
end
|
|
163
165
|
CouchRest.post "#{@root}/_bulk_docs", {:docs => docs}
|
|
164
166
|
end
|
|
@@ -211,7 +213,19 @@ module CouchRest
|
|
|
211
213
|
def compact!
|
|
212
214
|
CouchRest.post "#{@root}/_compact"
|
|
213
215
|
end
|
|
214
|
-
|
|
216
|
+
|
|
217
|
+
# Replicates via "pulling" from another database to this database. Makes no attempt to deal with conflicts.
|
|
218
|
+
def replicate_from other_db
|
|
219
|
+
raise ArgumentError, "must provide a CouchReset::Database" unless other_db.kind_of?(CouchRest::Database)
|
|
220
|
+
CouchRest.post "#{@host}/_replicate", :source => other_db.root, :target => name
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
# Replicates via "pushing" to another database. Makes no attempt to deal with conflicts.
|
|
224
|
+
def replicate_to other_db
|
|
225
|
+
raise ArgumentError, "must provide a CouchReset::Database" unless other_db.kind_of?(CouchRest::Database)
|
|
226
|
+
CouchRest.post "#{@host}/_replicate", :target => other_db.root, :source => name
|
|
227
|
+
end
|
|
228
|
+
|
|
215
229
|
# DELETE the database itself. This is not undoable and could be rather
|
|
216
230
|
# catastrophic. Use with care!
|
|
217
231
|
def delete!
|
data/lib/couchrest/core/model.rb
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
require 'rubygems'
|
|
2
|
-
|
|
2
|
+
begin
|
|
3
|
+
require 'extlib'
|
|
4
|
+
rescue
|
|
5
|
+
puts "CouchRest::Model requires extlib. This is left out of the gemspec on purpose."
|
|
6
|
+
raise
|
|
7
|
+
end
|
|
3
8
|
require 'digest/md5'
|
|
4
9
|
require File.dirname(__FILE__) + '/document'
|
|
5
10
|
require 'mime/types'
|
|
@@ -439,6 +444,7 @@ module CouchRest
|
|
|
439
444
|
saved['views'][name] = view
|
|
440
445
|
end
|
|
441
446
|
database.save(saved)
|
|
447
|
+
self.design_doc = saved
|
|
442
448
|
else
|
|
443
449
|
design_doc['_id'] = did
|
|
444
450
|
design_doc.delete('_rev')
|
|
@@ -624,6 +624,37 @@ describe CouchRest::Database do
|
|
|
624
624
|
@cr.databases.should_not include('couchrest-test')
|
|
625
625
|
end
|
|
626
626
|
end
|
|
627
|
+
|
|
628
|
+
describe "replicating a database" do
|
|
629
|
+
before do
|
|
630
|
+
@db.save({'_id' => 'test_doc', 'some-value' => 'foo'})
|
|
631
|
+
@other_db = @cr.database 'couchrest-test-replication'
|
|
632
|
+
@other_db.delete! rescue nil
|
|
633
|
+
@other_db = @cr.create_db 'couchrest-test-replication'
|
|
634
|
+
end
|
|
635
|
+
|
|
636
|
+
describe "via pulling" do
|
|
637
|
+
before do
|
|
638
|
+
@other_db.replicate_from @db
|
|
639
|
+
end
|
|
640
|
+
|
|
641
|
+
it "contains the document from the original database" do
|
|
642
|
+
doc = @other_db.get('test_doc')
|
|
643
|
+
doc['some-value'].should == 'foo'
|
|
644
|
+
end
|
|
645
|
+
end
|
|
646
|
+
|
|
647
|
+
describe "via pushing" do
|
|
648
|
+
before do
|
|
649
|
+
@db.replicate_to @other_db
|
|
650
|
+
end
|
|
651
|
+
|
|
652
|
+
it "copies the document to the other database" do
|
|
653
|
+
doc = @other_db.get('test_doc')
|
|
654
|
+
doc['some-value'].should == 'foo'
|
|
655
|
+
end
|
|
656
|
+
end
|
|
657
|
+
end
|
|
627
658
|
|
|
628
659
|
|
|
629
660
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mattly-couchrest
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.12.
|
|
4
|
+
version: 0.12.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- J. Chris Anderson
|
|
@@ -10,7 +10,7 @@ bindir: bin
|
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
12
|
date: 2008-11-22 00:00:00 -08:00
|
|
13
|
-
default_executable:
|
|
13
|
+
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: json
|
|
@@ -39,19 +39,10 @@ dependencies:
|
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: "1.15"
|
|
41
41
|
version:
|
|
42
|
-
- !ruby/object:Gem::Dependency
|
|
43
|
-
name: extlib
|
|
44
|
-
version_requirement:
|
|
45
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
46
|
-
requirements:
|
|
47
|
-
- - ">="
|
|
48
|
-
- !ruby/object:Gem::Version
|
|
49
|
-
version: 0.9.6
|
|
50
|
-
version:
|
|
51
42
|
description: CouchRest provides a simple interface on top of CouchDB's RESTful HTTP API, as well as including some utility scripts for managing views and attachments.
|
|
52
43
|
email: jchris@apache.org
|
|
53
|
-
executables:
|
|
54
|
-
|
|
44
|
+
executables: []
|
|
45
|
+
|
|
55
46
|
extensions: []
|
|
56
47
|
|
|
57
48
|
extra_rdoc_files:
|
|
@@ -63,7 +54,6 @@ files:
|
|
|
63
54
|
- README.md
|
|
64
55
|
- Rakefile
|
|
65
56
|
- THANKS.md
|
|
66
|
-
- bin/couchdir
|
|
67
57
|
- examples/model
|
|
68
58
|
- examples/model/example.rb
|
|
69
59
|
- examples/word_count
|
|
@@ -80,6 +70,7 @@ files:
|
|
|
80
70
|
- examples/word_count/views/word_count/count-reduce.js
|
|
81
71
|
- examples/word_count/word_count.rb
|
|
82
72
|
- examples/word_count/word_count_query.rb
|
|
73
|
+
- examples/word_count/word_count_views.rb
|
|
83
74
|
- lib/couchrest
|
|
84
75
|
- lib/couchrest/commands
|
|
85
76
|
- lib/couchrest/commands/generate.rb
|
data/bin/couchdir
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
unless ARGV.length >= 2
|
|
4
|
-
puts "usage: couchdir path/to/directory db-name [docid]"
|
|
5
|
-
exit
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
require 'rubygems'
|
|
9
|
-
require 'couchrest'
|
|
10
|
-
|
|
11
|
-
dirname = ARGV[0]
|
|
12
|
-
dbname = ARGV[1]
|
|
13
|
-
docid = ARGV[2]
|
|
14
|
-
|
|
15
|
-
puts "Create attachments for the files in #{dirname} in database #{dbname}."
|
|
16
|
-
|
|
17
|
-
fm = CouchRest::FileManager.new(dbname)
|
|
18
|
-
fm.loud = true
|
|
19
|
-
puts "Pushing views from directory #{dirname} to database #{fm.db}"
|
|
20
|
-
fm.push_directory(dirname, docid)
|