jgre-couchrest 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/LICENSE +176 -0
- data/README.md +68 -0
- data/Rakefile +66 -0
- data/THANKS.md +18 -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 +46 -0
- data/examples/word_count/word_count_query.rb +40 -0
- data/examples/word_count/word_count_views.rb +26 -0
- data/lib/couchrest.rb +139 -0
- data/lib/couchrest/commands/generate.rb +71 -0
- data/lib/couchrest/commands/push.rb +103 -0
- data/lib/couchrest/core/database.rb +241 -0
- data/lib/couchrest/core/design.rb +89 -0
- data/lib/couchrest/core/document.rb +94 -0
- data/lib/couchrest/core/model.rb +613 -0
- data/lib/couchrest/core/server.rb +51 -0
- data/lib/couchrest/core/view.rb +4 -0
- data/lib/couchrest/helper/pager.rb +103 -0
- data/lib/couchrest/helper/streamer.rb +44 -0
- data/lib/couchrest/monkeypatches.rb +38 -0
- data/spec/couchrest/core/couchrest_spec.rb +201 -0
- data/spec/couchrest/core/database_spec.rb +629 -0
- data/spec/couchrest/core/design_spec.rb +131 -0
- data/spec/couchrest/core/document_spec.rb +213 -0
- data/spec/couchrest/core/model_spec.rb +859 -0
- data/spec/couchrest/helpers/pager_spec.rb +122 -0
- data/spec/couchrest/helpers/streamer_spec.rb +23 -0
- data/spec/fixtures/attachments/README +3 -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 +20 -0
- data/utils/remap.rb +27 -0
- data/utils/subset.rb +30 -0
- metadata +143 -0
@@ -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 / limit 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', :limit => 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,20 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "spec" # Satisfies Autotest and anyone else not using the Rake tasks
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + '/../lib/couchrest'
|
5
|
+
|
6
|
+
unless defined?(FIXTURE_PATH)
|
7
|
+
FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures'
|
8
|
+
SCRATCH_PATH = File.dirname(__FILE__) + '/tmp'
|
9
|
+
|
10
|
+
COUCHHOST = "http://127.0.0.1:5984"
|
11
|
+
TESTDB = 'couchrest-test'
|
12
|
+
end
|
13
|
+
|
14
|
+
def reset_test_db!
|
15
|
+
cr = CouchRest.new(COUCHHOST)
|
16
|
+
db = cr.database(TESTDB)
|
17
|
+
db.delete! rescue nil
|
18
|
+
db = cr.create_db(TESTDB) rescue nin
|
19
|
+
db
|
20
|
+
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://127.0.0.1:5984").database('source-db')
|
6
|
+
source_view = 'mydesign/view-map'
|
7
|
+
|
8
|
+
# set the target db
|
9
|
+
target = CouchRest.new("http://127.0.0.1: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://127.0.0.1:5984").database('source-db')
|
9
|
+
|
10
|
+
# specify the target database
|
11
|
+
target = CouchRest.new("http://127.0.0.1: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,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jgre-couchrest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.12.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- J. Chris Anderson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-11-22 00:00:00 -08: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: mime-types
|
35
|
+
version_requirement:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "1.15"
|
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@apache.org
|
44
|
+
executables: []
|
45
|
+
|
46
|
+
extensions: []
|
47
|
+
|
48
|
+
extra_rdoc_files:
|
49
|
+
- README.md
|
50
|
+
- LICENSE
|
51
|
+
- THANKS.md
|
52
|
+
files:
|
53
|
+
- LICENSE
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- THANKS.md
|
57
|
+
- examples/model
|
58
|
+
- examples/model/example.rb
|
59
|
+
- examples/word_count
|
60
|
+
- examples/word_count/markov
|
61
|
+
- examples/word_count/views
|
62
|
+
- examples/word_count/views/books
|
63
|
+
- examples/word_count/views/books/chunked-map.js
|
64
|
+
- examples/word_count/views/books/united-map.js
|
65
|
+
- examples/word_count/views/markov
|
66
|
+
- examples/word_count/views/markov/chain-map.js
|
67
|
+
- examples/word_count/views/markov/chain-reduce.js
|
68
|
+
- examples/word_count/views/word_count
|
69
|
+
- examples/word_count/views/word_count/count-map.js
|
70
|
+
- examples/word_count/views/word_count/count-reduce.js
|
71
|
+
- examples/word_count/word_count.rb
|
72
|
+
- examples/word_count/word_count_query.rb
|
73
|
+
- examples/word_count/word_count_views.rb
|
74
|
+
- lib/couchrest
|
75
|
+
- lib/couchrest/commands
|
76
|
+
- lib/couchrest/commands/generate.rb
|
77
|
+
- lib/couchrest/commands/push.rb
|
78
|
+
- lib/couchrest/core
|
79
|
+
- lib/couchrest/core/database.rb
|
80
|
+
- lib/couchrest/core/design.rb
|
81
|
+
- lib/couchrest/core/document.rb
|
82
|
+
- lib/couchrest/core/model.rb
|
83
|
+
- lib/couchrest/core/server.rb
|
84
|
+
- lib/couchrest/core/view.rb
|
85
|
+
- lib/couchrest/helper
|
86
|
+
- lib/couchrest/helper/pager.rb
|
87
|
+
- lib/couchrest/helper/streamer.rb
|
88
|
+
- lib/couchrest/monkeypatches.rb
|
89
|
+
- lib/couchrest.rb
|
90
|
+
- spec/couchrest
|
91
|
+
- spec/couchrest/core
|
92
|
+
- spec/couchrest/core/couchrest_spec.rb
|
93
|
+
- spec/couchrest/core/database_spec.rb
|
94
|
+
- spec/couchrest/core/design_spec.rb
|
95
|
+
- spec/couchrest/core/document_spec.rb
|
96
|
+
- spec/couchrest/core/model_spec.rb
|
97
|
+
- spec/couchrest/helpers
|
98
|
+
- spec/couchrest/helpers/pager_spec.rb
|
99
|
+
- spec/couchrest/helpers/streamer_spec.rb
|
100
|
+
- spec/fixtures
|
101
|
+
- spec/fixtures/attachments
|
102
|
+
- spec/fixtures/attachments/couchdb.png
|
103
|
+
- spec/fixtures/attachments/README
|
104
|
+
- spec/fixtures/attachments/test.html
|
105
|
+
- spec/fixtures/views
|
106
|
+
- spec/fixtures/views/lib.js
|
107
|
+
- spec/fixtures/views/test_view
|
108
|
+
- spec/fixtures/views/test_view/lib.js
|
109
|
+
- spec/fixtures/views/test_view/only-map.js
|
110
|
+
- spec/fixtures/views/test_view/test-map.js
|
111
|
+
- spec/fixtures/views/test_view/test-reduce.js
|
112
|
+
- spec/spec.opts
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
- utils/remap.rb
|
115
|
+
- utils/subset.rb
|
116
|
+
has_rdoc: true
|
117
|
+
homepage: http://github.com/jchris/couchrest
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: "0"
|
128
|
+
version:
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: "0"
|
134
|
+
version:
|
135
|
+
requirements: []
|
136
|
+
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 1.2.0
|
139
|
+
signing_key:
|
140
|
+
specification_version: 2
|
141
|
+
summary: Lean and RESTful interface to CouchDB.
|
142
|
+
test_files: []
|
143
|
+
|