namelessjon-couchrest 1.0.0
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 +46 -0
- data/Rakefile +69 -0
- data/THANKS.md +21 -0
- data/couchrest.gemspec +111 -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 +145 -0
- data/lib/couchrest/commands/generate.rb +71 -0
- data/lib/couchrest/commands/push.rb +103 -0
- data/lib/couchrest/database.rb +373 -0
- data/lib/couchrest/design.rb +80 -0
- data/lib/couchrest/document.rb +89 -0
- data/lib/couchrest/helper/attachments.rb +29 -0
- data/lib/couchrest/helper/pager.rb +103 -0
- data/lib/couchrest/helper/streamer.rb +51 -0
- data/lib/couchrest/helper/upgrade.rb +52 -0
- data/lib/couchrest/json_response.rb +14 -0
- data/lib/couchrest/middlewares/logger.rb +263 -0
- data/lib/couchrest/monkeypatches.rb +42 -0
- data/lib/couchrest/response.rb +35 -0
- data/lib/couchrest/rest_api.rb +62 -0
- data/lib/couchrest/server.rb +90 -0
- data/lib/couchrest/support/inheritable_attributes.rb +107 -0
- data/lib/couchrest.rb +127 -0
- data/spec/couchrest/couchrest_spec.rb +202 -0
- data/spec/couchrest/database_spec.rb +870 -0
- data/spec/couchrest/design_spec.rb +158 -0
- data/spec/couchrest/document_spec.rb +279 -0
- data/spec/couchrest/helpers/pager_spec.rb +123 -0
- data/spec/couchrest/helpers/streamer_spec.rb +52 -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 +44 -0
- data/utils/remap.rb +27 -0
- data/utils/subset.rb +30 -0
- metadata +179 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "spec" # Satisfies Autotest and anyone else not using the Rake tasks
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), '..','lib','couchrest')
|
4
|
+
# check the following file to see how to use the spec'd features.
|
5
|
+
|
6
|
+
unless defined?(FIXTURE_PATH)
|
7
|
+
FIXTURE_PATH = File.join(File.dirname(__FILE__), '/fixtures')
|
8
|
+
SCRATCH_PATH = File.join(File.dirname(__FILE__), '/tmp')
|
9
|
+
|
10
|
+
COUCHHOST = ENV['COUCHHOST'] || "http://127.0.0.1:5984"
|
11
|
+
TESTDB = 'couchrest-test'
|
12
|
+
REPLICATIONDB = 'couchrest-test-replication'
|
13
|
+
TEST_SERVER = CouchRest.new COUCHHOST
|
14
|
+
TEST_SERVER.default_database = TESTDB
|
15
|
+
DB = TEST_SERVER.database(TESTDB)
|
16
|
+
end
|
17
|
+
|
18
|
+
def reset_test_db!
|
19
|
+
DB.recreate! rescue nil
|
20
|
+
DB
|
21
|
+
end
|
22
|
+
|
23
|
+
Spec::Runner.configure do |config|
|
24
|
+
config.before(:all) { reset_test_db! }
|
25
|
+
|
26
|
+
config.after(:all) do
|
27
|
+
cr = TEST_SERVER
|
28
|
+
test_dbs = cr.databases.select { |db| db =~ /^#{TESTDB}/ }
|
29
|
+
test_dbs.each do |db|
|
30
|
+
cr.database(db).delete! rescue nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def couchdb_lucene_available?
|
36
|
+
lucene_path = "http://localhost:5985/"
|
37
|
+
url = URI.parse(lucene_path)
|
38
|
+
req = Net::HTTP::Get.new(url.path)
|
39
|
+
res = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
|
40
|
+
true
|
41
|
+
rescue Exception => e
|
42
|
+
false
|
43
|
+
end
|
44
|
+
|
data/utils/remap.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'couchrest'
|
2
|
+
require 'couchrest/helper/pager'
|
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 'couchrest'
|
2
|
+
require 'couchrest/helper/pager'
|
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,179 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: namelessjon-couchrest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jonathan Stott
|
14
|
+
- J. Chris Anderson
|
15
|
+
- Matt Aimonetti
|
16
|
+
- Marcos Tapajos
|
17
|
+
- Will Leinweber
|
18
|
+
- Sam Lown
|
19
|
+
autorequire:
|
20
|
+
bindir: bin
|
21
|
+
cert_chain: []
|
22
|
+
|
23
|
+
date: 2010-08-06 00:00:00 +01:00
|
24
|
+
default_executable:
|
25
|
+
dependencies:
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rest-client
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
hash: 1
|
35
|
+
segments:
|
36
|
+
- 1
|
37
|
+
- 5
|
38
|
+
- 1
|
39
|
+
version: 1.5.1
|
40
|
+
type: :runtime
|
41
|
+
version_requirements: *id001
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: mime-types
|
44
|
+
prerelease: false
|
45
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
hash: 17
|
51
|
+
segments:
|
52
|
+
- 1
|
53
|
+
- 15
|
54
|
+
version: "1.15"
|
55
|
+
type: :runtime
|
56
|
+
version_requirements: *id002
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: yajl-ruby
|
59
|
+
prerelease: false
|
60
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
type: :runtime
|
70
|
+
version_requirements: *id003
|
71
|
+
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. This is a fork to make it work how I want it to. Most of the work was done by the original authors
|
72
|
+
email: jonathan.stott@gmail.com
|
73
|
+
executables: []
|
74
|
+
|
75
|
+
extensions: []
|
76
|
+
|
77
|
+
extra_rdoc_files:
|
78
|
+
- LICENSE
|
79
|
+
- README.md
|
80
|
+
- THANKS.md
|
81
|
+
files:
|
82
|
+
- LICENSE
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- THANKS.md
|
86
|
+
- couchrest.gemspec
|
87
|
+
- examples/word_count/markov
|
88
|
+
- examples/word_count/views/books/chunked-map.js
|
89
|
+
- examples/word_count/views/books/united-map.js
|
90
|
+
- examples/word_count/views/markov/chain-map.js
|
91
|
+
- examples/word_count/views/markov/chain-reduce.js
|
92
|
+
- examples/word_count/views/word_count/count-map.js
|
93
|
+
- examples/word_count/views/word_count/count-reduce.js
|
94
|
+
- examples/word_count/word_count.rb
|
95
|
+
- examples/word_count/word_count_query.rb
|
96
|
+
- examples/word_count/word_count_views.rb
|
97
|
+
- history.txt
|
98
|
+
- lib/couchrest.rb
|
99
|
+
- lib/couchrest/commands/generate.rb
|
100
|
+
- lib/couchrest/commands/push.rb
|
101
|
+
- lib/couchrest/database.rb
|
102
|
+
- lib/couchrest/design.rb
|
103
|
+
- lib/couchrest/document.rb
|
104
|
+
- lib/couchrest/helper/attachments.rb
|
105
|
+
- lib/couchrest/helper/pager.rb
|
106
|
+
- lib/couchrest/helper/streamer.rb
|
107
|
+
- lib/couchrest/helper/upgrade.rb
|
108
|
+
- lib/couchrest/json_response.rb
|
109
|
+
- lib/couchrest/middlewares/logger.rb
|
110
|
+
- lib/couchrest/monkeypatches.rb
|
111
|
+
- lib/couchrest/response.rb
|
112
|
+
- lib/couchrest/rest_api.rb
|
113
|
+
- lib/couchrest/server.rb
|
114
|
+
- lib/couchrest/support/inheritable_attributes.rb
|
115
|
+
- spec/couchrest/couchrest_spec.rb
|
116
|
+
- spec/couchrest/database_spec.rb
|
117
|
+
- spec/couchrest/design_spec.rb
|
118
|
+
- spec/couchrest/document_spec.rb
|
119
|
+
- spec/couchrest/helpers/pager_spec.rb
|
120
|
+
- spec/couchrest/helpers/streamer_spec.rb
|
121
|
+
- spec/couchrest/server_spec.rb
|
122
|
+
- spec/fixtures/attachments/README
|
123
|
+
- spec/fixtures/attachments/couchdb.png
|
124
|
+
- spec/fixtures/attachments/test.html
|
125
|
+
- spec/fixtures/views/lib.js
|
126
|
+
- spec/fixtures/views/test_view/lib.js
|
127
|
+
- spec/fixtures/views/test_view/only-map.js
|
128
|
+
- spec/fixtures/views/test_view/test-map.js
|
129
|
+
- spec/fixtures/views/test_view/test-reduce.js
|
130
|
+
- spec/spec.opts
|
131
|
+
- spec/spec_helper.rb
|
132
|
+
- utils/remap.rb
|
133
|
+
- utils/subset.rb
|
134
|
+
has_rdoc: true
|
135
|
+
homepage: http://github.com/namelessjon/couchrest
|
136
|
+
licenses: []
|
137
|
+
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options:
|
140
|
+
- --charset=UTF-8
|
141
|
+
require_paths:
|
142
|
+
- lib
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
none: false
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
hash: 3
|
149
|
+
segments:
|
150
|
+
- 0
|
151
|
+
version: "0"
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
hash: 3
|
158
|
+
segments:
|
159
|
+
- 0
|
160
|
+
version: "0"
|
161
|
+
requirements: []
|
162
|
+
|
163
|
+
rubyforge_project:
|
164
|
+
rubygems_version: 1.3.7
|
165
|
+
signing_key:
|
166
|
+
specification_version: 3
|
167
|
+
summary: Lean and RESTful interface to CouchDB.
|
168
|
+
test_files:
|
169
|
+
- spec/couchrest/server_spec.rb
|
170
|
+
- spec/couchrest/database_spec.rb
|
171
|
+
- spec/couchrest/helpers/streamer_spec.rb
|
172
|
+
- spec/couchrest/helpers/pager_spec.rb
|
173
|
+
- spec/couchrest/design_spec.rb
|
174
|
+
- spec/couchrest/couchrest_spec.rb
|
175
|
+
- spec/couchrest/document_spec.rb
|
176
|
+
- spec/spec_helper.rb
|
177
|
+
- examples/word_count/word_count_query.rb
|
178
|
+
- examples/word_count/word_count.rb
|
179
|
+
- examples/word_count/word_count_views.rb
|