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.
Files changed (97) hide show
  1. data/README +39 -0
  2. data/Rakefile +3 -54
  3. data/lib/couchrest.rb +39 -161
  4. data/lib/database.rb +83 -0
  5. data/script/couchdir +58 -0
  6. data/script/couchview +158 -0
  7. data/spec/couchrest_spec.rb +86 -0
  8. data/spec/database_spec.rb +407 -0
  9. metadata +15 -138
  10. data/LICENSE +0 -176
  11. data/README.md +0 -93
  12. data/THANKS.md +0 -18
  13. data/examples/model/example.rb +0 -144
  14. data/examples/word_count/markov +0 -38
  15. data/examples/word_count/views/books/chunked-map.js +0 -3
  16. data/examples/word_count/views/books/united-map.js +0 -1
  17. data/examples/word_count/views/markov/chain-map.js +0 -6
  18. data/examples/word_count/views/markov/chain-reduce.js +0 -7
  19. data/examples/word_count/views/word_count/count-map.js +0 -6
  20. data/examples/word_count/views/word_count/count-reduce.js +0 -3
  21. data/examples/word_count/word_count.rb +0 -46
  22. data/examples/word_count/word_count_query.rb +0 -40
  23. data/examples/word_count/word_count_views.rb +0 -26
  24. data/lib/couchrest/commands/generate.rb +0 -71
  25. data/lib/couchrest/commands/push.rb +0 -103
  26. data/lib/couchrest/core/database.rb +0 -318
  27. data/lib/couchrest/core/design.rb +0 -89
  28. data/lib/couchrest/core/document.rb +0 -96
  29. data/lib/couchrest/core/response.rb +0 -16
  30. data/lib/couchrest/core/server.rb +0 -88
  31. data/lib/couchrest/core/view.rb +0 -4
  32. data/lib/couchrest/helper/pager.rb +0 -103
  33. data/lib/couchrest/helper/streamer.rb +0 -44
  34. data/lib/couchrest/helper/upgrade.rb +0 -51
  35. data/lib/couchrest/mixins.rb +0 -4
  36. data/lib/couchrest/mixins/attachments.rb +0 -31
  37. data/lib/couchrest/mixins/callbacks.rb +0 -483
  38. data/lib/couchrest/mixins/design_doc.rb +0 -64
  39. data/lib/couchrest/mixins/document_queries.rb +0 -48
  40. data/lib/couchrest/mixins/extended_attachments.rb +0 -68
  41. data/lib/couchrest/mixins/extended_document_mixins.rb +0 -6
  42. data/lib/couchrest/mixins/properties.rb +0 -125
  43. data/lib/couchrest/mixins/validation.rb +0 -234
  44. data/lib/couchrest/mixins/views.rb +0 -168
  45. data/lib/couchrest/monkeypatches.rb +0 -119
  46. data/lib/couchrest/more/casted_model.rb +0 -28
  47. data/lib/couchrest/more/extended_document.rb +0 -217
  48. data/lib/couchrest/more/property.rb +0 -40
  49. data/lib/couchrest/support/blank.rb +0 -42
  50. data/lib/couchrest/support/class.rb +0 -191
  51. data/lib/couchrest/validation/auto_validate.rb +0 -163
  52. data/lib/couchrest/validation/contextual_validators.rb +0 -78
  53. data/lib/couchrest/validation/validation_errors.rb +0 -118
  54. data/lib/couchrest/validation/validators/absent_field_validator.rb +0 -74
  55. data/lib/couchrest/validation/validators/confirmation_validator.rb +0 -99
  56. data/lib/couchrest/validation/validators/format_validator.rb +0 -117
  57. data/lib/couchrest/validation/validators/formats/email.rb +0 -66
  58. data/lib/couchrest/validation/validators/formats/url.rb +0 -43
  59. data/lib/couchrest/validation/validators/generic_validator.rb +0 -120
  60. data/lib/couchrest/validation/validators/length_validator.rb +0 -134
  61. data/lib/couchrest/validation/validators/method_validator.rb +0 -89
  62. data/lib/couchrest/validation/validators/numeric_validator.rb +0 -104
  63. data/lib/couchrest/validation/validators/required_field_validator.rb +0 -109
  64. data/spec/couchrest/core/couchrest_spec.rb +0 -201
  65. data/spec/couchrest/core/database_spec.rb +0 -745
  66. data/spec/couchrest/core/design_spec.rb +0 -131
  67. data/spec/couchrest/core/document_spec.rb +0 -311
  68. data/spec/couchrest/core/server_spec.rb +0 -35
  69. data/spec/couchrest/helpers/pager_spec.rb +0 -122
  70. data/spec/couchrest/helpers/streamer_spec.rb +0 -23
  71. data/spec/couchrest/more/casted_extended_doc_spec.rb +0 -40
  72. data/spec/couchrest/more/casted_model_spec.rb +0 -98
  73. data/spec/couchrest/more/extended_doc_attachment_spec.rb +0 -130
  74. data/spec/couchrest/more/extended_doc_spec.rb +0 -509
  75. data/spec/couchrest/more/extended_doc_view_spec.rb +0 -207
  76. data/spec/couchrest/more/property_spec.rb +0 -130
  77. data/spec/couchrest/support/class_spec.rb +0 -59
  78. data/spec/fixtures/attachments/README +0 -3
  79. data/spec/fixtures/attachments/couchdb.png +0 -0
  80. data/spec/fixtures/attachments/test.html +0 -11
  81. data/spec/fixtures/more/article.rb +0 -34
  82. data/spec/fixtures/more/card.rb +0 -20
  83. data/spec/fixtures/more/course.rb +0 -14
  84. data/spec/fixtures/more/event.rb +0 -6
  85. data/spec/fixtures/more/invoice.rb +0 -17
  86. data/spec/fixtures/more/person.rb +0 -8
  87. data/spec/fixtures/more/question.rb +0 -6
  88. data/spec/fixtures/more/service.rb +0 -12
  89. data/spec/fixtures/views/lib.js +0 -3
  90. data/spec/fixtures/views/test_view/lib.js +0 -3
  91. data/spec/fixtures/views/test_view/only-map.js +0 -4
  92. data/spec/fixtures/views/test_view/test-map.js +0 -3
  93. data/spec/fixtures/views/test_view/test-reduce.js +0 -3
  94. data/spec/spec.opts +0 -6
  95. data/spec/spec_helper.rb +0 -26
  96. data/utils/remap.rb +0 -27
  97. data/utils/subset.rb +0 -30
