dpla-couchrest 1.2.1.pre.dpla
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.travis.yml +8 -0
- data/Gemfile +2 -0
- data/LICENSE +176 -0
- data/README.md +66 -0
- data/Rakefile +23 -0
- data/THANKS.md +21 -0
- data/VERSION +1 -0
- data/couchrest.gemspec +36 -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/history.txt +214 -0
- data/init.rb +1 -0
- data/lib/couchrest.rb +146 -0
- data/lib/couchrest/attributes.rb +89 -0
- data/lib/couchrest/commands/generate.rb +71 -0
- data/lib/couchrest/commands/push.rb +103 -0
- data/lib/couchrest/database.rb +402 -0
- data/lib/couchrest/design.rb +91 -0
- data/lib/couchrest/document.rb +105 -0
- data/lib/couchrest/helper/attachments.rb +29 -0
- data/lib/couchrest/helper/pager.rb +103 -0
- data/lib/couchrest/helper/streamer.rb +60 -0
- data/lib/couchrest/helper/upgrade.rb +51 -0
- data/lib/couchrest/middlewares/logger.rb +263 -0
- data/lib/couchrest/monkeypatches.rb +25 -0
- data/lib/couchrest/rest_api.rb +166 -0
- data/lib/couchrest/server.rb +92 -0
- data/lib/couchrest/support/inheritable_attributes.rb +107 -0
- data/spec/.gitignore +1 -0
- data/spec/couchrest/couchrest_spec.rb +197 -0
- data/spec/couchrest/database_spec.rb +914 -0
- data/spec/couchrest/design_spec.rb +206 -0
- data/spec/couchrest/document_spec.rb +400 -0
- data/spec/couchrest/helpers/pager_spec.rb +115 -0
- data/spec/couchrest/helpers/streamer_spec.rb +134 -0
- data/spec/couchrest/rest_api_spec.rb +241 -0
- data/spec/couchrest/server_spec.rb +35 -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 +5 -0
- data/spec/spec_helper.rb +46 -0
- data/utils/remap.rb +27 -0
- data/utils/subset.rb +30 -0
- metadata +212 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
describe CouchRest::Server do
|
4
|
+
|
5
|
+
describe "available databases" do
|
6
|
+
before(:each) do
|
7
|
+
@couch = CouchRest::Server.new COUCHHOST
|
8
|
+
end
|
9
|
+
|
10
|
+
after(:each) do
|
11
|
+
@couch.available_databases.each do |ref, db|
|
12
|
+
db.delete!
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should let you add more databases" do
|
17
|
+
@couch.available_databases.should be_empty
|
18
|
+
@couch.define_available_database(:default, "cr-server-test-db")
|
19
|
+
@couch.available_databases.keys.should include(:default)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should verify that a database is available" do
|
23
|
+
@couch.define_available_database(:default, "cr-server-test-db")
|
24
|
+
@couch.available_database?(:default).should be_true
|
25
|
+
@couch.available_database?("cr-server-test-db").should be_true
|
26
|
+
@couch.available_database?(:matt).should be_false
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should let you set a default database" do
|
30
|
+
@couch.default_database = 'cr-server-test-default-db'
|
31
|
+
@couch.available_database?(:default).should be_true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
Binary file
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "rubygems"
|
3
|
+
require "rspec"
|
4
|
+
|
5
|
+
require File.join(File.dirname(__FILE__), '..','lib','couchrest')
|
6
|
+
# check the following file to see how to use the spec'd features.
|
7
|
+
|
8
|
+
unless defined?(FIXTURE_PATH)
|
9
|
+
FIXTURE_PATH = File.join(File.dirname(__FILE__), '/fixtures')
|
10
|
+
SCRATCH_PATH = File.join(File.dirname(__FILE__), '/tmp')
|
11
|
+
|
12
|
+
COUCHHOST = ENV['COUCHHOST'] || "http://127.0.0.1:5984"
|
13
|
+
TESTDB = 'couchrest-test'
|
14
|
+
REPLICATIONDB = 'couchrest-test-replication'
|
15
|
+
TEST_SERVER = CouchRest.new COUCHHOST
|
16
|
+
TEST_SERVER.default_database = TESTDB
|
17
|
+
DB = TEST_SERVER.database(TESTDB)
|
18
|
+
end
|
19
|
+
|
20
|
+
def reset_test_db!
|
21
|
+
DB.recreate! rescue nil
|
22
|
+
DB
|
23
|
+
end
|
24
|
+
|
25
|
+
RSpec.configure do |config|
|
26
|
+
config.before(:all) { reset_test_db! }
|
27
|
+
|
28
|
+
config.after(:all) do
|
29
|
+
cr = TEST_SERVER
|
30
|
+
test_dbs = cr.databases.select { |db| db =~ /^#{TESTDB}/ }
|
31
|
+
test_dbs.each do |db|
|
32
|
+
cr.database(db).delete! rescue nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def couchdb_lucene_available?
|
38
|
+
lucene_path = "http://localhost:5985/"
|
39
|
+
url = URI.parse(lucene_path)
|
40
|
+
req = Net::HTTP::Get.new(url.path)
|
41
|
+
res = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
|
42
|
+
true
|
43
|
+
rescue Exception => e
|
44
|
+
false
|
45
|
+
end
|
46
|
+
|
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,212 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dpla-couchrest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.1.pre.dpla
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- J. Chris Anderson
|
8
|
+
- Matt Aimonetti
|
9
|
+
- Marcos Tapajos
|
10
|
+
- Will Leinweber
|
11
|
+
- Sam Lown
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
date: 2015-01-16 00:00:00.000000000 Z
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: rest-client
|
19
|
+
requirement: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '1.6'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '1.6'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: mime-types
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.1'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '2.1'
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: multi_json
|
47
|
+
requirement: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ~>
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '1.8'
|
52
|
+
type: :runtime
|
53
|
+
prerelease: false
|
54
|
+
version_requirements: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '1.8'
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: json
|
61
|
+
requirement: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.7.0
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 1.7.0
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: rspec
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ~>
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 2.6.0
|
80
|
+
type: :development
|
81
|
+
prerelease: false
|
82
|
+
version_requirements: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ~>
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 2.6.0
|
87
|
+
- !ruby/object:Gem::Dependency
|
88
|
+
name: rake
|
89
|
+
requirement: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
type: :development
|
95
|
+
prerelease: false
|
96
|
+
version_requirements: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
description: CouchRest provides a simple interface on top of CouchDB's RESTful HTTP
|
102
|
+
API, as well as including some utility scripts for managing views and attachments.
|
103
|
+
email: jchris@apache.org
|
104
|
+
executables: []
|
105
|
+
extensions: []
|
106
|
+
extra_rdoc_files:
|
107
|
+
- LICENSE
|
108
|
+
- README.md
|
109
|
+
- THANKS.md
|
110
|
+
files:
|
111
|
+
- .gitignore
|
112
|
+
- .travis.yml
|
113
|
+
- Gemfile
|
114
|
+
- LICENSE
|
115
|
+
- README.md
|
116
|
+
- Rakefile
|
117
|
+
- THANKS.md
|
118
|
+
- VERSION
|
119
|
+
- couchrest.gemspec
|
120
|
+
- examples/word_count/markov
|
121
|
+
- examples/word_count/views/books/chunked-map.js
|
122
|
+
- examples/word_count/views/books/united-map.js
|
123
|
+
- examples/word_count/views/markov/chain-map.js
|
124
|
+
- examples/word_count/views/markov/chain-reduce.js
|
125
|
+
- examples/word_count/views/word_count/count-map.js
|
126
|
+
- examples/word_count/views/word_count/count-reduce.js
|
127
|
+
- examples/word_count/word_count.rb
|
128
|
+
- examples/word_count/word_count_query.rb
|
129
|
+
- examples/word_count/word_count_views.rb
|
130
|
+
- history.txt
|
131
|
+
- init.rb
|
132
|
+
- lib/couchrest.rb
|
133
|
+
- lib/couchrest/attributes.rb
|
134
|
+
- lib/couchrest/commands/generate.rb
|
135
|
+
- lib/couchrest/commands/push.rb
|
136
|
+
- lib/couchrest/database.rb
|
137
|
+
- lib/couchrest/design.rb
|
138
|
+
- lib/couchrest/document.rb
|
139
|
+
- lib/couchrest/helper/attachments.rb
|
140
|
+
- lib/couchrest/helper/pager.rb
|
141
|
+
- lib/couchrest/helper/streamer.rb
|
142
|
+
- lib/couchrest/helper/upgrade.rb
|
143
|
+
- lib/couchrest/middlewares/logger.rb
|
144
|
+
- lib/couchrest/monkeypatches.rb
|
145
|
+
- lib/couchrest/rest_api.rb
|
146
|
+
- lib/couchrest/server.rb
|
147
|
+
- lib/couchrest/support/inheritable_attributes.rb
|
148
|
+
- spec/.gitignore
|
149
|
+
- spec/couchrest/couchrest_spec.rb
|
150
|
+
- spec/couchrest/database_spec.rb
|
151
|
+
- spec/couchrest/design_spec.rb
|
152
|
+
- spec/couchrest/document_spec.rb
|
153
|
+
- spec/couchrest/helpers/pager_spec.rb
|
154
|
+
- spec/couchrest/helpers/streamer_spec.rb
|
155
|
+
- spec/couchrest/rest_api_spec.rb
|
156
|
+
- spec/couchrest/server_spec.rb
|
157
|
+
- spec/fixtures/attachments/README
|
158
|
+
- spec/fixtures/attachments/couchdb.png
|
159
|
+
- spec/fixtures/attachments/test.html
|
160
|
+
- spec/fixtures/views/lib.js
|
161
|
+
- spec/fixtures/views/test_view/lib.js
|
162
|
+
- spec/fixtures/views/test_view/only-map.js
|
163
|
+
- spec/fixtures/views/test_view/test-map.js
|
164
|
+
- spec/fixtures/views/test_view/test-reduce.js
|
165
|
+
- spec/spec.opts
|
166
|
+
- spec/spec_helper.rb
|
167
|
+
- utils/remap.rb
|
168
|
+
- utils/subset.rb
|
169
|
+
homepage: http://github.com/dpla/couchrest
|
170
|
+
licenses:
|
171
|
+
- Apache License 2.0
|
172
|
+
metadata: {}
|
173
|
+
post_install_message:
|
174
|
+
rdoc_options:
|
175
|
+
- --charset=UTF-8
|
176
|
+
require_paths:
|
177
|
+
- lib
|
178
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - '>='
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - '>'
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: 1.3.1
|
188
|
+
requirements: []
|
189
|
+
rubyforge_project:
|
190
|
+
rubygems_version: 2.0.14
|
191
|
+
signing_key:
|
192
|
+
specification_version: 4
|
193
|
+
summary: Lean and RESTful interface to CouchDB.
|
194
|
+
test_files:
|
195
|
+
- spec/couchrest/couchrest_spec.rb
|
196
|
+
- spec/couchrest/database_spec.rb
|
197
|
+
- spec/couchrest/design_spec.rb
|
198
|
+
- spec/couchrest/document_spec.rb
|
199
|
+
- spec/couchrest/helpers/pager_spec.rb
|
200
|
+
- spec/couchrest/helpers/streamer_spec.rb
|
201
|
+
- spec/couchrest/rest_api_spec.rb
|
202
|
+
- spec/couchrest/server_spec.rb
|
203
|
+
- spec/fixtures/attachments/README
|
204
|
+
- spec/fixtures/attachments/couchdb.png
|
205
|
+
- spec/fixtures/attachments/test.html
|
206
|
+
- spec/fixtures/views/lib.js
|
207
|
+
- spec/fixtures/views/test_view/lib.js
|
208
|
+
- spec/fixtures/views/test_view/only-map.js
|
209
|
+
- spec/fixtures/views/test_view/test-map.js
|
210
|
+
- spec/fixtures/views/test_view/test-reduce.js
|
211
|
+
- spec/spec.opts
|
212
|
+
- spec/spec_helper.rb
|