couchrest 0.38 → 1.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -8
- data/Rakefile +3 -4
- data/couchrest.gemspec +25 -105
- data/history.txt +5 -4
- data/lib/couchrest.rb +31 -52
- data/lib/couchrest/{core/database.rb → database.rb} +6 -11
- data/lib/couchrest/{core/design.rb → design.rb} +2 -2
- data/lib/couchrest/{core/document.rb → document.rb} +1 -1
- data/lib/couchrest/helper/attachments.rb +29 -0
- data/lib/couchrest/middlewares/logger.rb +3 -3
- data/lib/couchrest/monkeypatches.rb +1 -71
- data/lib/couchrest/{core/response.rb → response.rb} +0 -0
- data/lib/couchrest/{core/rest_api.rb → rest_api.rb} +8 -12
- data/lib/couchrest/{core/server.rb → server.rb} +0 -2
- data/spec/couchrest/{core/couchrest_spec.rb → couchrest_spec.rb} +15 -9
- data/spec/couchrest/{core/database_spec.rb → database_spec.rb} +4 -4
- data/spec/couchrest/{core/design_spec.rb → design_spec.rb} +2 -2
- data/spec/couchrest/{core/document_spec.rb → document_spec.rb} +1 -1
- data/spec/couchrest/{core/server_spec.rb → server_spec.rb} +2 -2
- data/spec/spec.opts +0 -1
- data/spec/spec_helper.rb +0 -4
- metadata +32 -133
- data/examples/model/example.rb +0 -144
- data/lib/couchrest/core/adapters/restclient.rb +0 -35
- data/lib/couchrest/core/http_abstraction.rb +0 -48
- data/lib/couchrest/core/view.rb +0 -4
- data/lib/couchrest/mixins.rb +0 -4
- data/lib/couchrest/mixins/attachments.rb +0 -31
- data/lib/couchrest/mixins/attribute_protection.rb +0 -74
- data/lib/couchrest/mixins/callbacks.rb +0 -532
- data/lib/couchrest/mixins/class_proxy.rb +0 -124
- data/lib/couchrest/mixins/collection.rb +0 -260
- data/lib/couchrest/mixins/design_doc.rb +0 -103
- data/lib/couchrest/mixins/document_queries.rb +0 -80
- data/lib/couchrest/mixins/extended_attachments.rb +0 -70
- data/lib/couchrest/mixins/extended_document_mixins.rb +0 -9
- data/lib/couchrest/mixins/properties.rb +0 -158
- data/lib/couchrest/mixins/validation.rb +0 -246
- data/lib/couchrest/mixins/views.rb +0 -173
- data/lib/couchrest/more/casted_model.rb +0 -58
- data/lib/couchrest/more/extended_document.rb +0 -310
- data/lib/couchrest/more/property.rb +0 -58
- data/lib/couchrest/more/typecast.rb +0 -180
- data/lib/couchrest/support/blank.rb +0 -42
- data/lib/couchrest/support/rails.rb +0 -42
- data/lib/couchrest/validation/auto_validate.rb +0 -157
- data/lib/couchrest/validation/contextual_validators.rb +0 -78
- data/lib/couchrest/validation/validation_errors.rb +0 -125
- data/lib/couchrest/validation/validators/absent_field_validator.rb +0 -74
- data/lib/couchrest/validation/validators/confirmation_validator.rb +0 -107
- data/lib/couchrest/validation/validators/format_validator.rb +0 -122
- 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 -139
- data/lib/couchrest/validation/validators/method_validator.rb +0 -89
- data/lib/couchrest/validation/validators/numeric_validator.rb +0 -109
- data/lib/couchrest/validation/validators/required_field_validator.rb +0 -114
- data/spec/couchrest/more/attribute_protection_spec.rb +0 -150
- data/spec/couchrest/more/casted_extended_doc_spec.rb +0 -73
- data/spec/couchrest/more/casted_model_spec.rb +0 -406
- data/spec/couchrest/more/extended_doc_attachment_spec.rb +0 -135
- data/spec/couchrest/more/extended_doc_inherited_spec.rb +0 -40
- data/spec/couchrest/more/extended_doc_spec.rb +0 -807
- data/spec/couchrest/more/extended_doc_subclass_spec.rb +0 -98
- data/spec/couchrest/more/extended_doc_view_spec.rb +0 -456
- data/spec/couchrest/more/property_spec.rb +0 -628
- data/spec/fixtures/more/article.rb +0 -35
- data/spec/fixtures/more/card.rb +0 -22
- data/spec/fixtures/more/cat.rb +0 -20
- data/spec/fixtures/more/course.rb +0 -22
- data/spec/fixtures/more/event.rb +0 -8
- data/spec/fixtures/more/invoice.rb +0 -17
- data/spec/fixtures/more/person.rb +0 -9
- data/spec/fixtures/more/question.rb +0 -6
- data/spec/fixtures/more/service.rb +0 -12
- data/spec/fixtures/more/user.rb +0 -22
@@ -1,35 +0,0 @@
|
|
1
|
-
class Article < CouchRest::ExtendedDocument
|
2
|
-
use_database DB
|
3
|
-
unique_id :slug
|
4
|
-
|
5
|
-
provides_collection :article_details, 'Article', 'by_date', :descending => true, :include_docs => true
|
6
|
-
view_by :date, :descending => true
|
7
|
-
view_by :user_id, :date
|
8
|
-
|
9
|
-
view_by :tags,
|
10
|
-
:map =>
|
11
|
-
"function(doc) {
|
12
|
-
if (doc['couchrest-type'] == 'Article' && doc.tags) {
|
13
|
-
doc.tags.forEach(function(tag){
|
14
|
-
emit(tag, 1);
|
15
|
-
});
|
16
|
-
}
|
17
|
-
}",
|
18
|
-
:reduce =>
|
19
|
-
"function(keys, values, rereduce) {
|
20
|
-
return sum(values);
|
21
|
-
}"
|
22
|
-
|
23
|
-
property :date, :type => 'Date'
|
24
|
-
property :slug, :read_only => true
|
25
|
-
property :title
|
26
|
-
property :tags, :type => ['String']
|
27
|
-
|
28
|
-
timestamps!
|
29
|
-
|
30
|
-
before_save :generate_slug_from_title
|
31
|
-
|
32
|
-
def generate_slug_from_title
|
33
|
-
self['slug'] = title.downcase.gsub(/[^a-z0-9]/,'-').squeeze('-').gsub(/^\-|\-$/,'') if new?
|
34
|
-
end
|
35
|
-
end
|
data/spec/fixtures/more/card.rb
DELETED
@@ -1,22 +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 DB
|
9
|
-
|
10
|
-
# Official Schema
|
11
|
-
property :first_name
|
12
|
-
property :last_name, :alias => :family_name
|
13
|
-
property :read_only_value, :read_only => true
|
14
|
-
property :cast_alias, :cast_as => 'Person', :alias => :calias
|
15
|
-
|
16
|
-
|
17
|
-
timestamps!
|
18
|
-
|
19
|
-
# Validation
|
20
|
-
validates_presence_of :first_name
|
21
|
-
|
22
|
-
end
|
data/spec/fixtures/more/cat.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
class Cat < CouchRest::ExtendedDocument
|
2
|
-
include ::CouchRest::Validation
|
3
|
-
|
4
|
-
# Set the default database to use
|
5
|
-
use_database DB
|
6
|
-
|
7
|
-
property :name, :accessible => true
|
8
|
-
property :toys, :cast_as => ['CatToy'], :default => [], :accessible => true
|
9
|
-
property :favorite_toy, :cast_as => 'CatToy', :accessible => true
|
10
|
-
property :number
|
11
|
-
end
|
12
|
-
|
13
|
-
class CatToy < Hash
|
14
|
-
include ::CouchRest::CastedModel
|
15
|
-
include ::CouchRest::Validation
|
16
|
-
|
17
|
-
property :name
|
18
|
-
|
19
|
-
validates_presence_of :name
|
20
|
-
end
|
@@ -1,22 +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, :cast_as => 'String'
|
8
|
-
property :questions, :cast_as => ['Question']
|
9
|
-
property :professor, :cast_as => 'Person'
|
10
|
-
property :participants, :type => ['Object']
|
11
|
-
property :ends_at, :type => 'Time'
|
12
|
-
property :estimate, :type => 'Float'
|
13
|
-
property :hours, :type => 'Integer'
|
14
|
-
property :profit, :type => 'BigDecimal'
|
15
|
-
property :started_on, :type => 'Date'
|
16
|
-
property :updated_at, :type => 'DateTime'
|
17
|
-
property :active, :type => 'Boolean'
|
18
|
-
property :klass, :type => 'Class'
|
19
|
-
|
20
|
-
view_by :title
|
21
|
-
view_by :dept, :ducktype => true
|
22
|
-
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 DB
|
7
|
-
|
8
|
-
# Official Schema
|
9
|
-
property :client_name
|
10
|
-
property :employee_name
|
11
|
-
property :location
|
12
|
-
|
13
|
-
# Validation
|
14
|
-
validates_presence_of :client_name, :employee_name
|
15
|
-
validates_presence_of :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 DB
|
7
|
-
|
8
|
-
# Official Schema
|
9
|
-
property :name, :length => 4...20
|
10
|
-
property :price, :type => 'Integer'
|
11
|
-
|
12
|
-
end
|
data/spec/fixtures/more/user.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
class User < CouchRest::ExtendedDocument
|
2
|
-
# Set the default database to use
|
3
|
-
use_database DB
|
4
|
-
property :name, :accessible => true
|
5
|
-
property :admin # this will be automatically protected
|
6
|
-
end
|
7
|
-
|
8
|
-
class SpecialUser < CouchRest::ExtendedDocument
|
9
|
-
# Set the default database to use
|
10
|
-
use_database DB
|
11
|
-
property :name # this will not be protected
|
12
|
-
property :admin, :protected => true
|
13
|
-
end
|
14
|
-
|
15
|
-
# There are two modes of protection
|
16
|
-
# 1) Declare accessible poperties, assume all the rest are protected
|
17
|
-
# property :name, :accessible => true
|
18
|
-
# property :admin # this will be automatically protected
|
19
|
-
#
|
20
|
-
# 2) Declare protected properties, assume all the rest are accessible
|
21
|
-
# property :name # this will not be protected
|
22
|
-
# property :admin, :protected => true
|