paulcarey-relaxdb 0.3.3 → 0.3.4
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 +2 -0
- data/Rakefile +1 -1
- data/lib/relaxdb/document.rb +5 -4
- data/lib/relaxdb/paginator.rb +11 -2
- data/lib/relaxdb/relaxdb.rb +1 -0
- data/lib/relaxdb/views.rb +3 -3
- data/spec/belongs_to_spec.rb +1 -1
- data/spec/document_spec.rb +10 -3
- data/spec/has_many_spec.rb +29 -0
- data/spec/paginate_spec.rb +9 -0
- data/spec/relaxdb_spec.rb +3 -2
- data/spec/spec_models.rb +2 -0
- metadata +4 -3
data/README.textile
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
h3. What's New?
|
2
2
|
|
3
|
+
* 2009-08-15
|
4
|
+
** A few minor tweaks and patches push the version to 0.3.4, compatible with CouchDB 0.9.1.
|
3
5
|
* 2009-05-27
|
4
6
|
** 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.
|
5
7
|
* 2009-04-19
|
data/Rakefile
CHANGED
data/lib/relaxdb/document.rb
CHANGED
@@ -24,7 +24,7 @@ module RelaxDB
|
|
24
24
|
class_inheritable_accessor :__view_by_list__
|
25
25
|
self.__view_by_list__ = []
|
26
26
|
|
27
|
-
class_inheritable_accessor :belongs_to_rels, :
|
27
|
+
class_inheritable_accessor :belongs_to_rels, :reader => true
|
28
28
|
self.belongs_to_rels = {}
|
29
29
|
|
30
30
|
def self.property(prop, opts={})
|
@@ -306,12 +306,13 @@ module RelaxDB
|
|
306
306
|
alias_method :id, :to_param
|
307
307
|
|
308
308
|
def set_timestamps
|
309
|
+
now = Time.now
|
309
310
|
if new_document? && respond_to?(:created_at)
|
310
311
|
# Don't override it if it's already been set
|
311
|
-
@created_at =
|
312
|
+
@created_at = now if @created_at.nil?
|
312
313
|
end
|
313
314
|
|
314
|
-
@updated_at =
|
315
|
+
@updated_at = now if respond_to?(:updated_at)
|
315
316
|
end
|
316
317
|
|
317
318
|
def create_or_get_proxy(klass, relationship, opts=nil)
|
@@ -372,7 +373,7 @@ module RelaxDB
|
|
372
373
|
@has_many_rels << relationship
|
373
374
|
|
374
375
|
if RelaxDB.create_views?
|
375
|
-
target_class = opts[:class]
|
376
|
+
target_class = opts[:class] || relationship.to_s.singularize.camel_case
|
376
377
|
relationship_as_viewed_by_target = (opts[:known_as] || self.name.snake_case).to_s
|
377
378
|
ViewCreator.has_n(self.name, relationship, target_class, relationship_as_viewed_by_target).save
|
378
379
|
end
|
data/lib/relaxdb/paginator.rb
CHANGED
@@ -50,19 +50,28 @@ module RelaxDB
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def create_next(doc, view_keys)
|
53
|
-
next_key =
|
53
|
+
next_key = view_keys_to_vals doc, view_keys
|
54
54
|
next_key = next_key.length == 1 ? next_key[0] : next_key
|
55
55
|
next_key_docid = doc._id
|
56
56
|
{ :startkey => next_key, :startkey_docid => next_key_docid, :descending => @orig_paginate_params.descending }
|
57
57
|
end
|
58
58
|
|
59
59
|
def create_prev(doc, view_keys)
|
60
|
-
prev_key =
|
60
|
+
prev_key = view_keys_to_vals doc, view_keys
|
61
61
|
prev_key = prev_key.length == 1 ? prev_key[0] : prev_key
|
62
62
|
prev_key_docid = doc._id
|
63
63
|
prev_params = { :startkey => prev_key, :startkey_docid => prev_key_docid, :descending => !@orig_paginate_params.descending }
|
64
64
|
end
|
65
65
|
|
66
|
+
def view_keys_to_vals doc, view_keys
|
67
|
+
view_keys.map do |k|
|
68
|
+
if k.is_a?(Symbol) then doc.send(k)
|
69
|
+
elsif k.is_a?(Proc) then k.call(doc)
|
70
|
+
else k
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
66
75
|
def orig_offset(view_name)
|
67
76
|
if @paginate_params.order_inverted?
|
68
77
|
params = {:startkey => @orig_paginate_params.endkey, :descending => !@orig_paginate_params.descending}
|
data/lib/relaxdb/relaxdb.rb
CHANGED
data/lib/relaxdb/views.rb
CHANGED
@@ -25,7 +25,7 @@ module RelaxDB
|
|
25
25
|
map = <<-QUERY
|
26
26
|
function(doc) {
|
27
27
|
var class_match = #{kls_check kls}
|
28
|
-
if(class_match && #{prop_check}) {
|
28
|
+
if (class_match && #{prop_check}) {
|
29
29
|
emit(#{key}, doc);
|
30
30
|
}
|
31
31
|
}
|
@@ -39,7 +39,7 @@ module RelaxDB
|
|
39
39
|
def self.has_n(client_class, relationship, target_class, relationship_to_client)
|
40
40
|
map = <<-QUERY
|
41
41
|
function(doc) {
|
42
|
-
if(doc.relaxdb_class == "#{target_class}" && doc.#{relationship_to_client}_id)
|
42
|
+
if (doc.relaxdb_class == "#{target_class}" && doc.#{relationship_to_client}_id)
|
43
43
|
emit(doc.#{relationship_to_client}_id, doc);
|
44
44
|
}
|
45
45
|
QUERY
|
@@ -51,7 +51,7 @@ module RelaxDB
|
|
51
51
|
def self.references_many(client_class, relationship, target_class, peers)
|
52
52
|
map = <<-QUERY
|
53
53
|
function(doc) {
|
54
|
-
if(doc.relaxdb_class == "#{target_class}" && doc.#{peers}) {
|
54
|
+
if (doc.relaxdb_class == "#{target_class}" && doc.#{peers}) {
|
55
55
|
var i;
|
56
56
|
for(i = 0; i < doc.#{peers}.length; i++) {
|
57
57
|
emit(doc.#{peers}[i], doc);
|
data/spec/belongs_to_spec.rb
CHANGED
data/spec/document_spec.rb
CHANGED
@@ -165,11 +165,19 @@ describe RelaxDB::Document do
|
|
165
165
|
|
166
166
|
describe "user defined property writer" do
|
167
167
|
|
168
|
-
it "should not be used" do
|
168
|
+
it "should not be used to modify state" do
|
169
169
|
o = BespokeWriter.new(:val => 101).save
|
170
170
|
o = RelaxDB.load o._id
|
171
171
|
o.val.should == 81
|
172
172
|
end
|
173
|
+
|
174
|
+
it "may be used if effectively idempotent" do
|
175
|
+
o = BespokeWriter.new(:tt => "2009/04/01").save
|
176
|
+
RelaxDB.reload(o).tt.should == Time.parse("2009/04/01")
|
177
|
+
|
178
|
+
o = BespokeWriter.new(:tt => Time.now).save
|
179
|
+
RelaxDB.reload(o).tt.should be_close(Time.now, 1)
|
180
|
+
end
|
173
181
|
|
174
182
|
end
|
175
183
|
|
@@ -254,8 +262,7 @@ describe RelaxDB::Document do
|
|
254
262
|
end
|
255
263
|
|
256
264
|
it "should return an empty array when no instances exist" do
|
257
|
-
Atom.all.should
|
258
|
-
Atom.all.should be_empty
|
265
|
+
Atom.all.should == []
|
259
266
|
end
|
260
267
|
|
261
268
|
end
|
data/spec/has_many_spec.rb
CHANGED
@@ -8,6 +8,35 @@ describe RelaxDB::HasManyProxy do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe "has_many" do
|
11
|
+
|
12
|
+
|
13
|
+
describe "target_class in the generated view" do
|
14
|
+
it "should infer the class name from the relationship if not supplied" do
|
15
|
+
view = mock(:view).as_null_object
|
16
|
+
RelaxDB::ViewCreator.should_receive(:has_n).with(
|
17
|
+
"", # client_class
|
18
|
+
:foo_bars, # relationship
|
19
|
+
"FooBar", # target_class
|
20
|
+
"" # relationship_to_client
|
21
|
+
).and_return view
|
22
|
+
klass = Class.new(RelaxDB::Document) do
|
23
|
+
has_many :foo_bars
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should use the class name if supplied" do
|
28
|
+
view = mock(:view).as_null_object
|
29
|
+
RelaxDB::ViewCreator.should_receive(:has_n).with(
|
30
|
+
"", # client_class
|
31
|
+
:foo_bars, # relationship
|
32
|
+
"Bar", # target_class
|
33
|
+
"" # relationship_to_client
|
34
|
+
).and_return view
|
35
|
+
klass = Class.new(RelaxDB::Document) do
|
36
|
+
has_many :foo_bars, :class => "Bar"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
11
40
|
|
12
41
|
it "should be considered enumerable" do
|
13
42
|
u = User.new.save
|
data/spec/paginate_spec.rb
CHANGED
@@ -346,6 +346,15 @@ describe "RelaxDB Pagination" do
|
|
346
346
|
navigate_b_series query
|
347
347
|
end
|
348
348
|
|
349
|
+
it "should pass using lambdas as view_keys" do
|
350
|
+
query = lambda do |page_params|
|
351
|
+
RelaxDB.paginate_view "Letter_by_letter_and_number", :page_params => page_params,
|
352
|
+
:startkey => ["b"], :endkey => ["b", {}], :limit => 2,
|
353
|
+
:attributes => ["b", lambda { |l| l.number } ]
|
354
|
+
end
|
355
|
+
navigate_b_series query
|
356
|
+
end
|
357
|
+
|
349
358
|
end
|
350
359
|
|
351
360
|
end
|
data/spec/relaxdb_spec.rb
CHANGED
@@ -217,8 +217,9 @@ describe RelaxDB do
|
|
217
217
|
ns = (0...100).map { rand(1_000_000_000).to_s }
|
218
218
|
objs = ns.map { |n| Primitives.new :_id => n }
|
219
219
|
RelaxDB.bulk_save! *objs
|
220
|
+
ns = ns.reverse
|
220
221
|
objs = RelaxDB.load! ns
|
221
|
-
(0
|
222
|
+
99.downto(0) do |i|
|
222
223
|
ns[i].should == objs[i]._id
|
223
224
|
end
|
224
225
|
end
|
@@ -249,7 +250,7 @@ describe RelaxDB do
|
|
249
250
|
it "should request a view and return an array" do
|
250
251
|
RelaxDB::DesignDocument.get(RelaxDB.dd).add_view("simple", "map", map_func).save
|
251
252
|
data = RelaxDB.view("simple")
|
252
|
-
data.should
|
253
|
+
data.should == []
|
253
254
|
end
|
254
255
|
|
255
256
|
it "may accept query params" do
|
data/spec/spec_models.rb
CHANGED
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
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Carey
|
@@ -9,7 +9,7 @@ autorequire: relaxdb
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-15 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- spec/view_spec.rb
|
108
108
|
has_rdoc: false
|
109
109
|
homepage: http://github.com/paulcarey/relaxdb/
|
110
|
+
licenses:
|
110
111
|
post_install_message:
|
111
112
|
rdoc_options: []
|
112
113
|
|
@@ -127,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
128
|
requirements: []
|
128
129
|
|
129
130
|
rubyforge_project:
|
130
|
-
rubygems_version: 1.
|
131
|
+
rubygems_version: 1.3.5
|
131
132
|
signing_key:
|
132
133
|
specification_version: 2
|
133
134
|
summary: RelaxDB provides a simple interface to CouchDB
|