metadata CHANGED
@@ -1,21 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jchris-couchrest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.7.99
5
5
  platform: ruby
6
6
  authors:
7
7
  - J. Chris Anderson
8
- - Matt Aimonetti
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
11
 
13
- date: 2008-11-22 00:00:00 -08:00
12
+ date: 2008-06-20 00:00:00 -07:00
14
13
  default_executable:
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: json
18
- type: :runtime
19
17
  version_requirement:
20
18
  version_requirements: !ruby/object:Gem::Requirement
21
19
  requirements:
@@ -25,152 +23,31 @@ dependencies:
25
23
  version:
26
24
  - !ruby/object:Gem::Dependency
27
25
  name: rest-client
28
- type: :runtime
29
26
  version_requirement:
30
27
  version_requirements: !ruby/object:Gem::Requirement
31
28
  requirements:
32
29
  - - ">="
33
30
  - !ruby/object:Gem::Version
34
- version: "0.5"
35
- version:
36
- - !ruby/object:Gem::Dependency
37
- name: mime-types
38
- type: :runtime
39
- version_requirement:
40
- version_requirements: !ruby/object:Gem::Requirement
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- version: "1.15"
31
+ version: "0.4"
45
32
  version:
46
33
  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.
47
- email: jchris@apache.org
34
+ email: jchris@grabb.it
48
35
  executables: []
49
36
 
50
37
  extensions: []
51
38
 
52
- extra_rdoc_files:
53
- - README.md
54
- - LICENSE
55
- - THANKS.md
39
+ extra_rdoc_files: []
40
+
56
41
  files:
