relix 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjY4Y2ExMjRhYTk5MTJjYjUyYTUwZjE4NWUxZDlmOGEwNGU5YWJjYw==
4
+ NWRmYWJjZWYxNDM0MmU3OTEzOGE4MzFhODI4Y2RhOWU5ZWY3ZThjMA==
5
5
  data.tar.gz: !binary |-
6
- ZjA5NGFhODZhODYyYzZjZjA3MmU1ODA5YTkyM2Q2YWM4ZGZkNjJlYw==
6
+ NzJjMDM1MDdmMzM0ZDgyODU1MmMwN2YxZTA0ODgyYzEzOWRiZDYxZg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- Yzg0NzA4YjczZTI0YzJkZmE2NTJlNzA1NWNkNWJkZTEyNzIzYTU1MjYzYjgz
10
- YWQyYjQ2NjA0MzJmZThjMzJjYTY3YmYyNjZhNGRjYzFhNzhlNmViYWU3ODFl
11
- ZDAwY2Y2OTc4NzFlMzVmNDlhYTMwMDI5ZGI4ZTE3ZGMwZDEwYTI=
9
+ YTNmNGVjN2U2ZDc5OTQ1Mzk5ZmZkNjlhYjI3MTI3N2RlZjQwZDMyMTJjOTZk
10
+ NmEyNWExZmEyNWQ4Y2IyMWIzNWFjMThiMmY1MTgwOWQxMDEzYTk5MTE3MDlj
11
+ Mjg3Y2E4M2EwYmUwMDM4YTNkMmQ1N2JlNzYyNGY4ODE4M2I1YzU=
12
12
  data.tar.gz: !binary |-
13
- ZDA1ZTZjMDMxMzliMDIyZjZmZjIxZjk3MTYxOTAzYTk1NjhjODJiYzFiOTAx
14
- NmZlMDQ4Y2JlNGIzN2RiMTI2MDk3MDM2ODg0NjI0OTg1YmExN2E0NDlmN2Yy
15
- NjQyN2RkYjEzNTQ2YzA2NmIxMjIxMWVkMzE5NjE4ZDg0Y2M3MTk=
13
+ Y2YwODAwZTRkNDI5MTZkMTlhZGVhYmRiOWNkMWUxMjQ1M2JmMzUwYjg5YzFh
14
+ ZWI5N2YyMjJjZTQ4MmM3ZGRjMjlhMWQzNjQ2Zjc0NWYyZmQyNzliZjVkOTFi
15
+ ZTk5MWJiZjAyNjE1ZjJiMTNkYzEyZjNjOWQ4YTQ4NTdmNzFjZDI=
data/HISTORY.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 2.1.0
2
+
3
+ * Make IndexSet lazy-retrieve the Redis client. (ntalbott)
4
+
1
5
  ### 2.0.0
2
6
 
3
7
  * Require Redis 2.6. (ntalbott)
data/lib/relix/core.rb CHANGED
@@ -14,7 +14,7 @@ module Relix
14
14
 
15
15
  module ClassMethods
16
16
  def relix(&block)
17
- @relix ||= IndexSet.new(self, Relix.redis)
17
+ @relix ||= IndexSet.new(self, Relix)
18
18
  if block_given?
19
19
  @relix.instance_eval(&block)
20
20
  else
@@ -2,13 +2,17 @@ module Relix
2
2
  class IndexSet
3
3
  attr_accessor :redis
4
4
  attr_reader :klass
5
- def initialize(klass, redis)
5
+ def initialize(klass, redis_source)
6
6
  @klass = klass
7
- @redis = redis
7
+ @redis_source = redis_source
8
8
  @indexes = Hash.new
9
9
  @keyer = Keyer.default_for(@klass) unless parent
10
10
  end
11
11
 
12
+ def redis
13
+ @redis ||= @redis_source.redis
14
+ end
15
+
12
16
  def primary_key(accessor)
13
17
  @primary_key_index = add_index(:primary_key, accessor)
14
18
  end
@@ -57,38 +61,38 @@ module Relix
57
61
  yield(query)
58
62
  query.run
59
63
  else
60
- primary_key_index.all(@redis)
64
+ primary_key_index.all(redis)
61
65
  end
62
66
  end
