juozasg-couchrest 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +176 -0
- data/README.rdoc +67 -0
- data/Rakefile +86 -0
- data/THANKS +15 -0
- data/bin/couchapp +58 -0
- data/bin/couchdir +20 -0
- data/bin/couchview +48 -0
- data/examples/model/example.rb +138 -0
- data/examples/word_count/markov +38 -0
- data/examples/word_count/views/books/chunked-map.js +3 -0
- data/examples/word_count/views/books/united-map.js +1 -0
- data/examples/word_count/views/markov/chain-map.js +6 -0
- data/examples/word_count/views/markov/chain-reduce.js +7 -0
- data/examples/word_count/views/word_count/count-map.js +6 -0
- data/examples/word_count/views/word_count/count-reduce.js +3 -0
- data/examples/word_count/word_count.rb +67 -0
- data/examples/word_count/word_count_query.rb +39 -0
- data/lib/couchrest/commands/generate.rb +71 -0
- data/lib/couchrest/commands/push.rb +103 -0
- data/lib/couchrest/core/database.rb +173 -0
- data/lib/couchrest/core/design.rb +89 -0
- data/lib/couchrest/core/document.rb +60 -0
- data/lib/couchrest/core/model.rb +557 -0
- data/lib/couchrest/core/server.rb +51 -0
- data/lib/couchrest/core/view.rb +4 -0
- data/lib/couchrest/helper/file_manager.rb +317 -0
- data/lib/couchrest/helper/pager.rb +103 -0
- data/lib/couchrest/helper/streamer.rb +44 -0
- data/lib/couchrest/helper/templates/bar.txt +11 -0
- data/lib/couchrest/helper/templates/example-map.js +8 -0
- data/lib/couchrest/helper/templates/example-reduce.js +10 -0
- data/lib/couchrest/helper/templates/index.html +26 -0
- data/lib/couchrest/monkeypatches.rb +24 -0
- data/lib/couchrest.rb +125 -0
- data/spec/couchapp_spec.rb +87 -0
- data/spec/couchrest/core/couchrest_spec.rb +191 -0
- data/spec/couchrest/core/database_spec.rb +478 -0
- data/spec/couchrest/core/design_spec.rb +131 -0
- data/spec/couchrest/core/document_spec.rb +96 -0
- data/spec/couchrest/core/model_spec.rb +660 -0
- data/spec/couchrest/helpers/file_manager_spec.rb +203 -0
- data/spec/couchrest/helpers/pager_spec.rb +122 -0
- data/spec/couchrest/helpers/streamer_spec.rb +23 -0
- data/spec/fixtures/attachments/couchdb.png +0 -0
- data/spec/fixtures/attachments/test.html +11 -0
- data/spec/fixtures/views/lib.js +3 -0
- data/spec/fixtures/views/test_view/lib.js +3 -0
- data/spec/fixtures/views/test_view/only-map.js +4 -0
- data/spec/fixtures/views/test_view/test-map.js +3 -0
- data/spec/fixtures/views/test_view/test-reduce.js +3 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +14 -0
- data/utils/remap.rb +27 -0
- data/utils/subset.rb +30 -0
- metadata +154 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
|
+
|
|
3
|
+
describe CouchRest::FileManager do
|
|
4
|
+
before(:all) do
|
|
5
|
+
@cr = CouchRest.new(COUCHHOST)
|
|
6
|
+
@db = @cr.database(TESTDB)
|
|
7
|
+
@db.delete! rescue nil
|
|
8
|
+
@db = @cr.create_db(TESTDB) rescue nil
|
|
9
|
+
end
|
|
10
|
+
it "should initialize" do
|
|
11
|
+
@fm = CouchRest::FileManager.new(TESTDB)
|
|
12
|
+
@fm.should_not be_nil
|
|
13
|
+
end
|
|
14
|
+
it "should require a db name" do
|
|
15
|
+
lambda{CouchRest::FileManager.new}.should raise_error
|
|
16
|
+
end
|
|
17
|
+
it "should accept a db name" do
|
|
18
|
+
@fm = CouchRest::FileManager.new(TESTDB, 'http://localhost')
|
|
19
|
+
@fm.db.name.should == TESTDB
|
|
20
|
+
end
|
|
21
|
+
it "should default to localhost couchdb" do
|
|
22
|
+
@fm = CouchRest::FileManager.new(TESTDB)
|
|
23
|
+
@fm.db.host.should == 'http://localhost:5984'
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe CouchRest::FileManager, "generating an app" do
|
|
28
|
+
before(:all) do
|
|
29
|
+
@appdir = FIXTURE_PATH + '/couchapp'
|
|
30
|
+
`rm -rf #{@appdir}`
|
|
31
|
+
`mkdir -p #{@appdir}`
|
|
32
|
+
CouchRest::FileManager.generate_app(@appdir)
|
|
33
|
+
end
|
|
34
|
+
it "should create an attachments directory" do
|
|
35
|
+
Dir["#{@appdir}/*"].select{|x|x =~ /attachments/}.length.should == 1
|
|
36
|
+
end
|
|
37
|
+
it "should create a views directory" do
|
|
38
|
+
Dir["#{@appdir}/*"].select{|x|x =~ /views/}.length.should == 1
|
|
39
|
+
end
|
|
40
|
+
it "should create a foo directory" do
|
|
41
|
+
Dir["#{@appdir}/*"].select{|x|x =~ /foo/}.length.should == 1
|
|
42
|
+
end
|
|
43
|
+
it "should create index.html" do
|
|
44
|
+
html = File.open("#{@appdir}/_attachments/index.html").read
|
|
45
|
+
html.should match(/DOCTYPE/)
|
|
46
|
+
end
|
|
47
|
+
it "should create bar.txt" do
|
|
48
|
+
html = File.open("#{@appdir}/foo/bar.txt").read
|
|
49
|
+
html.should match(/Couchapp will/)
|
|
50
|
+
end
|
|
51
|
+
it "should create an example view" do
|
|
52
|
+
map = File.open("#{@appdir}/views/example-map.js").read
|
|
53
|
+
map.should match(/function\(doc\)/)
|
|
54
|
+
reduce = File.open("#{@appdir}/views/example-reduce.js").read
|
|
55
|
+
reduce.should match(/rereduce/)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe CouchRest::FileManager, "pushing an app" do
|
|
60
|
+
before(:all) do
|
|
61
|
+
@cr = CouchRest.new(COUCHHOST)
|
|
62
|
+
@db = @cr.database(TESTDB)
|
|
63
|
+
@db.delete! rescue nil
|
|
64
|
+
@db = @cr.create_db(TESTDB) rescue nil
|
|
65
|
+
|
|
66
|
+
@appdir = FIXTURE_PATH + '/couchapp'
|
|
67
|
+
`rm -rf #{@appdir}`
|
|
68
|
+
`mkdir -p #{@appdir}`
|
|
69
|
+
CouchRest::FileManager.generate_app(@appdir)
|
|
70
|
+
|
|
71
|
+
@fm = CouchRest::FileManager.new(TESTDB, COUCHHOST)
|
|
72
|
+
r = @fm.push_app(@appdir, "couchapp")
|
|
73
|
+
end
|
|
74
|
+
it "should create a design document" do
|
|
75
|
+
lambda{@db.get("_design/couchapp")}.should_not raise_error
|
|
76
|
+
end
|
|
77
|
+
it "should create the views" do
|
|
78
|
+
doc = @db.get("_design/couchapp")
|
|
79
|
+
doc['views']['example']['map'].should match(/function/)
|
|
80
|
+
end
|
|
81
|
+
it "should create the index" do
|
|
82
|
+
doc = @db.get("_design/couchapp")
|
|
83
|
+
doc['_attachments']['index.html']["content_type"].should == 'text/html'
|
|
84
|
+
end
|
|
85
|
+
it "should push bar.txt and pals" do
|
|
86
|
+
File.open("#{@appdir}/foo/test.json",'w') do |f|
|
|
87
|
+
f.write("[1,2,3,4]")
|
|
88
|
+
end
|
|
89
|
+
r = @fm.push_app(@appdir, "couchapp")
|
|
90
|
+
doc = @db.get("_design/couchapp")
|
|
91
|
+
doc["foo"].should_not be_nil
|
|
92
|
+
doc["foo"]["bar"].should include("Couchapp will")
|
|
93
|
+
doc["foo"]["test"].should == [1,2,3,4]
|
|
94
|
+
end
|
|
95
|
+
it "should push json as json" do
|
|
96
|
+
File.open("#{@appdir}/test.json",'w') do |f|
|
|
97
|
+
f.write("[1,2,3,4]")
|
|
98
|
+
end
|
|
99
|
+
r = @fm.push_app(@appdir, "couchapp")
|
|
100
|
+
doc = @db.get("_design/couchapp")
|
|
101
|
+
doc['test'].should == [1,2,3,4]
|
|
102
|
+
end
|
|
103
|
+
it "should apply keys from doc.json directly to the doc" do
|
|
104
|
+
File.open("#{@appdir}/doc.json",'w') do |f|
|
|
105
|
+
f.write('{"magical":"so magic"}')
|
|
106
|
+
end
|
|
107
|
+
r = @fm.push_app(@appdir, "couchapp")
|
|
108
|
+
doc = @db.get("_design/couchapp")
|
|
109
|
+
doc['magical'].should == "so magic"
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
describe CouchRest::FileManager, "pushing views" do
|
|
115
|
+
before(:all) do
|
|
116
|
+
@cr = CouchRest.new(COUCHHOST)
|
|
117
|
+
@db = @cr.database(TESTDB)
|
|
118
|
+
@db.delete! rescue nil
|
|
119
|
+
@db = @cr.create_db(TESTDB) rescue nil
|
|
120
|
+
|
|
121
|
+
@fm = CouchRest::FileManager.new(TESTDB, COUCHHOST)
|
|
122
|
+
@view_dir = FIXTURE_PATH + '/views'
|
|
123
|
+
ds = @fm.push_views(@view_dir)
|
|
124
|
+
@design = @db.get("_design/test_view")
|
|
125
|
+
end
|
|
126
|
+
it "should create a design document for each folder" do
|
|
127
|
+
@design["views"].should_not be_nil
|
|
128
|
+
end
|
|
129
|
+
it "should push a map and reduce view" do
|
|
130
|
+
@design["views"]["test-map"].should_not be_nil
|
|
131
|
+
@design["views"]["test-reduce"].should_not be_nil
|
|
132
|
+
end
|
|
133
|
+
it "should push a map only view" do
|
|
134
|
+
@design["views"]["only-map"].should_not be_nil
|
|
135
|
+
@design["views"]["only-reduce"].should be_nil
|
|
136
|
+
end
|
|
137
|
+
it "should include library files" do
|
|
138
|
+
@design["views"]["only-map"]["map"].should include("globalLib")
|
|
139
|
+
@design["views"]["only-map"]["map"].should include("justThisView")
|
|
140
|
+
end
|
|
141
|
+
it "should not create extra design docs" do
|
|
142
|
+
docs = @db.documents(:startkey => '_design', :endkey => '_design/ZZZZZZ')
|
|
143
|
+
docs['total_rows'].should == 1
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
describe CouchRest::FileManager, "pushing a directory with id" do
|
|
148
|
+
before(:all) do
|
|
149
|
+
@cr = CouchRest.new(COUCHHOST)
|
|
150
|
+
@db = @cr.database(TESTDB)
|
|
151
|
+
@db.delete! rescue nil
|
|
152
|
+
@db = @cr.create_db(TESTDB) rescue nil
|
|
153
|
+
|
|
154
|
+
@fm = CouchRest::FileManager.new(TESTDB, COUCHHOST)
|
|
155
|
+
@push_dir = FIXTURE_PATH + '/attachments'
|
|
156
|
+
ds = @fm.push_directory(@push_dir, 'attached')
|
|
157
|
+
end
|
|
158
|
+
it "should create a document for the folder" do
|
|
159
|
+
@db.get("attached")
|
|
160
|
+
end
|
|
161
|
+
it "should make attachments" do
|
|
162
|
+
doc = @db.get("attached")
|
|
163
|
+
doc["_attachments"]["test.html"].should_not be_nil
|
|
164
|
+
end
|
|
165
|
+
it "should set the content type" do
|
|
166
|
+
doc = @db.get("attached")
|
|
167
|
+
doc["_attachments"]["test.html"]["content_type"].should == "text/html"
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
describe CouchRest::FileManager, "pushing a directory without id" do
|
|
172
|
+
before(:all) do
|
|
173
|
+
@cr = CouchRest.new(COUCHHOST)
|
|
174
|
+
@db = @cr.database(TESTDB)
|
|
175
|
+
@db.delete! rescue nil
|
|
176
|
+
@db = @cr.create_db(TESTDB) rescue nil
|
|
177
|
+
|
|
178
|
+
@fm = CouchRest::FileManager.new(TESTDB, COUCHHOST)
|
|
179
|
+
@push_dir = FIXTURE_PATH + '/attachments'
|
|
180
|
+
ds = @fm.push_directory(@push_dir)
|
|
181
|
+
end
|
|
182
|
+
it "should use the dirname" do
|
|
183
|
+
doc = @db.get("attachments")
|
|
184
|
+
doc["_attachments"]["test.html"].should_not be_nil
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
describe CouchRest::FileManager, "pushing a directory/ without id" do
|
|
189
|
+
before(:all) do
|
|
190
|
+
@cr = CouchRest.new(COUCHHOST)
|
|
191
|
+
@db = @cr.database(TESTDB)
|
|
192
|
+
@db.delete! rescue nil
|
|
193
|
+
@db = @cr.create_db(TESTDB) rescue nil
|
|
194
|
+
|
|
195
|
+
@fm = CouchRest::FileManager.new(TESTDB, COUCHHOST)
|
|
196
|
+
@push_dir = FIXTURE_PATH + '/attachments/'
|
|
197
|
+
ds = @fm.push_directory(@push_dir)
|
|
198
|
+
end
|
|
199
|
+
it "should use the dirname" do
|
|
200
|
+
doc = @db.get("attachments")
|
|
201
|
+
doc["_attachments"]["test.html"].should_not be_nil
|
|
202
|
+
end
|
|
203
|
+
end
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
|
+
|
|
3
|
+
describe CouchRest::Pager do
|
|
4
|
+
before(:all) do
|
|
5
|
+
@cr = CouchRest.new(COUCHHOST)
|
|
6
|
+
@db = @cr.database(TESTDB)
|
|
7
|
+
@db.delete! rescue nil
|
|
8
|
+
@db = @cr.create_db(TESTDB) rescue nil
|
|
9
|
+
@pager = CouchRest::Pager.new(@db)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
after(:all) do
|
|
13
|
+
begin
|
|
14
|
+
@db.delete!
|
|
15
|
+
rescue RestClient::Request::RequestFailed
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should store the db" do
|
|
20
|
+
@pager.db.should == @db
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe "paging all docs" do
|
|
24
|
+
before(:all) do
|
|
25
|
+
@docs = []
|
|
26
|
+
100.times do |i|
|
|
27
|
+
@docs << ({:number => (i % 10)})
|
|
28
|
+
end
|
|
29
|
+
@db.bulk_save(@docs)
|
|
30
|
+
end
|
|
31
|
+
it "should yield total_docs / count times" do
|
|
32
|
+
n = 0
|
|
33
|
+
@pager.all_docs(10) do |doc|
|
|
34
|
+
n += 1
|
|
35
|
+
end
|
|
36
|
+
n.should == 10
|
|
37
|
+
end
|
|
38
|
+
it "should yield each docrow group without duplicate docs" do
|
|
39
|
+
docids = {}
|
|
40
|
+
@pager.all_docs(10) do |docrows|
|
|
41
|
+
docrows.each do |row|
|
|
42
|
+
docids[row['id']].should be_nil
|
|
43
|
+
docids[row['id']] = true
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
docids.keys.length.should == 100
|
|
47
|
+
end
|
|
48
|
+
it "should yield each docrow group" do
|
|
49
|
+
@pager.all_docs(10) do |docrows|
|
|
50
|
+
doc = @db.get(docrows[0]['id'])
|
|
51
|
+
doc['number'].class.should == Fixnum
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe "Pager with a view and docs" do
|
|
57
|
+
before(:all) do
|
|
58
|
+
@docs = []
|
|
59
|
+
100.times do |i|
|
|
60
|
+
@docs << ({:number => (i % 10)})
|
|
61
|
+
end
|
|
62
|
+
@db.bulk_save(@docs)
|
|
63
|
+
@db.save({
|
|
64
|
+
'_id' => '_design/magic',
|
|
65
|
+
'views' => {
|
|
66
|
+
'number' => {
|
|
67
|
+
'map' => 'function(doc){emit(doc.number,null)}'
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "should have docs" do
|
|
74
|
+
@docs.length.should == 100
|
|
75
|
+
@db.documents['rows'].length.should == 101
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it "should have a view" do
|
|
79
|
+
@db.view('magic/number', :count => 10)['rows'][0]['key'].should == 0
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "should yield once per key" do
|
|
83
|
+
results = {}
|
|
84
|
+
@pager.key_reduce('magic/number', 20) do |k,vs|
|
|
85
|
+
results[k] = vs.length
|
|
86
|
+
end
|
|
87
|
+
results[0].should == 10
|
|
88
|
+
results[3].should == 10
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "with a small step size should yield once per key" do
|
|
92
|
+
results = {}
|
|
93
|
+
@pager.key_reduce('magic/number', 7) do |k,vs|
|
|
94
|
+
results[k] = vs.length
|
|
95
|
+
end
|
|
96
|
+
results[0].should == 10
|
|
97
|
+
results[3].should == 10
|
|
98
|
+
results[9].should == 10
|
|
99
|
+
end
|
|
100
|
+
it "with a large step size should yield once per key" do
|
|
101
|
+
results = {}
|
|
102
|
+
@pager.key_reduce('magic/number', 1000) do |k,vs|
|
|
103
|
+
results[k] = vs.length
|
|
104
|
+
end
|
|
105
|
+
results[0].should == 10
|
|
106
|
+
results[3].should == 10
|
|
107
|
+
results[9].should == 10
|
|
108
|
+
end
|
|
109
|
+
it "with a begin and end should only yield in the range (and leave out the lastkey)" do
|
|
110
|
+
results = {}
|
|
111
|
+
@pager.key_reduce('magic/number', 1000, 4, 7) do |k,vs|
|
|
112
|
+
results[k] = vs.length
|
|
113
|
+
end
|
|
114
|
+
results[0].should be_nil
|
|
115
|
+
results[4].should == 10
|
|
116
|
+
results[6].should == 10
|
|
117
|
+
results[7].should be_nil
|
|
118
|
+
results[8].should be_nil
|
|
119
|
+
results[9].should be_nil
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
|
+
|
|
3
|
+
describe CouchRest::Streamer do
|
|
4
|
+
before(:all) do
|
|
5
|
+
@cr = CouchRest.new(COUCHHOST)
|
|
6
|
+
@db = @cr.database(TESTDB)
|
|
7
|
+
@db.delete! rescue nil
|
|
8
|
+
@db = @cr.create_db(TESTDB) rescue nil
|
|
9
|
+
@streamer = CouchRest::Streamer.new(@db)
|
|
10
|
+
@docs = (1..1000).collect{|i| {:integer => i, :string => i.to_s}}
|
|
11
|
+
@db.bulk_save(@docs)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "should yield each row in a view" do
|
|
15
|
+
count = 0
|
|
16
|
+
sum = 0
|
|
17
|
+
@streamer.view("_all_docs") do |row|
|
|
18
|
+
count += 1
|
|
19
|
+
end
|
|
20
|
+
count.should == 1001
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
Binary file
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/couchrest'
|
|
2
|
+
|
|
3
|
+
FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures'
|
|
4
|
+
|
|
5
|
+
COUCHHOST = "http://localhost:5984"
|
|
6
|
+
TESTDB = 'couchrest-test'
|
|
7
|
+
|
|
8
|
+
def reset_test_db!
|
|
9
|
+
cr = CouchRest.new(COUCHHOST)
|
|
10
|
+
db = cr.database(TESTDB)
|
|
11
|
+
db.delete! rescue nil
|
|
12
|
+
db = cr.create_db(TESTDB) rescue nin
|
|
13
|
+
db
|
|
14
|
+
end
|
data/utils/remap.rb
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'couchrest'
|
|
3
|
+
|
|
4
|
+
# set the source db and map view
|
|
5
|
+
source = CouchRest.new("http://localhost:5984").database('source-db')
|
|
6
|
+
source_view = 'mydesign/view-map'
|
|
7
|
+
|
|
8
|
+
# set the target db
|
|
9
|
+
target = CouchRest.new("http://localhost:5984").database('target-db')
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
pager = CouchRest::Pager.new(source)
|
|
13
|
+
|
|
14
|
+
# pager will yield once per uniq key in the source view
|
|
15
|
+
|
|
16
|
+
pager.key_reduce(source_view, 10000) do |key, values|
|
|
17
|
+
# create a doc from the key and the values
|
|
18
|
+
example_doc = {
|
|
19
|
+
:key => key,
|
|
20
|
+
:values => values.uniq
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
target.save(example_doc)
|
|
24
|
+
|
|
25
|
+
# keep us up to date with progress
|
|
26
|
+
puts k if (rand > 0.9)
|
|
27
|
+
end
|
data/utils/subset.rb
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'couchrest'
|
|
3
|
+
|
|
4
|
+
# subset.rb replicates a percentage of a database to a fresh database.
|
|
5
|
+
# use it to create a smaller dataset on which to prototype views.
|
|
6
|
+
|
|
7
|
+
# specify the source database
|
|
8
|
+
source = CouchRest.new("http://localhost:5984").database('source-db')
|
|
9
|
+
|
|
10
|
+
# specify the target database
|
|
11
|
+
target = CouchRest.new("http://localhost:5984").database('target-db')
|
|
12
|
+
|
|
13
|
+
# pager efficiently yields all view rows
|
|
14
|
+
pager = CouchRest::Pager.new(source)
|
|
15
|
+
|
|
16
|
+
pager.all_docs(1000) do |rows|
|
|
17
|
+
docs = rows.collect do |r|
|
|
18
|
+
# the percentage of docs to clone
|
|
19
|
+
next if rand > 0.1
|
|
20
|
+
doc = source.get(r['id'])
|
|
21
|
+
doc.delete('_rev')
|
|
22
|
+
doc
|
|
23
|
+
end.compact
|
|
24
|
+
puts docs.length
|
|
25
|
+
next if docs.empty?
|
|
26
|
+
|
|
27
|
+
puts docs.first['_id']
|
|
28
|
+
target.bulk_save(docs)
|
|
29
|
+
end
|
|
30
|
+
|
metadata
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: juozasg-couchrest
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.10.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- J. Chris Anderson
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2008-10-27 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: json
|
|
17
|
+
version_requirement:
|
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
19
|
+
requirements:
|
|
20
|
+
- - ">="
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 1.1.2
|
|
23
|
+
version:
|
|
24
|
+
- !ruby/object:Gem::Dependency
|
|
25
|
+
name: rest-client
|
|
26
|
+
version_requirement:
|
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
28
|
+
requirements:
|
|
29
|
+
- - ">="
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: "0.5"
|
|
32
|
+
version:
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: extlib
|
|
35
|
+
version_requirement:
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 0.9.6
|
|
41
|
+
version:
|
|
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.
|
|
43
|
+
email: jchris@grabb.it
|
|
44
|
+
executables:
|
|
45
|
+
- couchview
|
|
46
|
+
- couchdir
|
|
47
|
+
- couchapp
|
|
48
|
+
extensions: []
|
|
49
|
+
|
|
50
|
+
extra_rdoc_files:
|
|
51
|
+
- README.rdoc
|
|
52
|
+
- LICENSE
|
|
53
|
+
- THANKS
|
|
54
|
+
files:
|
|
55
|
+
- LICENSE
|
|
56
|
+
- README.rdoc
|
|
57
|
+
- Rakefile
|
|
58
|
+
- THANKS
|
|
59
|
+
- bin/couchapp
|
|
60
|
+
- bin/couchdir
|
|
61
|
+
- bin/couchview
|
|
62
|
+
- examples/model
|
|
63
|
+
- examples/model/example.rb
|
|
64
|
+
- examples/word_count
|
|
65
|
+
- examples/word_count/markov
|
|
66
|
+
- examples/word_count/views
|
|
67
|
+
- examples/word_count/views/books
|
|
68
|
+
- examples/word_count/views/books/chunked-map.js
|
|
69
|
+
- examples/word_count/views/books/united-map.js
|
|
70
|
+
- examples/word_count/views/markov
|
|
71
|
+
- examples/word_count/views/markov/chain-map.js
|
|
72
|
+
- examples/word_count/views/markov/chain-reduce.js
|
|
73
|
+
- examples/word_count/views/word_count
|
|
74
|
+
- examples/word_count/views/word_count/count-map.js
|
|
75
|
+
- examples/word_count/views/word_count/count-reduce.js
|
|
76
|
+
- examples/word_count/word_count.rb
|
|
77
|
+
- examples/word_count/word_count_query.rb
|
|
78
|
+
- lib/couchrest
|
|
79
|
+
- lib/couchrest/commands
|
|
80
|
+
- lib/couchrest/commands/generate.rb
|
|
81
|
+
- lib/couchrest/commands/push.rb
|
|
82
|
+
- lib/couchrest/core
|
|
83
|
+
- lib/couchrest/core/database.rb
|
|
84
|
+
- lib/couchrest/core/design.rb
|
|
85
|
+
- lib/couchrest/core/document.rb
|
|
86
|
+
- lib/couchrest/core/model.rb
|
|
87
|
+
- lib/couchrest/core/server.rb
|
|
88
|
+
- lib/couchrest/core/view.rb
|
|
89
|
+
- lib/couchrest/helper
|
|
90
|
+
- lib/couchrest/helper/file_manager.rb
|
|
91
|
+
- lib/couchrest/helper/pager.rb
|
|
92
|
+
- lib/couchrest/helper/streamer.rb
|
|
93
|
+
- lib/couchrest/helper/templates
|
|
94
|
+
- lib/couchrest/helper/templates/bar.txt
|
|
95
|
+
- lib/couchrest/helper/templates/example-map.js
|
|
96
|
+
- lib/couchrest/helper/templates/example-reduce.js
|
|
97
|
+
- lib/couchrest/helper/templates/index.html
|
|
98
|
+
- lib/couchrest/monkeypatches.rb
|
|
99
|
+
- lib/couchrest.rb
|
|
100
|
+
- spec/couchapp_spec.rb
|
|
101
|
+
- spec/couchrest
|
|
102
|
+
- spec/couchrest/core
|
|
103
|
+
- spec/couchrest/core/couchrest_spec.rb
|
|
104
|
+
- spec/couchrest/core/database_spec.rb
|
|
105
|
+
- spec/couchrest/core/design_spec.rb
|
|
106
|
+
- spec/couchrest/core/document_spec.rb
|
|
107
|
+
- spec/couchrest/core/model_spec.rb
|
|
108
|
+
- spec/couchrest/helpers
|
|
109
|
+
- spec/couchrest/helpers/file_manager_spec.rb
|
|
110
|
+
- spec/couchrest/helpers/pager_spec.rb
|
|
111
|
+
- spec/couchrest/helpers/streamer_spec.rb
|
|
112
|
+
- spec/fixtures
|
|
113
|
+
- spec/fixtures/attachments
|
|
114
|
+
- spec/fixtures/attachments/couchdb.png
|
|
115
|
+
- spec/fixtures/attachments/test.html
|
|
116
|
+
- spec/fixtures/views
|
|
117
|
+
- spec/fixtures/views/lib.js
|
|
118
|
+
- spec/fixtures/views/test_view
|
|
119
|
+
- spec/fixtures/views/test_view/lib.js
|
|
120
|
+
- spec/fixtures/views/test_view/only-map.js
|
|
121
|
+
- spec/fixtures/views/test_view/test-map.js
|
|
122
|
+
- spec/fixtures/views/test_view/test-reduce.js
|
|
123
|
+
- spec/spec.opts
|
|
124
|
+
- spec/spec_helper.rb
|
|
125
|
+
- utils/remap.rb
|
|
126
|
+
- utils/subset.rb
|
|
127
|
+
has_rdoc: "true"
|
|
128
|
+
homepage: http://github.com/jchris/couchrest
|
|
129
|
+
post_install_message:
|
|
130
|
+
rdoc_options: []
|
|
131
|
+
|
|
132
|
+
require_paths:
|
|
133
|
+
- lib
|
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - ">="
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: "0"
|
|
139
|
+
version:
|
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
|
+
requirements:
|
|
142
|
+
- - ">="
|
|
143
|
+
- !ruby/object:Gem::Version
|
|
144
|
+
version: "0"
|
|
145
|
+
version:
|
|
146
|
+
requirements: []
|
|
147
|
+
|
|
148
|
+
rubyforge_project:
|
|
149
|
+
rubygems_version: 1.2.0
|
|
150
|
+
signing_key:
|
|
151
|
+
specification_version: 2
|
|
152
|
+
summary: Lean and RESTful interface to CouchDB.
|
|
153
|
+
test_files: []
|
|
154
|
+
|