paulcarey-relaxdb 0.3.4 → 0.3.5

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.textile CHANGED
@@ -1,7 +1,8 @@
1
1
  h3. What's New?
2
2
 
3
3
  * 2009-08-15
4
- ** A few minor tweaks and patches push the version to 0.3.4, compatible with CouchDB 0.9.1.
4
+ ** A few tweaks, patches and fixes push the version to 0.3.5, compatible with CouchDB 0.9.1 and the 0.10 branch.
5
+ ** The Rails error_messages_for helper is now supported. Thanks to "Balint Erdi":http://github.com/balinterdi.
5
6
  * 2009-05-27
6
7
  ** Added minimal support for data migrations. Although CouchDB's nature removes the necessity for migrations, certain knowledge that all objects possess a particular property can simplify client logic. This desire for simplification is the rationale behind this change.
7
8
  * 2009-04-19
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'spec/rake/spectask'
4
4
 
5
5
  PLUGIN = "relaxdb"
6
6
  NAME = "relaxdb"
7
- GEM_VERSION = "0.3.4"
7
+ GEM_VERSION = "0.3.5"
8
8
  AUTHOR = "Paul Carey"
9
9
  EMAIL = "paul.p.carey@gmail.com"
10
10
  HOMEPAGE = "http://github.com/paulcarey/relaxdb/"
@@ -16,7 +16,7 @@ module RelaxDB
16
16
 
17
17
  def __getobj__
18
18
  unless @objs
19
- @objs = RelaxDB.view "#{@class_name}_all", @params
19
+ @objs = RelaxDB.rf_view "#{@class_name}_all", @params
20
20
  end
21
21
  @objs
22
22
  end
@@ -538,11 +538,11 @@ module RelaxDB
538
538
  define_method by_name do |*params|
539
539
  view_name = "#{self.name}_#{by_name}"
540
540
  if params.empty?
541
- res = RelaxDB.view view_name, opts
541
+ res = RelaxDB.rf_view view_name, opts
542
542
  elsif params[0].is_a? Hash
543
- res = RelaxDB.view view_name, opts.merge(params[0])
543
+ res = RelaxDB.rf_view view_name, opts.merge(params[0])
544
544
  else
545
- res = RelaxDB.view(view_name, :key => params[0]).first
545
+ res = RelaxDB.rf_view(view_name, :key => params[0]).first
546
546
  end
547
547
  end
548
548
  end
@@ -1,15 +1,24 @@
1
1
  class Errors < Hash
2
2
  alias_method :on, :[]
3
+ alias_method :count, :size
4
+
5
+ def full_messages
6
+ full_messages = []
7
+ each_key do |attr|
8
+ full_messages << attr.to_s + ": " + self[attr]
9
+ end
10
+ full_messages
11
+ end
3
12
  end
4
13
 
5
14
  class Time
6
-
15
+
7
16
  # Ensure that all Times are stored as UTC
8
- # Times in the following format may be passed directly to
17
+ # Times in the following format may be passed directly to
9
18
  # Date.new in a JavaScript runtime
10
19
  def to_json
11
20
  utc
12
21
  %Q("#{strftime "%Y/%m/%d %H:%M:%S +0000"}")
13
22
  end
14
-
23
+
15
24
  end
@@ -80,7 +80,7 @@ module RelaxDB
80
80
  end
81
81
  params[:limit] = 1
82
82
 
83
- RelaxDB.view(view_name, params).offset
83
+ RelaxDB.rf_view(view_name, params).offset
84
84
  end
85
85
 
86
86
  end
data/lib/relaxdb/query.rb CHANGED
@@ -7,7 +7,8 @@ module RelaxDB
7
7
  class Query
8
8
 
9
9
  # keys is not included in the standard param as it is significantly different from the others
10
- @@params = %w(key startkey startkey_docid endkey endkey_docid limit update descending skip group group_level reduce include_docs)
10
+ @@params = %w(key startkey startkey_docid endkey endkey_docid limit update
11
+ descending skip group group_level reduce include_docs batch)
11
12
 
12
13
  @@params.each do |param|
13
14
  define_method(param.to_sym) do |*val|
@@ -22,13 +23,9 @@ module RelaxDB
22
23
  end
23
24
  end
24
25
 
25
- def initialize(view_name, params = {})
26
- # CouchDB defaults reduce to true when a reduce func is present
27
- # but returning the map view is typically more useful
28
- reduce(false)
29
-
26
+ def initialize view_name, params = {}
30
27
  @view_name = view_name
31
- params.each { |k, v| send(k, v) }
28
+ params.each { |k, v| send k, v }
32
29
  end
33
30
 
34
31
  def keys(keys=nil)
@@ -145,6 +145,22 @@ module RelaxDB
145
145
 