57
- - LICENSE
58
- - README.md
59
- - Rakefile
60
- - THANKS.md
61
- - examples/model
62
- - examples/model/example.rb
63
- - examples/word_count
64
- - examples/word_count/markov
65
- - examples/word_count/views
66
- - examples/word_count/views/books
67
- - examples/word_count/views/books/chunked-map.js
68
- - examples/word_count/views/books/united-map.js
69
- - examples/word_count/views/markov
70
- - examples/word_count/views/markov/chain-map.js
71
- - examples/word_count/views/markov/chain-reduce.js
72
- - examples/word_count/views/word_count
73
- - examples/word_count/views/word_count/count-map.js
74
- - examples/word_count/views/word_count/count-reduce.js
75
- - examples/word_count/word_count.rb
76
- - examples/word_count/word_count_query.rb
77
- - examples/word_count/word_count_views.rb
78
- - lib/couchrest
79
- - lib/couchrest/commands
80
- - lib/couchrest/commands/generate.rb
81
- - lib/couchrest/commands/push.rb
82
- - lib/couchrest/core
83
- - lib/couchrest/core/database.rb
84
- - lib/couchrest/core/design.rb
85
- - lib/couchrest/core/document.rb
86
- - lib/couchrest/core/response.rb
87
- - lib/couchrest/core/server.rb
88
- - lib/couchrest/core/view.rb
89
- - lib/couchrest/helper
90
- - lib/couchrest/helper/pager.rb
91
- - lib/couchrest/helper/streamer.rb
92
- - lib/couchrest/helper/upgrade.rb
93
- - lib/couchrest/mixins
94
- - lib/couchrest/mixins/attachments.rb
95
- - lib/couchrest/mixins/callbacks.rb
96
- - lib/couchrest/mixins/design_doc.rb
97
- - lib/couchrest/mixins/document_queries.rb
98
- - lib/couchrest/mixins/extended_attachments.rb
99
- - lib/couchrest/mixins/extended_document_mixins.rb
100
- - lib/couchrest/mixins/properties.rb
101
- - lib/couchrest/mixins/validation.rb
102
- - lib/couchrest/mixins/views.rb
103
- - lib/couchrest/mixins.rb
104
- - lib/couchrest/monkeypatches.rb
105
- - lib/couchrest/more
106
- - lib/couchrest/more/casted_model.rb
107
- - lib/couchrest/more/extended_document.rb
108
- - lib/couchrest/more/property.rb
109
- - lib/couchrest/support
110
- - lib/couchrest/support/blank.rb
111
- - lib/couchrest/support/class.rb
112
- - lib/couchrest/validation
113
- - lib/couchrest/validation/auto_validate.rb
114
- - lib/couchrest/validation/contextual_validators.rb
115
- - lib/couchrest/validation/validation_errors.rb
116
- - lib/couchrest/validation/validators
117
- - lib/couchrest/validation/validators/absent_field_validator.rb
118
- - lib/couchrest/validation/validators/confirmation_validator.rb
119
- - lib/couchrest/validation/validators/format_validator.rb
120
- - lib/couchrest/validation/validators/formats
121
- - lib/couchrest/validation/validators/formats/email.rb
122
- - lib/couchrest/validation/validators/formats/url.rb
123
- - lib/couchrest/validation/validators/generic_validator.rb
124
- - lib/couchrest/validation/validators/length_validator.rb
125
- - lib/couchrest/validation/validators/method_validator.rb
126
- - lib/couchrest/validation/validators/numeric_validator.rb
127
- - lib/couchrest/validation/validators/required_field_validator.rb
128
42
  - lib/couchrest.rb
129
- - spec/couchrest
130
- - spec/couchrest/core
131
- - spec/couchrest/core/couchrest_spec.rb
132
- - spec/couchrest/core/database_spec.rb
133
- - spec/couchrest/core/design_spec.rb
134
- - spec/couchrest/core/document_spec.rb
135
- - spec/couchrest/core/server_spec.rb
136
- - spec/couchrest/helpers
137
- - spec/couchrest/helpers/pager_spec.rb
138
- - spec/couchrest/helpers/streamer_spec.rb
139
- - spec/couchrest/more
140
- - spec/couchrest/more/casted_extended_doc_spec.rb
141
- - spec/couchrest/more/casted_model_spec.rb
142
- - spec/couchrest/more/extended_doc_attachment_spec.rb
143
- - spec/couchrest/more/extended_doc_spec.rb
144
- - spec/couchrest/more/extended_doc_view_spec.rb
145
- - spec/couchrest/more/property_spec.rb
146
- - spec/couchrest/support
147
- - spec/couchrest/support/class_spec.rb
148
- - spec/fixtures
149
- - spec/fixtures/attachments
150
- - spec/fixtures/attachments/couchdb.png
151
- - spec/fixtures/attachments/README
152
- - spec/fixtures/attachments/test.html
153
- - spec/fixtures/more
154
- - spec/fixtures/more/article.rb
155
- - spec/fixtures/more/card.rb
156
- - spec/fixtures/more/course.rb
157
- - spec/fixtures/more/event.rb
158
- - spec/fixtures/more/invoice.rb
159
- - spec/fixtures/more/person.rb
160
- - spec/fixtures/more/question.rb
161
- - spec/fixtures/more/service.rb
162
- - spec/fixtures/views
163
- - spec/fixtures/views/lib.js
164
- - spec/fixtures/views/test_view
165
- - spec/fixtures/views/test_view/lib.js
166
- - spec/fixtures/views/test_view/only-map.js
167
- - spec/fixtures/views/test_view/test-map.js
168
- - spec/fixtures/views/test_view/test-reduce.js
169
- - spec/spec.opts
170
- - spec/spec_helper.rb
171
- - utils/remap.rb
172
- - utils/subset.rb
173
- has_rdoc: true
43
+ - lib/database.rb
44
+ - Rakefile
45
+ - README
46
+ - script/couchdir
47
+ - script/couchview
48
+ - spec/couchrest_spec.rb
49
+ - spec/database_spec.rb
50
+ has_rdoc: false
174
51
  homepage: http://github.com/jchris/couchrest
