mattetti-couchrest 0.2.1.0 → 0.13
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/README.md +6 -31
- data/Rakefile +1 -1
- data/examples/model/example.rb +13 -19
- data/lib/couchrest/core/database.rb +4 -3
- data/lib/couchrest/core/model.rb +615 -0
- data/lib/couchrest/core/response.rb +4 -5
- data/lib/couchrest/core/server.rb +1 -1
- data/lib/couchrest/mixins/callbacks.rb +33 -74
- data/lib/couchrest/mixins/design_doc.rb +1 -2
- data/lib/couchrest/mixins/document_queries.rb +1 -1
- data/lib/couchrest/mixins/extended_document_mixins.rb +1 -2
- data/lib/couchrest/mixins/properties.rb +3 -8
- data/lib/couchrest/mixins/validation.rb +1 -2
- data/lib/couchrest/mixins/views.rb +5 -5
- data/lib/couchrest/monkeypatches.rb +48 -65
- data/lib/couchrest/more/extended_document.rb +8 -75
- data/lib/couchrest/more/property.rb +1 -12
- data/lib/couchrest/support/class.rb +132 -148
- data/lib/couchrest.rb +8 -33
- data/spec/couchrest/core/database_spec.rb +23 -28
- data/spec/couchrest/core/model_spec.rb +856 -0
- data/spec/couchrest/more/casted_model_spec.rb +0 -14
- data/spec/couchrest/more/extended_doc_spec.rb +4 -450
- data/spec/couchrest/more/property_spec.rb +5 -16
- data/spec/spec_helper.rb +0 -4
- metadata +3 -16
- data/lib/couchrest/mixins/extended_attachments.rb +0 -68
- data/lib/couchrest/validation/validators/confirmation_validator.rb +0 -99
- data/spec/couchrest/more/casted_extended_doc_spec.rb +0 -40
- data/spec/couchrest/more/extended_doc_attachment_spec.rb +0 -129
- data/spec/couchrest/more/extended_doc_view_spec.rb +0 -206
- data/spec/couchrest/support/class_spec.rb +0 -59
- data/spec/fixtures/more/article.rb +0 -34
- data/spec/fixtures/more/course.rb +0 -14
- data/spec/fixtures/more/event.rb +0 -6
- data/spec/fixtures/more/person.rb +0 -8
- data/spec/fixtures/more/question.rb +0 -6
data/README.md
CHANGED
@@ -59,35 +59,10 @@ Creating and Querying Views:
|
|
59
59
|
|
60
60
|
## CouchRest::Model
|
61
61
|
|
62
|
-
CouchRest::Model
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
### Callbacks
|
68
|
-
|
69
|
-
`CouchRest::ExtendedDocuments` instances have 2 callbacks already defined for you:
|
70
|
-
`create_callback`, `save_callback`, `update_callback` and `destroy_callback`
|
71
|
-
|
72
|
-
In your document inherits from `CouchRest::ExtendedDocument`, define your callback as follows:
|
73
|
-
|
74
|
-
save_callback :before, :generate_slug_from_name
|
75
|
-
|
76
|
-
CouchRest uses a mixin you can find in lib/mixins/callbacks which is extracted from Rails 3, here are some simple usage examples:
|
77
|
-
|
78
|
-
save_callback :before, :before_method
|
79
|
-
save_callback :after, :after_method, :if => :condition
|
80
|
-
save_callback :around {|r| stuff; yield; stuff }
|
81
|
-
|
82
|
-
Check the mixin or the ExtendedDocument class to see how to implement your own callbacks.
|
83
|
-
|
84
|
-
### Casting
|
85
|
-
|
86
|
-
Often, you will want to store multiple objects within a document, to be able to retrieve your objects when you load the document,
|
87
|
-
you can define some casting rules.
|
88
|
-
|
89
|
-
property :casted_attribute, :cast_as => 'WithCastedModelMixin'
|
90
|
-
property :keywords, :cast_as => ["String"]
|
91
|
-
|
92
|
-
If you want to cast an array of instances from a specific Class, use the trick shown above ["ClassName"]
|
62
|
+
CouchRest::Model is a module designed along the lines of DataMapper::Resource.
|
63
|
+
By subclassing, suddenly you get all sorts of powerful sugar, so that working
|
64
|
+
with CouchDB in your Rails or Merb app is no harder than working with the
|
65
|
+
standard SQL alternatives. See the CouchRest::Model documentation for an
|
66
|
+
example article class that illustrates usage.
|
93
67
|
|
68
|
+
CouchRest::Model will be removed from this package.
|
data/Rakefile
CHANGED
@@ -23,7 +23,7 @@ spec = Gem::Specification.new do |s|
|
|
23
23
|
s.homepage = "http://github.com/jchris/couchrest"
|
24
24
|
s.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."
|
25
25
|
s.has_rdoc = true
|
26
|
-
s.authors = ["J. Chris Anderson"
|
26
|
+
s.authors = ["J. Chris Anderson"]
|
27
27
|
s.files = %w( LICENSE README.md Rakefile THANKS.md ) +
|
28
28
|
Dir["{examples,lib,spec,utils}/**/*"] -
|
29
29
|
Dir["spec/tmp"]
|
data/examples/model/example.rb
CHANGED
@@ -1,38 +1,31 @@
|
|
1
|
-
require
|
1
|
+
require 'rubygems'
|
2
|
+
require 'couchrest'
|
2
3
|
|
3
4
|
def show obj
|
4
5
|
puts obj.inspect
|
5
6
|
puts
|
6
7
|
end
|
7
8
|
|
8
|
-
|
9
|
-
SERVER.default_database = 'couchrest-extendeddoc-example'
|
9
|
+
CouchRest::Model.default_database = CouchRest.database!('couchrest-model-example')
|
10
10
|
|
11
|
-
class Author < CouchRest::
|
12
|
-
|
13
|
-
property :name
|
14
|
-
|
11
|
+
class Author < CouchRest::Model
|
12
|
+
key_accessor :name
|
15
13
|
def drink_scotch
|
16
14
|
puts "... glug type glug ... I'm #{name} ... type glug glug ..."
|
17
15
|
end
|
18
16
|
end
|
19
17
|
|
20
|
-
class Post < CouchRest::
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
property :body
|
25
|
-
property :author, :cast_as => 'Author'
|
18
|
+
class Post < CouchRest::Model
|
19
|
+
key_accessor :title, :body, :author
|
20
|
+
|
21
|
+
cast :author, :as => 'Author'
|
26
22
|
|
27
23
|
timestamps!
|
28
24
|
end
|
29
25
|
|
30
|
-
class Comment < CouchRest::
|
31
|
-
|
32
|
-
|
33
|
-
property :commenter, :cast_as => 'Author'
|
34
|
-
timestamps!
|
35
|
-
|
26
|
+
class Comment < CouchRest::Model
|
27
|
+
cast :commenter, :as => 'Author'
|
28
|
+
|
36
29
|
def post= post
|
37
30
|
self["post_id"] = post.id
|
38
31
|
end
|
@@ -40,6 +33,7 @@ class Comment < CouchRest::ExtendedDocument
|
|
40
33
|
Post.get(self['post_id']) if self['post_id']
|
41
34
|
end
|
42
35
|
|
36
|
+
timestamps!
|
43
37
|
end
|
44
38
|
|
45
39
|
puts "Act I: CRUD"
|
@@ -20,7 +20,7 @@ module CouchRest
|
|
20
20
|
@uri = @root = "#{host}/#{name}"
|
21
21
|
@streamer = Streamer.new(self)
|
22
22
|
@bulk_save_cache = []
|
23
|
-
@bulk_save_cache_limit =
|
23
|
+
@bulk_save_cache_limit = 50
|
24
24
|
end
|
25
25
|
|
26
26
|
# returns the database's uri
|
@@ -90,7 +90,9 @@ module CouchRest
|
|
90
90
|
def fetch_attachment(doc, name)
|
91
91
|
# slug = escape_docid(docid)
|
92
92
|
# name = CGI.escape(name)
|
93
|
+
|
93
94
|
uri = uri_for_attachment(doc, name)
|
95
|
+
|
94
96
|
RestClient.get uri
|
95
97
|
# "#{@uri}/#{slug}/#{name}"
|
96
98
|
end
|
@@ -175,7 +177,6 @@ module CouchRest
|
|
175
177
|
end
|
176
178
|
CouchRest.post "#{@uri}/_bulk_docs", {:docs => docs}
|
177
179
|
end
|
178
|
-
alias :bulk_delete :bulk_save
|
179
180
|
|
180
181
|
# DELETE the document from CouchDB that has the given <tt>_id</tt> and
|
181
182
|
# <tt>_rev</tt>.
|
@@ -279,7 +280,7 @@ module CouchRest
|
|
279
280
|
|
280
281
|
private
|
281
282
|
|
282
|
-
def uri_for_attachment
|
283
|
+
def uri_for_attachment doc, name
|
283
284
|
if doc.is_a?(String)
|
284
285
|
puts "CouchRest::Database#fetch_attachment will eventually require a doc as the first argument, not a doc.id"
|
285
286
|
docid = doc
|