mingo 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mingo/connection.rb +5 -1
- data/lib/mingo/cursor.rb +14 -11
- data/lib/mingo/properties.rb +4 -2
- data/spec/mingo_spec.rb +26 -1
- metadata +3 -4
- data/lib/mingo/pagination.rb +0 -29
data/lib/mingo/connection.rb
CHANGED
data/lib/mingo/cursor.rb
CHANGED
@@ -32,16 +32,6 @@ class Mingo
|
|
32
32
|
Hash === selector[:_id] && selector[:_id]["$in"]
|
33
33
|
end
|
34
34
|
|
35
|
-
def next_document
|
36
|
-
if !@query_run && by_ids? && !order
|
37
|
-
limit_ids do
|
38
|
-
preload_cache
|
39
|
-
sort_cache_by_ids
|
40
|
-
end
|
41
|
-
end
|
42
|
-
super
|
43
|
-
end
|
44
|
-
|
45
35
|
def reverse
|
46
36
|
check_modifiable
|
47
37
|
if by_ids? and !order
|
@@ -62,6 +52,19 @@ class Mingo
|
|
62
52
|
end
|
63
53
|
|
64
54
|
private
|
55
|
+
|
56
|
+
alias refresh_without_sorting refresh
|
57
|
+
|
58
|
+
def refresh
|
59
|
+
if !@query_run && by_ids? && !order
|
60
|
+
limit_ids do
|
61
|
+
preload_cache
|
62
|
+
sort_cache_by_ids
|
63
|
+
end
|
64
|
+
else
|
65
|
+
refresh_without_sorting
|
66
|
+
end
|
67
|
+
end
|
65
68
|
|
66
69
|
def limit_ids
|
67
70
|
if @limit > 0 || @skip > 0
|
@@ -82,7 +85,7 @@ class Mingo
|
|
82
85
|
|
83
86
|
def preload_cache
|
84
87
|
begin
|
85
|
-
|
88
|
+
refresh_without_sorting
|
86
89
|
end until @cursor_id.zero? || closed? || @n_received.to_i < 1
|
87
90
|
end
|
88
91
|
|
data/lib/mingo/properties.rb
CHANGED
@@ -11,12 +11,13 @@ class Mingo
|
|
11
11
|
module ClassMethods
|
12
12
|
attr_reader :properties
|
13
13
|
|
14
|
-
def property(name, options =
|
14
|
+
def property(name, options = nil)
|
15
15
|
self.properties << name.to_sym
|
16
16
|
|
17
17
|
setter_name = "#{name}="
|
18
18
|
unless method_defined?(setter_name)
|
19
|
-
|
19
|
+
methods = Module.new
|
20
|
+
methods.module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
20
21
|
def #{name}(&block)
|
21
22
|
self.[](#{name.to_s.inspect}, &block)
|
22
23
|
end
|
@@ -25,6 +26,7 @@ class Mingo
|
|
25
26
|
self.[]=(#{name.to_s.inspect}, value)
|
26
27
|
end
|
27
28
|
RUBY
|
29
|
+
include methods
|
28
30
|
end
|
29
31
|
|
30
32
|
if defined? @subclasses
|
data/spec/mingo_spec.rb
CHANGED
@@ -6,13 +6,32 @@ Mingo.connect('mingo')
|
|
6
6
|
class User < Mingo
|
7
7
|
property :name
|
8
8
|
property :age
|
9
|
+
|
10
|
+
def age=(value)
|
11
|
+
super(value.nil? ? nil : value.to_i)
|
12
|
+
end
|
9
13
|
end
|
10
14
|
|
11
15
|
describe User do
|
12
16
|
before :all do
|
13
17
|
User.collection.remove
|
14
18
|
end
|
15
|
-
|
19
|
+
|
20
|
+
it "has connection" do
|
21
|
+
Mingo.should be_connected
|
22
|
+
User.should be_connected
|
23
|
+
|
24
|
+
old_db = Mingo.db
|
25
|
+
Mingo.db = nil
|
26
|
+
begin
|
27
|
+
Mingo.should_not be_connected
|
28
|
+
User.should_not be_connected
|
29
|
+
User.db.should be_nil
|
30
|
+
ensure
|
31
|
+
Mingo.db = old_db
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
16
35
|
it "obtains an ID by saving" do
|
17
36
|
user = build :name => 'Mislav'
|
18
37
|
user.should_not be_persisted
|
@@ -76,6 +95,12 @@ describe User do
|
|
76
95
|
doc.should have_key('name')
|
77
96
|
end
|
78
97
|
end
|
98
|
+
|
99
|
+
it "supports overloading the setter method" do
|
100
|
+
user = build
|
101
|
+
user.age = '12'
|
102
|
+
user.age.should == 12
|
103
|
+
end
|
79
104
|
|
80
105
|
context "existing doc" do
|
81
106
|
before do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: mingo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.4.
|
5
|
+
version: 0.4.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- "Mislav Marohni\xC4\x87"
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-08-31 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: mongo
|
@@ -39,7 +39,6 @@ files:
|
|
39
39
|
- lib/mingo/cursor.rb
|
40
40
|
- lib/mingo/finders.rb
|
41
41
|
- lib/mingo/many_proxy.rb
|
42
|
-
- lib/mingo/pagination.rb
|
43
42
|
- lib/mingo/persistence.rb
|
44
43
|
- lib/mingo/properties.rb
|
45
44
|
- lib/mingo/timestamps.rb
|
@@ -68,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
67
|
requirements: []
|
69
68
|
|
70
69
|
rubyforge_project:
|
71
|
-
rubygems_version: 1.8.
|
70
|
+
rubygems_version: 1.8.8
|
72
71
|
signing_key:
|
73
72
|
specification_version: 3
|
74
73
|
summary: Minimal Mongo
|
data/lib/mingo/pagination.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'will_paginate/finders/base'
|
2
|
-
|
3
|
-
class Mingo
|
4
|
-
module Pagination
|
5
|
-
def self.extended(base)
|
6
|
-
klass = base::Cursor
|
7
|
-
unless klass.instance_methods.map(&:to_sym).include? :paginate
|
8
|
-
klass.send(:include, PaginatedCursor)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def paginate(options)
|
13
|
-
find.paginate(options)
|
14
|
-
end
|
15
|
-
|
16
|
-
module PaginatedCursor
|
17
|
-
include WillPaginate::Finders::Base
|
18
|
-
|
19
|
-
def wp_query(options, pager, args)
|
20
|
-
self.limit pager.per_page
|
21
|
-
self.skip pager.offset
|
22
|
-
pager.replace self.to_a
|
23
|
-
pager.total_entries = self.count unless pager.total_entries
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
extend Pagination
|
29
|
-
end
|