mattetti-couchrest 0.2.1.0 → 0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/README.md +6 -31
  2. data/Rakefile +1 -1
  3. data/examples/model/example.rb +13 -19
  4. data/lib/couchrest/core/database.rb +4 -3
  5. data/lib/couchrest/core/model.rb +615 -0
  6. data/lib/couchrest/core/response.rb +4 -5
  7. data/lib/couchrest/core/server.rb +1 -1
  8. data/lib/couchrest/mixins/callbacks.rb +33 -74
  9. data/lib/couchrest/mixins/design_doc.rb +1 -2
  10. data/lib/couchrest/mixins/document_queries.rb +1 -1
  11. data/lib/couchrest/mixins/extended_document_mixins.rb +1 -2
  12. data/lib/couchrest/mixins/properties.rb +3 -8
  13. data/lib/couchrest/mixins/validation.rb +1 -2
  14. data/lib/couchrest/mixins/views.rb +5 -5
  15. data/lib/couchrest/monkeypatches.rb +48 -65
  16. data/lib/couchrest/more/extended_document.rb +8 -75
  17. data/lib/couchrest/more/property.rb +1 -12
  18. data/lib/couchrest/support/class.rb +132 -148
  19. data/lib/couchrest.rb +8 -33
  20. data/spec/couchrest/core/database_spec.rb +23 -28
  21. data/spec/couchrest/core/model_spec.rb +856 -0
  22. data/spec/couchrest/more/casted_model_spec.rb +0 -14
  23. data/spec/couchrest/more/extended_doc_spec.rb +4 -450
  24. data/spec/couchrest/more/property_spec.rb +5 -16
  25. data/spec/spec_helper.rb +0 -4
  26. metadata +3 -16
  27. data/lib/couchrest/mixins/extended_attachments.rb +0 -68
  28. data/lib/couchrest/validation/validators/confirmation_validator.rb +0 -99
  29. data/spec/couchrest/more/casted_extended_doc_spec.rb +0 -40
  30. data/spec/couchrest/more/extended_doc_attachment_spec.rb +0 -129
  31. data/spec/couchrest/more/extended_doc_view_spec.rb +0 -206
  32. data/spec/couchrest/support/class_spec.rb +0 -59
  33. data/spec/fixtures/more/article.rb +0 -34
  34. data/spec/fixtures/more/course.rb +0 -14
  35. data/spec/fixtures/more/event.rb +0 -6
  36. data/spec/fixtures/more/person.rb +0 -8
  37. 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 has been deprecated and replaced by CouchRest::ExtendedDocument
63
-
64
-
65
- ## CouchRest::ExtendedDocument
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", "Matt Aimonetti"]
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"]
@@ -1,38 +1,31 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'couchrest')
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
- SERVER = CouchRest.new
9
- SERVER.default_database = 'couchrest-extendeddoc-example'
9
+ CouchRest::Model.default_database = CouchRest.database!('couchrest-model-example')
10
10
 
11
- class Author < CouchRest::ExtendedDocument
12
- use_database SERVER.default_database
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::ExtendedDocument
21
- use_database SERVER.default_database
22
-
23
- property :title
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::ExtendedDocument
31
- use_database SERVER.default_database
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 = 500 # must be smaller than the uuid count
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(doc, name)
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