jchris-couchrest 0.2.2 → 0.7.99
Sign up to get free protection for your applications and to get access to all the features.
- data/README +39 -0
- data/Rakefile +3 -54
- data/lib/couchrest.rb +39 -161
- data/lib/database.rb +83 -0
- data/script/couchdir +58 -0
- data/script/couchview +158 -0
- data/spec/couchrest_spec.rb +86 -0
- data/spec/database_spec.rb +407 -0
- metadata +15 -138
- data/LICENSE +0 -176
- data/README.md +0 -93
- data/THANKS.md +0 -18
- data/examples/model/example.rb +0 -144
- data/examples/word_count/markov +0 -38
- data/examples/word_count/views/books/chunked-map.js +0 -3
- data/examples/word_count/views/books/united-map.js +0 -1
- data/examples/word_count/views/markov/chain-map.js +0 -6
- data/examples/word_count/views/markov/chain-reduce.js +0 -7
- data/examples/word_count/views/word_count/count-map.js +0 -6
- data/examples/word_count/views/word_count/count-reduce.js +0 -3
- data/examples/word_count/word_count.rb +0 -46
- data/examples/word_count/word_count_query.rb +0 -40
- data/examples/word_count/word_count_views.rb +0 -26
- data/lib/couchrest/commands/generate.rb +0 -71
- data/lib/couchrest/commands/push.rb +0 -103
- data/lib/couchrest/core/database.rb +0 -318
- data/lib/couchrest/core/design.rb +0 -89
- data/lib/couchrest/core/document.rb +0 -96
- data/lib/couchrest/core/response.rb +0 -16
- data/lib/couchrest/core/server.rb +0 -88
- data/lib/couchrest/core/view.rb +0 -4
- data/lib/couchrest/helper/pager.rb +0 -103
- data/lib/couchrest/helper/streamer.rb +0 -44
- data/lib/couchrest/helper/upgrade.rb +0 -51
- data/lib/couchrest/mixins.rb +0 -4
- data/lib/couchrest/mixins/attachments.rb +0 -31
- data/lib/couchrest/mixins/callbacks.rb +0 -483
- data/lib/couchrest/mixins/design_doc.rb +0 -64
- data/lib/couchrest/mixins/document_queries.rb +0 -48
- data/lib/couchrest/mixins/extended_attachments.rb +0 -68
- data/lib/couchrest/mixins/extended_document_mixins.rb +0 -6
- data/lib/couchrest/mixins/properties.rb +0 -125
- data/lib/couchrest/mixins/validation.rb +0 -234
- data/lib/couchrest/mixins/views.rb +0 -168
- data/lib/couchrest/monkeypatches.rb +0 -119
- data/lib/couchrest/more/casted_model.rb +0 -28
- data/lib/couchrest/more/extended_document.rb +0 -217
- data/lib/couchrest/more/property.rb +0 -40
- data/lib/couchrest/support/blank.rb +0 -42
- data/lib/couchrest/support/class.rb +0 -191
- data/lib/couchrest/validation/auto_validate.rb +0 -163
- data/lib/couchrest/validation/contextual_validators.rb +0 -78
- data/lib/couchrest/validation/validation_errors.rb +0 -118
- data/lib/couchrest/validation/validators/absent_field_validator.rb +0 -74
- data/lib/couchrest/validation/validators/confirmation_validator.rb +0 -99
- data/lib/couchrest/validation/validators/format_validator.rb +0 -117
- data/lib/couchrest/validation/validators/formats/email.rb +0 -66
- data/lib/couchrest/validation/validators/formats/url.rb +0 -43
- data/lib/couchrest/validation/validators/generic_validator.rb +0 -120
- data/lib/couchrest/validation/validators/length_validator.rb +0 -134
- data/lib/couchrest/validation/validators/method_validator.rb +0 -89
- data/lib/couchrest/validation/validators/numeric_validator.rb +0 -104
- data/lib/couchrest/validation/validators/required_field_validator.rb +0 -109
- data/spec/couchrest/core/couchrest_spec.rb +0 -201
- data/spec/couchrest/core/database_spec.rb +0 -745
- data/spec/couchrest/core/design_spec.rb +0 -131
- data/spec/couchrest/core/document_spec.rb +0 -311
- data/spec/couchrest/core/server_spec.rb +0 -35
- data/spec/couchrest/helpers/pager_spec.rb +0 -122
- data/spec/couchrest/helpers/streamer_spec.rb +0 -23
- data/spec/couchrest/more/casted_extended_doc_spec.rb +0 -40
- data/spec/couchrest/more/casted_model_spec.rb +0 -98
- data/spec/couchrest/more/extended_doc_attachment_spec.rb +0 -130
- data/spec/couchrest/more/extended_doc_spec.rb +0 -509
- data/spec/couchrest/more/extended_doc_view_spec.rb +0 -207
- data/spec/couchrest/more/property_spec.rb +0 -130
- data/spec/couchrest/support/class_spec.rb +0 -59
- data/spec/fixtures/attachments/README +0 -3
- data/spec/fixtures/attachments/couchdb.png +0 -0
- data/spec/fixtures/attachments/test.html +0 -11
- data/spec/fixtures/more/article.rb +0 -34
- data/spec/fixtures/more/card.rb +0 -20
- data/spec/fixtures/more/course.rb +0 -14
- data/spec/fixtures/more/event.rb +0 -6
- data/spec/fixtures/more/invoice.rb +0 -17
- data/spec/fixtures/more/person.rb +0 -8
- data/spec/fixtures/more/question.rb +0 -6
- data/spec/fixtures/more/service.rb +0 -12
- data/spec/fixtures/views/lib.js +0 -3
- data/spec/fixtures/views/test_view/lib.js +0 -3
- data/spec/fixtures/views/test_view/only-map.js +0 -4
- data/spec/fixtures/views/test_view/test-map.js +0 -3
- data/spec/fixtures/views/test_view/test-reduce.js +0 -3
- data/spec/spec.opts +0 -6
- data/spec/spec_helper.rb +0 -26
- data/utils/remap.rb +0 -27
- data/utils/subset.rb +0 -30
data/spec/fixtures/more/card.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
class Card < CouchRest::ExtendedDocument
|
2
|
-
# Include the validation module to get access to the validation methods
|
3
|
-
include CouchRest::Validation
|
4
|
-
# set the auto_validation before defining the properties
|
5
|
-
auto_validate!
|
6
|
-
|
7
|
-
# Set the default database to use
|
8
|
-
use_database TEST_SERVER.default_database
|
9
|
-
|
10
|
-
# Official Schema
|
11
|
-
property :first_name
|
12
|
-
property :last_name, :alias => :family_name
|
13
|
-
property :read_only_value, :read_only => true
|
14
|
-
|
15
|
-
timestamps!
|
16
|
-
|
17
|
-
# Validation
|
18
|
-
validates_present :first_name
|
19
|
-
|
20
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require File.join(FIXTURE_PATH, 'more', 'question')
|
2
|
-
require File.join(FIXTURE_PATH, 'more', 'person')
|
3
|
-
|
4
|
-
class Course < CouchRest::ExtendedDocument
|
5
|
-
use_database TEST_SERVER.default_database
|
6
|
-
|
7
|
-
property :title
|
8
|
-
property :questions, :cast_as => ['Question']
|
9
|
-
property :professor, :cast_as => 'Person'
|
10
|
-
property :final_test_at, :cast_as => 'Time'
|
11
|
-
|
12
|
-
view_by :title
|
13
|
-
view_by :dept, :ducktype => true
|
14
|
-
end
|
data/spec/fixtures/more/event.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
class Invoice < CouchRest::ExtendedDocument
|
2
|
-
# Include the validation module to get access to the validation methods
|
3
|
-
include CouchRest::Validation
|
4
|
-
|
5
|
-
# Set the default database to use
|
6
|
-
use_database TEST_SERVER.default_database
|
7
|
-
|
8
|
-
# Official Schema
|
9
|
-
property :client_name
|
10
|
-
property :employee_name
|
11
|
-
property :location
|
12
|
-
|
13
|
-
# Validation
|
14
|
-
validates_present :client_name, :employee_name
|
15
|
-
validates_present :location, :message => "Hey stupid!, you forgot the location"
|
16
|
-
|
17
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
class Service < CouchRest::ExtendedDocument
|
2
|
-
# Include the validation module to get access to the validation methods
|
3
|
-
include CouchRest::Validation
|
4
|
-
auto_validate!
|
5
|
-
# Set the default database to use
|
6
|
-
use_database TEST_SERVER.default_database
|
7
|
-
|
8
|
-
# Official Schema
|
9
|
-
property :name, :length => 4...20
|
10
|
-
property :price, :type => Integer
|
11
|
-
|
12
|
-
end
|
data/spec/fixtures/views/lib.js
DELETED
data/spec/spec.opts
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "spec" # Satisfies Autotest and anyone else not using the Rake tasks
|
3
|
-
|
4
|
-
require File.join(File.dirname(__FILE__), '..','lib','couchrest')
|
5
|
-
# check the following file to see how to use the spec'd features.
|
6
|
-
|
7
|
-
unless defined?(FIXTURE_PATH)
|
8
|
-
FIXTURE_PATH = File.join(File.dirname(__FILE__), '/fixtures')
|
9
|
-
SCRATCH_PATH = File.join(File.dirname(__FILE__), '/tmp')
|
10
|
-
|
11
|
-
COUCHHOST = "http://127.0.0.1:5984"
|
12
|
-
TESTDB = 'couchrest-test'
|
13
|
-
TEST_SERVER = CouchRest.new
|
14
|
-
TEST_SERVER.default_database = TESTDB
|
15
|
-
end
|
16
|
-
|
17
|
-
class Basic < CouchRest::ExtendedDocument
|
18
|
-
use_database TEST_SERVER.default_database
|
19
|
-
end
|
20
|
-
|
21
|
-
def reset_test_db!
|
22
|
-
cr = TEST_SERVER
|
23
|
-
db = cr.database(TESTDB)
|
24
|
-
db.recreate! rescue nil
|
25
|
-
db
|
26
|
-
end
|
data/utils/remap.rb
DELETED
@@ -1,27 +0,0 @@
|
|
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
DELETED
@@ -1,30 +0,0 @@
|
|
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
|
-
|