175
52
  post_install_message:
176
53
  rdoc_options: []
@@ -192,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
69
  requirements: []
193
70
 
194
71
  rubyforge_project:
195
- rubygems_version: 1.2.0
72
+ rubygems_version: 1.0.1
196
73
  signing_key:
197
74
  specification_version: 2
198
75
  summary: Lean and RESTful interface to CouchDB.
data/LICENSE DELETED
@@ -1,176 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
data/README.md DELETED
@@ -1,93 +0,0 @@
1
- # CouchRest: CouchDB, close to the metal
2
-
3
- CouchRest is based on [CouchDB's couch.js test
4
- library](http://svn.apache.org/repos/asf/incubator/couchdb/trunk/share/www/script/couch.js),
5
- which I find to be concise, clear, and well designed. CouchRest lightly wraps
6
- CouchDB's HTTP API, managing JSON serialization, and remembering the URI-paths
7
- to CouchDB's API endpoints so you don't have to.
8
-
9
- CouchRest is designed to make a simple base for application and framework-specific object oriented APIs. CouchRest is Object-Mapper agnostic, the parsed JSON it returns from CouchDB shows up as subclasses of Ruby's Hash. Naked JSON, just as it was mean to be.
10
-
11
- ## Easy Install
12
-
13
- Easy Install is moving to RubyForge, heads up for the gem.
14
-
15
- ### Relax, it's RESTful
16
-
17
- The core of Couchrest is Heroku’s excellent REST Client Ruby HTTP wrapper.
18
- REST Client takes all the nastyness of Net::HTTP and gives is a pretty face,
19
- while still giving you more control than Open-URI. I recommend it anytime
20
- you’re interfacing with a well-defined web service.
21
-
22
- ### Running the Specs
23
-
24
- The most complete documentation is the spec/ directory. To validate your
25
- CouchRest install, from the project root directory run `rake`, or `autotest`
26
- (requires RSpec and optionally ZenTest for autotest support).
27
-
28
- ## Examples
29
-
30
- Quick Start:
31
-
32
- # with !, it creates the database if it doesn't already exist
33
- @db = CouchRest.database!("http://127.0.0.1:5984/couchrest-test")
34
- response = @db.save_doc({:key => 'value', 'another key' => 'another value'})
35
- doc = @db.get(response['id'])
36
- puts doc.inspect
37
-
38
- Bulk Save:
39
-
40
- @db.bulk_save([
41
- {"wild" => "and random"},
42
- {"mild" => "yet local"},
43
- {"another" => ["set","of","keys"]}
44
- ])
45
- # returns ids and revs of the current docs
46
- puts @db.documents.inspect
47
-
48
- Creating and Querying Views:
49
-
50
- @db.save_doc({
51
- "_id" => "_design/first",
52
- :views => {
53
- :test => {
54
- :map => "function(doc){for(var w in doc){ if(!w.match(/^_/))emit(w,doc[w])}}"
55
- }
56
- }
57
- })
58
- puts @db.view('first/test')['rows'].inspect
59
-
60
- ## CouchRest::Model
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"]
93
-