couchrest 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.1.2
@@ -1,12 +1,12 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require File.join(File.dirname(__FILE__),'lib','couchrest','version')
2
+
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{couchrest}
5
- s.version = CouchRest::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 = %q{2011-04-06}
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
 
@@ -1,3 +1,8 @@
1
+ == 1.1.2 - 2011-07-18
2
+
3
+ * Minor changes
4
+ * Added `as_couch_json` method. If available, will be called before sending document to JSON encoder.
5
+
1
6
  == 1.1.1 - 2011-07-04
2
7
 
3
8
  * Urgent change
@@ -23,7 +23,6 @@ $:.unshift File.dirname(__FILE__) unless
23
23
  require 'couchrest/monkeypatches'
24
24
  require 'couchrest/rest_api'
25
25
  require 'couchrest/support/inheritable_attributes'
26
- require 'couchrest/version'
27
26
 
28
27
  require 'forwardable'
29
28
 
@@ -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.
@@ -96,10 +96,10 @@ module CouchRest
96
96
  end
97
97
  end
98
98
 
99
- # Prepare a two hashes, one for the request to the REST backend and a second
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 and array of request options and parser options.
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)) ? doc : MultiJson.encode(doc)
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
- version: 1.1.1
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-04-06 00:00:00 +02:00
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.3.9.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.
@@ -1,3 +0,0 @@
1
- module CouchRest
2
- VERSION = '1.1.1'
3
- end