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 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
 
@@ -203,7 +203,7 @@ module Related
203
203
  raise Related::NotFound, id
204
204
  end
205
205
  end
206
- klass = options[:model] ? options[:model].call(attributes) : self
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] ? options[:model].call(attributes) : self
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] ? options[:model].call(attributes) : self
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|
@@ -1,3 +1,3 @@
1
1
  module Related
2
- Version = VERSION = '0.6.3'
2
+ Version = VERSION = '0.6.4'
3
3
  end
data/test/dump-1.rdb ADDED
@@ -0,0 +1 @@
1
+ REDIS0006�ܳC�Z��V
data/test/dump-2.rdb CHANGED
@@ -1 +1 @@
1
- REDIS0002
1
+ REDIS0006�ܳCZ��V
data/test/dump-3.rdb CHANGED
@@ -1 +1 @@
1
- REDIS0002
1
+ REDIS0006�ܳCZ��V
data/test/dump-4.rdb CHANGED
@@ -1 +1 @@
1
- REDIS0002
1
+ REDIS0006�ܳCZ��V
@@ -5,7 +5,7 @@ class User < Related::Node
5
5
  include Related::Follower
6
6
  end
7
7
 
8
- class FollowerTest < Test::Unit::TestCase
8
+ class FollowerTest < MiniTest::Unit::TestCase
9
9
 
10
10
  def setup
11
11
  Related.redis.flushall
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
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('test/test_helper')
2
2
  require 'benchmark'
3
3
 
4
- class PerformanceTest < Test::Unit::TestCase
4
+ class PerformanceTest < MiniTest::Unit::TestCase
5
5
 
6
6
  def setup
7
7
  Related.redis.flushall
@@ -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>
@@ -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>
@@ -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>
@@ -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
@@ -1,6 +1,6 @@
1
1
  require File.expand_path('test/test_helper')
2
2
 
3
- class RelatedTest < Test::Unit::TestCase
3
+ class RelatedTest < MiniTest::Unit::TestCase
4
4
 
5
5
  def setup
6
6
  Related.redis.flushall
data/test/test_helper.rb CHANGED
@@ -2,8 +2,9 @@
2
2
  dir = File.dirname(File.expand_path(__FILE__))
3
3
  $LOAD_PATH.unshift dir + '/../lib'
4
4
 
5
+ gem 'minitest'
5
6
  require 'rubygems'
6
- require 'test/unit'
7
+ require 'minitest/unit'
7
8
  require 'related'
8
9
  require 'redis/distributed'
9
10
 
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.3
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: 2012-04-04 00:00:00.000000000 Z
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: &70248787222180 !ruby/object:Gem::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: *70248787222180
24
+ version_requirements: *70134047954640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redis-namespace
27
- requirement: &70248787220860 !ruby/object:Gem::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: *70248787220860
35
+ version_requirements: *70134047954040
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activemodel
38
- requirement: &70248787219920 !ruby/object:Gem::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: *70248787219920
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