146
146
  res
147
147
  end
148
+
149
+ #
150
+ # CouchDB defaults reduce to true when a reduce func is present.
151
+ # RelaxDB used to indiscriminately set reduce=false, allowing clients to override
152
+ # if desired. However, as of CouchDB 0.10, such behaviour results in
153
+ # {"error":"query_parse_error","reason":"Invalid URL parameter `reduce` for map view."}
154
+ # View https://issues.apache.org/jira/browse/COUCHDB-383#action_12722350
155
+ #
156
+ # This method is an internal workaround for this change to CouchDB and may
157
+ # be removed if a future change allows for a better solution e.g. map=true
158
+ # or a _map endpoint
159
+ #
160
+ def rf_view view_name, params
161
+ params[:reduce] = false
162
+ view view_name, params
163
+ end
148
164
 
149
165
  def view(view_name, params = {})
150
166
  q = Query.new(view_name, params)
@@ -185,7 +201,8 @@ module RelaxDB
185
201
  raise paginate_params.error_msg if paginate_params.invalid?
186
202
 
187
203
  paginator = Paginator.new(paginate_params, page_params)
188
-
204
+
205
+ atts[:reduce] = false
189
206
  query = Query.new(view_name, atts)
190
207
  query.merge(paginate_params)
191
208
 
data/spec/query_spec.rb CHANGED
@@ -24,55 +24,55 @@ describe RelaxDB::Query do
24
24
 
25
25
  it "should list design document and view name and default reduce to false" do
26
26
  q = RelaxDB::Query.new("mount")
27
- q.view_path.should == "_design//_view/mount?reduce=false"
27
+ q.view_path.should == "_design//_view/mount"
28
28
  end
29
29
 
30
30
  it "should contain URL and JSON encoded key when the key has been set" do
31
31
  q = RelaxDB::Query.new("")
32
32
  q.key("olympus")
33
- q.view_path.should == "_design//_view/?key=%22olympus%22&reduce=false"
33
+ q.view_path.should == "_design//_view/?key=%22olympus%22"
34
34
  end
35
35
 
36
36
  it "should honour startkey, endkey and limit" do
37
37
  q = RelaxDB::Query.new("")
38
38
  q.startkey(["olympus"]).endkey(["vesuvius", 3600]).limit(100)
39
- q.view_path.should == "_design//_view/?startkey=%5B%22olympus%22%5D&endkey=%5B%22vesuvius%22%2C3600%5D&limit=100&reduce=false"
39
+ q.view_path.should == "_design//_view/?startkey=%5B%22olympus%22%5D&endkey=%5B%22vesuvius%22%2C3600%5D&limit=100"
40
40
  end
41
41
 
42
42
  it "should specify a null key if key was set to nil" do
43
43
  q = RelaxDB::Query.new("")
44
44
  q.key(nil)
45
- q.view_path.should == "_design//_view/?key=null&reduce=false"
45
+ q.view_path.should == "_design//_view/?key=null"
46
46
  end
47
47
 
48
48
  it "should specify a null startkey if startkey was set to nil" do
49
49
  q = RelaxDB::Query.new("")
50
50
  q.startkey(nil)
51
- q.view_path.should == "_design//_view/?startkey=null&reduce=false"
51
+ q.view_path.should == "_design//_view/?startkey=null"
52
52
  end
53
53
 
54
54
  it "should specify a null endkey if endkey was set to nil" do
55
55
  q = RelaxDB::Query.new("")
56
56
  q.endkey(nil)
57
- q.view_path.should == "_design//_view/?endkey=null&reduce=false"
57
+ q.view_path.should == "_design//_view/?endkey=null"
58
58
  end
59
59
 
60
60
  it "should not JSON encode the startkey_docid" do
61
61
  q = RelaxDB::Query.new("")
62
62
  q.startkey_docid("foo")
63
- q.view_path.should == "_design//_view/?startkey_docid=foo&reduce=false"
63
+ q.view_path.should == "_design//_view/?startkey_docid=foo"
64
64
  end
65
65
 
66
66
  it "should not JSON encode the endkey_docid" do
67
67
  q = RelaxDB::Query.new("")
68
68
  q.endkey_docid("foo")
69
- q.view_path.should == "_design//_view/?endkey_docid=foo&reduce=false"
69
+ q.view_path.should == "_design//_view/?endkey_docid=foo"
70
70
  end
71
71
 
72
72
  it "should not include design or view if it starts with a _" do
73
73
  q = RelaxDB::Query.new "_"
74
74
  # q.view_path.should == "_"
75
- q.view_path.should == "_?reduce=false"
75
+ q.view_path.should == "_"
76
76
  end
77
77
 
78
78
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paulcarey-relaxdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Carey