couchrest 1.1.1 → 1.1.2
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/VERSION +1 -0
- data/couchrest.gemspec +3 -3
- data/history.txt +5 -0
- data/lib/couchrest.rb +0 -1
- data/lib/couchrest/attributes.rb +7 -0
- data/lib/couchrest/rest_api.rb +7 -3
- data/spec/couchrest/document_spec.rb +15 -0
- data/spec/couchrest/rest_api_spec.rb +9 -1
- metadata +41 -4
- data/lib/couchrest/version.rb +0 -3
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.1.2
|
data/couchrest.gemspec
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
2
|
+
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{couchrest}
|
5
|
-
s.version =
|
5
|
+
s.version = `cat VERSION`.strip
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["J. Chris Anderson", "Matt Aimonetti", "Marcos Tapajos", "Will Leinweber", "Sam Lown"]
|
9
|
-
s.date =
|
9
|
+
s.date = File.mtime('VERSION')
|
10
10
|
s.description = %q{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.}
|
11
11
|
s.email = %q{jchris@apache.org}
|
12
12
|
|
data/history.txt
CHANGED
data/lib/couchrest.rb
CHANGED
data/lib/couchrest/attributes.rb
CHANGED
@@ -54,6 +54,13 @@ module CouchRest
|
|
54
54
|
_attributes
|
55
55
|
end
|
56
56
|
|
57
|
+
# Provide JSON data hash that can be stored in the database.
|
58
|
+
# Will go through each attribute value and request the `as_couch_json` method
|
59
|
+
# on each if available, or return the value as-is.
|
60
|
+
def as_couch_json
|
61
|
+
_attributes.inject({}) {|h, (k,v)| h[k] = v.respond_to?(:as_couch_json) ? v.as_couch_json : v; h}
|
62
|
+
end
|
63
|
+
|
57
64
|
# Freeze the object's attributes instead of the actual document.
|
58
65
|
# This prevents further modifications to stored data, but does allow access
|
59
66
|
# to local variables useful for callbacks or cached data.
|
data/lib/couchrest/rest_api.rb
CHANGED
@@ -96,10 +96,10 @@ module CouchRest
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
# Prepare
|
99
|
+
# Prepare two hashes, one for the request to the REST backend and a second
|
100
100
|
# for the JSON parser.
|
101
101
|
#
|
102
|
-
# Returns
|
102
|
+
# Returns an array of request and parser options.
|
103
103
|
#
|
104
104
|
def prepare_and_split_options(url, method, options)
|
105
105
|
request = {
|
@@ -132,7 +132,11 @@ module CouchRest
|
|
132
132
|
# * :raw TrueClass, if true the payload will not be altered.
|
133
133
|
#
|
134
134
|
def payload_from_doc(doc, opts = {})
|
135
|
-
(opts.delete(:raw) || doc.nil? || doc.is_a?(IO) || doc.is_a?(Tempfile))
|
135
|
+
if (opts.delete(:raw) || doc.nil? || doc.is_a?(IO) || doc.is_a?(Tempfile))
|
136
|
+
doc
|
137
|
+
else
|
138
|
+
MultiJson.encode(doc.respond_to?(:as_couch_json) ? doc.as_couch_json : doc)
|
139
|
+
end
|
136
140
|
end
|
137
141
|
|
138
142
|
# Parse the response provided.
|
@@ -119,6 +119,21 @@ describe CouchRest::Document do
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
+
describe "#as_couch_json" do
|
123
|
+
it "should provide a hash of data from normal document" do
|
124
|
+
@doc = CouchRest::Document.new('foo' => 'bar')
|
125
|
+
h = @doc.as_couch_json
|
126
|
+
h.should be_a(Hash)
|
127
|
+
h['foo'].should eql('bar')
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should handle nested documents" do
|
131
|
+
@doc = CouchRest::Document.new('foo' => 'bar', 'doc' => CouchRest::Document.new('foo2' => 'bar2'))
|
132
|
+
h = @doc.as_couch_json
|
133
|
+
h['doc'].should be_a(Hash)
|
134
|
+
h['doc']['foo2'].should eql('bar2')
|
135
|
+
end
|
136
|
+
end
|
122
137
|
|
123
138
|
describe "#inspect" do
|
124
139
|
it "should provide a string of keys and values of the Response" do
|
@@ -152,7 +152,15 @@ describe CouchRest::RestAPI do
|
|
152
152
|
f.close
|
153
153
|
end
|
154
154
|
|
155
|
-
|
155
|
+
it "should use as_couch_json method if available" do
|
156
|
+
h = {'foo' => 'bar'}
|
157
|
+
doc = CouchRest::Document.new(h)
|
158
|
+
doc.should_receive(:as_couch_json).and_return(h)
|
159
|
+
request.should_receive(:execute).and_return(simple_response)
|
160
|
+
parser.should_receive(:encode).with(h)
|
161
|
+
parser.should_receive(:decode).with(simple_response, parser_opts)
|
162
|
+
CouchRest.post('foo', doc)
|
163
|
+
end
|
156
164
|
end
|
157
165
|
|
158
166
|
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couchrest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
4
5
|
prerelease:
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
- 2
|
10
|
+
version: 1.1.2
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- J. Chris Anderson
|
@@ -14,7 +19,7 @@ autorequire:
|
|
14
19
|
bindir: bin
|
15
20
|
cert_chain: []
|
16
21
|
|
17
|
-
date: 2011-
|
22
|
+
date: 2011-07-23 00:00:00 +02:00
|
18
23
|
default_executable:
|
19
24
|
dependencies:
|
20
25
|
- !ruby/object:Gem::Dependency
|
@@ -25,6 +30,11 @@ dependencies:
|
|
25
30
|
requirements:
|
26
31
|
- - ~>
|
27
32
|
- !ruby/object:Gem::Version
|
33
|
+
hash: 13
|
34
|
+
segments:
|
35
|
+
- 1
|
36
|
+
- 6
|
37
|
+
- 1
|
28
38
|
version: 1.6.1
|
29
39
|
type: :runtime
|
30
40
|
version_requirements: *id001
|
@@ -36,6 +46,10 @@ dependencies:
|
|
36
46
|
requirements:
|
37
47
|
- - ~>
|
38
48
|
- !ruby/object:Gem::Version
|
49
|
+
hash: 17
|
50
|
+
segments:
|
51
|
+
- 1
|
52
|
+
- 15
|
39
53
|
version: "1.15"
|
40
54
|
type: :runtime
|
41
55
|
version_requirements: *id002
|
@@ -47,6 +61,11 @@ dependencies:
|
|
47
61
|
requirements:
|
48
62
|
- - ~>
|
49
63
|
- !ruby/object:Gem::Version
|
64
|
+
hash: 23
|
65
|
+
segments:
|
66
|
+
- 1
|
67
|
+
- 0
|
68
|
+
- 0
|
50
69
|
version: 1.0.0
|
51
70
|
type: :runtime
|
52
71
|
version_requirements: *id003
|
@@ -58,6 +77,11 @@ dependencies:
|
|
58
77
|
requirements:
|
59
78
|
- - ~>
|
60
79
|
- !ruby/object:Gem::Version
|
80
|
+
hash: 1
|
81
|
+
segments:
|
82
|
+
- 1
|
83
|
+
- 5
|
84
|
+
- 1
|
61
85
|
version: 1.5.1
|
62
86
|
type: :development
|
63
87
|
version_requirements: *id004
|
@@ -69,6 +93,11 @@ dependencies:
|
|
69
93
|
requirements:
|
70
94
|
- - ~>
|
71
95
|
- !ruby/object:Gem::Version
|
96
|
+
hash: 23
|
97
|
+
segments:
|
98
|
+
- 2
|
99
|
+
- 6
|
100
|
+
- 0
|
72
101
|
version: 2.6.0
|
73
102
|
type: :development
|
74
103
|
version_requirements: *id005
|
@@ -89,6 +118,7 @@ files:
|
|
89
118
|
- README.md
|
90
119
|
- Rakefile
|
91
120
|
- THANKS.md
|
121
|
+
- VERSION
|
92
122
|
- couchrest.gemspec
|
93
123
|
- examples/word_count/markov
|
94
124
|
- examples/word_count/views/books/chunked-map.js
|
@@ -118,7 +148,6 @@ files:
|
|
118
148
|
- lib/couchrest/rest_api.rb
|
119
149
|
- lib/couchrest/server.rb
|
120
150
|
- lib/couchrest/support/inheritable_attributes.rb
|
121
|
-
- lib/couchrest/version.rb
|
122
151
|
- spec/.gitignore
|
123
152
|
- spec/couchrest/couchrest_spec.rb
|
124
153
|
- spec/couchrest/database_spec.rb
|
@@ -154,17 +183,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
154
183
|
requirements:
|
155
184
|
- - ">="
|
156
185
|
- !ruby/object:Gem::Version
|
186
|
+
hash: 3
|
187
|
+
segments:
|
188
|
+
- 0
|
157
189
|
version: "0"
|
158
190
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
191
|
none: false
|
160
192
|
requirements:
|
161
193
|
- - ">"
|
162
194
|
- !ruby/object:Gem::Version
|
195
|
+
hash: 25
|
196
|
+
segments:
|
197
|
+
- 1
|
198
|
+
- 3
|
199
|
+
- 1
|
163
200
|
version: 1.3.1
|
164
201
|
requirements: []
|
165
202
|
|
166
203
|
rubyforge_project:
|
167
|
-
rubygems_version: 1.
|
204
|
+
rubygems_version: 1.6.2
|
168
205
|
signing_key:
|
169
206
|
specification_version: 3
|
170
207
|
summary: Lean and RESTful interface to CouchDB.
|
data/lib/couchrest/version.rb
DELETED