oedipus-dm 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/oedipus/data_mapper/index.rb +22 -7
- data/lib/oedipus/data_mapper/version.rb +1 -1
- data/spec/integration/index_spec.rb +29 -0
- metadata +13 -13
@@ -200,6 +200,17 @@ module Oedipus
|
|
200
200
|
}
|
201
201
|
end
|
202
202
|
|
203
|
+
# Fetch a specific record from the index, or nil if it's not in the index.
|
204
|
+
#
|
205
|
+
# @param [Fixnum] id
|
206
|
+
# the id of the resource to fetch
|
207
|
+
#
|
208
|
+
# @return [DataMapper::Resource]
|
209
|
+
# the resource, or nil if not found
|
210
|
+
def fetch(id)
|
211
|
+
build_resource(raw.fetch(id))
|
212
|
+
end
|
213
|
+
|
203
214
|
# Map an attribute in the index with a property on the model.
|
204
215
|
#
|
205
216
|
# @param [Symbol] attr
|
@@ -232,14 +243,18 @@ module Oedipus
|
|
232
243
|
end
|
233
244
|
end
|
234
245
|
|
246
|
+
def build_resource(record)
|
247
|
+
return if record.nil?
|
248
|
+
|
249
|
+
record.inject(model.new) { |r, (k, v)|
|
250
|
+
r.tap { @mappings[k][:set].call(r, v) if @mappings.key?(k) && @mappings[k][:set] }
|
251
|
+
}.tap { |r|
|
252
|
+
r.persistence_state = ::DataMapper::Resource::PersistenceState::Clean.new(r)
|
253
|
+
}
|
254
|
+
end
|
255
|
+
|
235
256
|
def build_collection(result)
|
236
|
-
resources = result[:records].collect
|
237
|
-
record.inject(model.new) { |r, (k, v)|
|
238
|
-
r.tap { @mappings[k][:set].call(r, v) if @mappings.key?(k) && @mappings[k][:set] }
|
239
|
-
}.tap { |r|
|
240
|
-
r.persistence_state = ::DataMapper::Resource::PersistenceState::Clean.new(r)
|
241
|
-
}
|
242
|
-
end
|
257
|
+
resources = result[:records].collect { |record| build_resource(record) }
|
243
258
|
|
244
259
|
query = ::DataMapper::Query.new(
|
245
260
|
model.repository,
|
@@ -46,6 +46,35 @@ describe Oedipus::DataMapper::Index do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
describe "#fetch" do
|
50
|
+
let(:user) do
|
51
|
+
User.create(username: "bob")
|
52
|
+
end
|
53
|
+
|
54
|
+
let(:post) do
|
55
|
+
Post.create(
|
56
|
+
title: "There was one was a badger",
|
57
|
+
body: "And a nice one he was.",
|
58
|
+
user: user,
|
59
|
+
view_count: 98
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
before(:each) do
|
64
|
+
conn[:posts_rt].insert(
|
65
|
+
post.id,
|
66
|
+
title: post.title,
|
67
|
+
body: post.body,
|
68
|
+
user_id: post.user_id,
|
69
|
+
views: post.view_count
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "fetches an individual resource from the index" do
|
74
|
+
index.fetch(post.id).should == post
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
49
78
|
pending "the sphinxql grammar does not currently support this, though I'm patching it" do
|
50
79
|
describe "#update" do
|
51
80
|
let(:user) do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oedipus-dm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-05-26 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oedipus
|
16
|
-
requirement: &
|
16
|
+
requirement: &17714040 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.0.5
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *17714040
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: dm-core
|
27
|
-
requirement: &
|
27
|
+
requirement: &17710580 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '1.2'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *17710580
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &17721180 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *17721180
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &17733380 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *17733380
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: dm-pager
|
60
|
-
requirement: &
|
60
|
+
requirement: &17727280 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *17727280
|
69
69
|
description: ! '== DataMapper Integration for Oedipus
|
70
70
|
|
71
71
|
|
@@ -117,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
117
|
version: '0'
|
118
118
|
segments:
|
119
119
|
- 0
|
120
|
-
hash:
|
120
|
+
hash: 1802437292701062016
|
121
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
122
|
none: false
|
123
123
|
requirements:
|
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
126
|
version: '0'
|
127
127
|
segments:
|
128
128
|
- 0
|
129
|
-
hash:
|
129
|
+
hash: 1802437292701062016
|
130
130
|
requirements: []
|
131
131
|
rubyforge_project:
|
132
132
|
rubygems_version: 1.8.11
|