63
67
 
64
68
  def lookup_values(index)
65
- self[index].values(@redis)
69
+ self[index].values(redis)
66
70
  end
67
71
 
68
72
  def index_ops(object, pk)
69
73
  current_values_name = current_values_name(pk)
70
- @redis.watch current_values_name
71
- current_values = @redis.hgetall(current_values_name)
74
+ redis.watch current_values_name
75
+ current_values = redis.hgetall(current_values_name)
72
76
 
73
77
  ops = full_index_list.collect do |name,index|
74
78
  value = index.read_normalized(object)
75
79
  old_value = current_values[name]
76
80
 
77
- ((watch = index.watch(value, old_value)) && @redis.watch(*watch))
81
+ ((watch = index.watch(value, old_value)) && redis.watch(*watch))
78
82
 
79
83
  next if value == old_value
80
84
  current_values[name] = value unless index.attribute_immutable?
81
85
 
82
- next unless index.filter(@redis, object, value)
86
+ next unless index.filter(redis, object, value)
83
87
 
84
- query_value = index.query(@redis, value)
88
+ query_value = index.query(redis, value)
85
89
  proc do
86
- index.index(@redis, pk, object, value, old_value, *query_value)
90
+ index.index(redis, pk, object, value, old_value, *query_value)
87
91
  end
88
92
  end.compact
89
93
 
90
94
  ops << proc do
91
- @redis.hmset(current_values_name, *current_values.flatten)
95
+ redis.hmset(current_values_name, *current_values.flatten)
92
96
  end if current_values.any?
93
97
 
94
98
  ops
@@ -107,8 +111,8 @@ module Relix
107
111
 
108
112
  handle_concurrent_modifications(pk) do
109
113
  current_values_name = current_values_name(pk)
110
- @redis.watch current_values_name
111
- current_values = @redis.hgetall(current_values_name)
114
+ redis.watch current_values_name
115
+ current_values = redis.hgetall(current_values_name)
112
116
 
113
117
  full_index_list.map do |name, index|
114
118
  old_value = if index.attribute_immutable?
@@ -117,24 +121,24 @@ module Relix
117
121
  current_values[name]
118
122
  end
119
123
 
120
- ((watch = index.watch(old_value)) && !watch.empty? && @redis.watch(*watch))
121
- proc { index.deindex(@redis, pk, old_value) }
122
- end.tap { |ops| ops << proc { @redis.del current_values_name } }
124
+ ((watch = index.watch(old_value)) && !watch.empty? && redis.watch(*watch))
125
+ proc { index.deindex(redis, pk, old_value) }
126
+ end.tap { |ops| ops << proc { redis.del current_values_name } }
123
127
  end
124
128
  end
125
129
 
126
130
  def deindex_by_primary_key!(pk)
127
131
  handle_concurrent_modifications(pk) do
128
132
  current_values_name = current_values_name(pk)
129
- @redis.watch current_values_name
130
- current_values = @redis.hgetall(current_values_name)
133
+ redis.watch current_values_name
134
+ current_values = redis.hgetall(current_values_name)
131
135
 
132
136
  full_index_list.map do |name, index|
133
137
  old_value = current_values[name]
134
138
 
135
- ((watch = index.watch(old_value)) && !watch.empty? && @redis.watch(*watch))
136
- proc { index.deindex(@redis, pk, old_value) }
137
- end.tap { |ops| ops << proc { @redis.del current_values_name } }
139
+ ((watch = index.watch(old_value)) && !watch.empty? && redis.watch(*watch))
140
+ proc { index.deindex(redis, pk, old_value) }
141
+ end.tap { |ops| ops << proc { redis.del current_values_name } }
138
142
  end
139
143
  end
140
144
 
@@ -171,7 +175,7 @@ module Relix
171
175
  loop do
172
176
  ops = yield
173
177
 
174
- results = @redis.multi do
178
+ results = redis.multi do
175
179
  ops.each do |op|
176
180
  op.call(primary_key)
177
181
  end
data/lib/relix/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Relix
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  REDIS_VERSION = "2.6"
4
4
 
5
5
  class Version
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relix
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathaniel Talbott
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-18 00:00:00.000000000 Z
11
+ date: 2013-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  prerelease: false