gitmodel 0.0.3 → 0.0.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/Gemfile.lock +1 -1
- data/README.md +4 -0
- data/gitmodel.gemspec +1 -1
- data/lib/gitmodel/persistable.rb +4 -3
- data/spec/gitmodel/persistable_spec.rb +14 -2
- metadata +1 -1
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -48,6 +48,10 @@ Status
|
|
48
48
|
_It is not yet production ready but I'm working on it. Please feel free to
|
49
49
|
contribute tests and/or code to help!_
|
50
50
|
|
51
|
+
I will attempt to follow [Semantic Versioning](http://semver.org/) so 1.0.0
|
52
|
+
will be considered the first stable release, until then the API may change at
|
53
|
+
any time.
|
54
|
+
|
51
55
|
See the "To do" section below for details, but the main thing that needs
|
52
56
|
finishing is support for querying. Right now you can find an instance by it's
|
53
57
|
id, but there is incomplete support (90% complete) for querying, e.g.:
|
data/gitmodel.gemspec
CHANGED
data/lib/gitmodel/persistable.rb
CHANGED
@@ -255,9 +255,6 @@ module GitModel
|
|
255
255
|
results = results[0, limit]
|
256
256
|
end
|
257
257
|
else
|
258
|
-
if limit
|
259
|
-
matching_ids = matching_ids[0, limit]
|
260
|
-
end
|
261
258
|
if order == :asc
|
262
259
|
matching_ids = matching_ids.sort{|a,b| a <=> b}
|
263
260
|
elsif order == :desc
|
@@ -265,6 +262,10 @@ module GitModel
|
|
265
262
|
else
|
266
263
|
raise GitModel::InvalidParams("invalid order: '#{order}'")
|
267
264
|
end
|
265
|
+
if limit
|
266
|
+
|
267
|
+
matching_ids = matching_ids[0, limit]
|
268
|
+
end
|
268
269
|
results = matching_ids.map{|k| find(k)}
|
269
270
|
end
|
270
271
|
|
@@ -454,18 +454,30 @@ describe GitModel::Persistable do
|
|
454
454
|
r.second.id.should == 'one'
|
455
455
|
end
|
456
456
|
|
457
|
-
it 'can limit the number of results returned' do
|
457
|
+
it 'can limit the number of results returned with ascending order' do
|
458
458
|
TestEntity.create!(:id => 'one', :attributes => {:a => 1, :b => 1})
|
459
459
|
TestEntity.create!(:id => 'two', :attributes => {:a => 1, :b => 2})
|
460
460
|
TestEntity.create!(:id => 'three', :attributes => {:a => 1, :b => 3})
|
461
461
|
TestEntity.index!
|
462
462
|
|
463
|
-
r = TestEntity.find_all(:a => 1, :limit => 2)
|
463
|
+
r = TestEntity.find_all(:a => 1, :order => :asc, :limit => 2)
|
464
464
|
r.size.should == 2
|
465
465
|
r.first.id.should == 'one'
|
466
466
|
r.second.id.should == 'three'
|
467
467
|
end
|
468
468
|
|
469
|
+
it 'can limit the number of results returned with descending order' do
|
470
|
+
TestEntity.create!(:id => 'one', :attributes => {:a => 1, :b => 1})
|
471
|
+
TestEntity.create!(:id => 'two', :attributes => {:a => 1, :b => 2})
|
472
|
+
TestEntity.create!(:id => 'three', :attributes => {:a => 1, :b => 3})
|
473
|
+
TestEntity.index!
|
474
|
+
|
475
|
+
r = TestEntity.find_all(:a => 1, :order => :desc, :limit => 2)
|
476
|
+
r.size.should == 2
|
477
|
+
r.first.id.should == 'two'
|
478
|
+
r.second.id.should == 'three'
|
479
|
+
end
|
480
|
+
|
469
481
|
end
|
470
482
|
|
471
483
|
describe '.exists?' do
|