related 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -0
- data/lib/related/entity.rb +10 -3
- data/lib/related/version.rb +1 -1
- data/test/dump-1.rdb +1 -0
- data/test/dump-2.rdb +1 -1
- data/test/dump-3.rdb +1 -1
- data/test/dump-4.rdb +1 -1
- data/test/follower_test.rb +1 -1
- data/test/model_test.rb +3 -0
- data/test/performance_test.rb +1 -1
- data/test/redis-test-1.conf +1 -8
- data/test/redis-test-2.conf +1 -8
- data/test/redis-test-3.conf +1 -8
- data/test/redis-test-4.conf +1 -8
- data/test/related_test.rb +1 -1
- data/test/test_helper.rb +2 -1
- metadata +9 -8
data/README.md
CHANGED
@@ -188,6 +188,13 @@ node.outgoing(:attending).options(
|
|
188
188
|
)
|
189
189
|
```
|
190
190
|
|
191
|
+
You can also specify a simple model class if you don't need to dynamically
|
192
|
+
instantiate different model classes based on an attribute.
|
193
|
+
|
194
|
+
````ruby
|
195
|
+
Related::Node.find(..., :model => Event)
|
196
|
+
```
|
197
|
+
|
191
198
|
Weight
|
192
199
|
------
|
193
200
|
|
data/lib/related/entity.rb
CHANGED
@@ -203,7 +203,7 @@ module Related
|
|
203
203
|
raise Related::NotFound, id
|
204
204
|
end
|
205
205
|
end
|
206
|
-
klass = options[:model]
|
206
|
+
klass = get_model(options[:model], attributes)
|
207
207
|
klass.new.send(:load_attributes, id, attributes)
|
208
208
|
end
|
209
209
|
|
@@ -216,23 +216,30 @@ module Related
|
|
216
216
|
end
|
217
217
|
end
|
218
218
|
objects = []
|
219
|
+
|
219
220
|
ids.each_with_index do |id,i|
|
220
221
|
if options[:fields]
|
221
222
|
attributes = {}
|
222
223
|
res[i].each_with_index do |value, i|
|
223
224
|
attributes[options[:fields][i]] = value
|
224
225
|
end
|
225
|
-
klass = options[:model]
|
226
|
+
klass = get_model(options[:model], attributes)
|
226
227
|
objects << klass.new.send(:load_attributes, id, attributes)
|
227
228
|
else
|
228
229
|
attributes = res[i].is_a?(Array) ? Hash[*res[i]] : res[i]
|
229
|
-
klass = options[:model]
|
230
|
+
klass = get_model(options[:model], attributes)
|
230
231
|
objects << klass.new.send(:load_attributes, id, attributes)
|
231
232
|
end
|
232
233
|
end
|
233
234
|
objects
|
234
235
|
end
|
235
236
|
|
237
|
+
def self.get_model(model, attributes)
|
238
|
+
return self unless model
|
239
|
+
|
240
|
+
model.is_a?(Proc) ? model.call(attributes) : model
|
241
|
+
end
|
242
|
+
|
236
243
|
def self.pipelined_fetch(ids, &block)
|
237
244
|
Related.redis.pipelined do
|
238
245
|
ids.each do |id|
|
data/lib/related/version.rb
CHANGED
data/test/dump-1.rdb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
REDIS0006�ܳC�Z��V
|
data/test/dump-2.rdb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
REDIS0006�ܳC�Z��V
|
data/test/dump-3.rdb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
REDIS0006�ܳC�Z��V
|
data/test/dump-4.rdb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
REDIS0006�ܳC�Z��V
|
data/test/follower_test.rb
CHANGED
data/test/model_test.rb
CHANGED
@@ -50,6 +50,9 @@ class ModelTest < ActiveModel::TestCase
|
|
50
50
|
nodes = e1.outgoing(:test).nodes.options(:model =>
|
51
51
|
lambda {|attributes| attributes['popularity'].to_f > 0.5 ? Event : Related::Node }).to_a
|
52
52
|
assert_equal Event, nodes.first.class
|
53
|
+
|
54
|
+
nodes = Related::Node.find(e1.id, e2.id, model: Event)
|
55
|
+
assert_equal [Event, Event], nodes.map(&:class)
|
53
56
|
end
|
54
57
|
|
55
58
|
def test_custom_weight
|
data/test/performance_test.rb
CHANGED
data/test/redis-test-1.conf
CHANGED
@@ -105,11 +105,4 @@ databases 16
|
|
105
105
|
# to upgrade. With maxmemory after the limit is reached you'll start to get
|
106
106
|
# errors for write operations, and this may even lead to DB inconsistency.
|
107
107
|
|
108
|
-
# maxmemory <bytes>
|
109
|
-
|
110
|
-
############################### ADVANCED CONFIG ###############################
|
111
|
-
|
112
|
-
# Glue small output buffers together in order to send small replies in a
|
113
|
-
# single TCP packet. Uses a bit more CPU but most of the times it is a win
|
114
|
-
# in terms of number of queries per second. Use 'yes' if unsure.
|
115
|
-
glueoutputbuf yes
|
108
|
+
# maxmemory <bytes>
|
data/test/redis-test-2.conf
CHANGED
@@ -105,11 +105,4 @@ databases 16
|
|
105
105
|
# to upgrade. With maxmemory after the limit is reached you'll start to get
|
106
106
|
# errors for write operations, and this may even lead to DB inconsistency.
|
107
107
|
|
108
|
-
# maxmemory <bytes>
|
109
|
-
|
110
|
-
############################### ADVANCED CONFIG ###############################
|
111
|
-
|
112
|
-
# Glue small output buffers together in order to send small replies in a
|
113
|
-
# single TCP packet. Uses a bit more CPU but most of the times it is a win
|
114
|
-
# in terms of number of queries per second. Use 'yes' if unsure.
|
115
|
-
glueoutputbuf yes
|
108
|
+
# maxmemory <bytes>
|
data/test/redis-test-3.conf
CHANGED
@@ -105,11 +105,4 @@ databases 16
|
|
105
105
|
# to upgrade. With maxmemory after the limit is reached you'll start to get
|
106
106
|
# errors for write operations, and this may even lead to DB inconsistency.
|
107
107
|
|
108
|
-
# maxmemory <bytes>
|
109
|
-
|
110
|
-
############################### ADVANCED CONFIG ###############################
|
111
|
-
|
112
|
-
# Glue small output buffers together in order to send small replies in a
|
113
|
-
# single TCP packet. Uses a bit more CPU but most of the times it is a win
|
114
|
-
# in terms of number of queries per second. Use 'yes' if unsure.
|
115
|
-
glueoutputbuf yes
|
108
|
+
# maxmemory <bytes>
|
data/test/redis-test-4.conf
CHANGED
@@ -105,11 +105,4 @@ databases 16
|
|
105
105
|
# to upgrade. With maxmemory after the limit is reached you'll start to get
|
106
106
|
# errors for write operations, and this may even lead to DB inconsistency.
|
107
107
|
|
108
|
-
# maxmemory <bytes>
|
109
|
-
|
110
|
-
############################### ADVANCED CONFIG ###############################
|
111
|
-
|
112
|
-
# Glue small output buffers together in order to send small replies in a
|
113
|
-
# single TCP packet. Uses a bit more CPU but most of the times it is a win
|
114
|
-
# in terms of number of queries per second. Use 'yes' if unsure.
|
115
|
-
glueoutputbuf yes
|
108
|
+
# maxmemory <bytes>
|
data/test/related_test.rb
CHANGED
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: related
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-10-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
16
|
-
requirement: &
|
16
|
+
requirement: &70134047954640 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>'
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70134047954640
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: redis-namespace
|
27
|
-
requirement: &
|
27
|
+
requirement: &70134047954040 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>'
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.8.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70134047954040
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: activemodel
|
38
|
-
requirement: &
|
38
|
+
requirement: &70134047953660 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70134047953660
|
47
47
|
description: Related is a Redis-backed high performance distributed graph database.
|
48
48
|
email: niklas@sutajio.se
|
49
49
|
executables: []
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- test/active_model_test.rb
|
70
70
|
- test/custom_node_test.rb
|
71
71
|
- test/data_flow_test.rb
|
72
|
+
- test/dump-1.rdb
|
72
73
|
- test/dump-2.rdb
|
73
74
|
- test/dump-3.rdb
|
74
75
|
- test/dump-4.rdb
|