zermelo 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae0c1829b05137f5e13c5207d3566b90f780f9af
4
- data.tar.gz: a5657d99593052349f359f0386c84a7f7c4b69a1
3
+ metadata.gz: a21c0260c1633e48c3203e3418f61a07c181d444
4
+ data.tar.gz: d0ab97b66d0ce06f6350ec2708c42008ee5f4991
5
5
  SHA512:
6
- metadata.gz: 94d2147aeea3514e4df3c2af4e59a1290840c6b4eb367f02ee5ae2633e6b9e10cc1675a044c2c1dce6d93c85843969dac77f4c5096ac60f7af0eaf149b736770
7
- data.tar.gz: 6a01b9dc40dca07ca4be3b65b27c3ca432da402014873306f217ba55c8d0785b263af335d6dd4a69b06d7a4afb94504101e781efee8a0dad90adb1e79275a054
6
+ metadata.gz: cb2ff5d282451aa8e3d1e9d69b8f4bc7abea99020af24ff75e9a8c33bb9b916db312db311b354b10425be5f1f4f7ad9244778900f8fc28764dacb29df4fc9f01
7
+ data.tar.gz: 5de6172e640d28f471a2430d038a3f360236e1c6e3bd2aa4966bf249acc678773854f556190d9ea5153e0628182b4afe1c60df09c76b1b6fa44ee2456aaa7805
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## Zermelo Changelog
2
2
 
3
+ # 1.4.2 - 2015-12-01
4
+
5
+ * methods to dump generated keys and backend key names
6
+
3
7
  # 1.4.1 - 2015-11-24
4
8
 
5
9
  * bugfix require statements
@@ -46,6 +46,16 @@ module Zermelo
46
46
  )
47
47
  end
48
48
 
49
+ def key_dump
50
+ k = Zermelo::Records::Key.new(
51
+ :klass => @parent_klass,
52
+ :name => "by_#{@attribute_name}:*",
53
+ :type => :set,
54
+ :object => :index
55
+ )
56
+ [@backend.key_to_backend_key(k), k]
57
+ end
58
+
49
59
  end
50
60
  end
51
61
  end
@@ -111,6 +111,10 @@ module Zermelo
111
111
  end
112
112
  end
113
113
 
114
+ def key_dump
115
+ [@backend.key_to_backend_key(@record_ids_key), @record_ids_key]
116
+ end
117
+
114
118
  private
115
119
 
116
120
  def _inverse
@@ -39,6 +39,9 @@ module Zermelo
39
39
  )
40
40
  end
41
41
 
42
+ def key_dump
43
+ [@backend.key_to_backend_key(key), key]
44
+ end
42
45
  end
43
46
  end
44
47
  end
@@ -62,6 +62,10 @@ module Zermelo
62
62
  v
63
63
  end
64
64
 
65
+ def key_dump
66
+ [@backend.key_to_backend_key(@record_id_key), @record_id_key]
67
+ end
68
+
65
69
  private
66
70
 
67
71
  # on_remove already runs inside a lock & transaction
@@ -39,6 +39,9 @@ module Zermelo
39
39
  )
40
40
  end
41
41
 
42
+ def key_dump
43
+ [@backend.key_to_backend_key(key), key]
44
+ end
42
45
  end
43
46
  end
44
47
  end
@@ -17,9 +17,9 @@ module Zermelo
17
17
 
18
18
  include Zermelo::Backend
19
19
 
20
- # def default_sorted_set_key
21
- # :time
22
- # end
20
+ def key_to_backend_key(key)
21
+ "TODO"
22
+ end
23
23
 
24
24
  def filter(ids_key, associated_class, callback_target_class = nil,
25
25
  callback_target_id = nil, callbacks = nil, sort_order = nil)
@@ -17,9 +17,24 @@ module Zermelo
17
17
  @changes = nil
18
18
  end
19
19
 
20
- # def default_sorted_set_key
21
- # :timestamp
22
- # end
20
+ def key_to_backend_key(key)
21
+ class_key = key.klass.send(:class_key)
22
+
23
+ obj = case key.object
24
+ when :attribute
25
+ 'attrs'
26
+ when :association
27
+ 'assocs'
28
+ when :index
29
+ 'indices'
30
+ when :temporary
31
+ 'tmp'
32
+ end
33
+
34
+ name = Zermelo::COLLECTION_TYPES.has_key?(key.type) ? ":#{key.name}" : ''
35
+
36
+ "#{class_key}:#{key.id.nil? ? '' : key.id}:#{obj}#{name}"
37
+ end
23
38
 
24
39
  def filter(ids_key, associated_class, callback_target_class = nil,
25
40
  callback_target_id = nil, callbacks = nil, sort_order = nil)
@@ -31,7 +46,7 @@ module Zermelo
31
46
 
32
47
  def get_multiple(*attr_keys)
33
48
  attr_keys.inject({}) do |memo, attr_key|
34
- redis_attr_key = key_to_redis_key(attr_key)
49
+ redis_attr_key = key_to_backend_key(attr_key)
35
50
 
36
51
  class_key = attr_key.klass.send(:class_key)
37
52
 
@@ -124,25 +139,6 @@ module Zermelo
124
139
  true
125
140
  end
126
141
 
127
- def key_to_redis_key(key)
128
- class_key = key.klass.send(:class_key)
129
-
130
- obj = case key.object
131
- when :attribute
132
- 'attrs'
133
- when :association
134
- 'assocs'
135
- when :index
136
- 'indices'
137
- when :temporary
138
- 'tmp'
139
- end
140
-
141
- name = Zermelo::COLLECTION_TYPES.has_key?(key.type) ? ":#{key.name}" : ''
142
-
143
- "#{class_key}:#{key.id.nil? ? '' : key.id}:#{obj}#{name}"
144
- end
145
-
146
142
  def temp_key_wrap
147
143
  return unless block_given?
148
144
  temp_keys = []
@@ -152,7 +148,7 @@ module Zermelo
152
148
  raise
153
149
  ensure
154
150
  unless temp_keys.empty?
155
- Zermelo.redis.del(*temp_keys.collect {|tk| key_to_redis_key(tk)})
151
+ Zermelo.redis.del(*temp_keys.collect {|tk| key_to_backend_key(tk)})
156
152
  temp_keys.clear
157
153
  end
158
154
  end
@@ -171,12 +167,12 @@ module Zermelo
171
167
 
172
168
  idx_key = associated_class.send(:temp_key, type)
173
169
  temp_keys << idx_key
174
- idx_result = key_to_redis_key(idx_key)
170
+ idx_result = key_to_backend_key(idx_key)
175
171
 
176
172
  starts_with_string_re = /^string:/
177
173
  case idx_class.name
178
174
  when 'Zermelo::Associations::UniqueIndex'
179
- index_key = key_to_redis_key(Zermelo::Records::Key.new(
175
+ index_key = key_to_backend_key(Zermelo::Records::Key.new(
180
176
  :klass => associated_class,
181
177
  :name => "by_#{att}",
182
178
  :type => :hash,
@@ -197,7 +193,7 @@ module Zermelo
197
193
  end
198
194
  end
199
195
  when 'Zermelo::Associations::Index'
200
- key_root = key_to_redis_key(Zermelo::Records::Key.new(
196
+ key_root = key_to_backend_key(Zermelo::Records::Key.new(
201
197
  :klass => associated_class,
202
198
  :name => "by_#{att}:string",
203
199
  :type => :set,
@@ -242,14 +238,14 @@ module Zermelo
242
238
  idx_key = associated_class.send(:temp_key, type)
243
239
  temp_keys << idx_key
244
240
 
245
- val = Zermelo.redis.hget(key_to_redis_key(index.key),
241
+ val = Zermelo.redis.hget(key_to_backend_key(index.key),
246
242
  index_keys(attr_type, value).join(':'))
247
243
 
248
244
  case type
249
245
  when :set
250
- Zermelo.redis.sadd(key_to_redis_key(idx_key), val)
246
+ Zermelo.redis.sadd(key_to_backend_key(idx_key), val)
251
247
  when :sorted_set
252
- Zermelo.redis.zadd(key_to_redis_key(idx_key), [1, val])
248
+ Zermelo.redis.zadd(key_to_backend_key(idx_key), [1, val])
253
249
  end
254
250
  idx_key
255
251
  when Zermelo::Associations::Index
@@ -259,7 +255,7 @@ module Zermelo
259
255
  end
260
256
 
261
257
  def range_lookup(key, range, type, attr_type, associated_class, temp_keys)
262
- r_key = key_to_redis_key(key)
258
+ r_key = key_to_backend_key(key)
263
259
  opts = case type
264
260
  when :set
265
261
  {}
@@ -281,7 +277,7 @@ module Zermelo
281
277
  ret_key = associated_class.send(:temp_key, key.type)
282
278
  temp_keys << ret_key
283
279
  unless result.empty?
284
- r_key = key_to_redis_key(ret_key)
280
+ r_key = key_to_backend_key(ret_key)
285
281
  case type
286
282
  when :set
287
283
  Zermelo.redis.sadd(r_key, result)
@@ -318,7 +314,7 @@ module Zermelo
318
314
  # TODO check that collection types handle nil value for whole thing
319
315
  if Zermelo::COLLECTION_TYPES.has_key?(key.type)
320
316
 
321
- complex_attr_key = key_to_redis_key(key)
317
+ complex_attr_key = key_to_backend_key(key)
322
318
 
323
319
  case op
324
320
  when :add, :set
@@ -351,14 +347,14 @@ module Zermelo
351
347
  when :move
352
348
  case key.type
353
349
  when :set
354
- Zermelo.redis.smove(complex_attr_key, key_to_redis_key(key_to), value)
350
+ Zermelo.redis.smove(complex_attr_key, key_to_backend_key(key_to), value)
355
351
  when :list
356
352
  # TODO via sort 'nosort', or the workaround required prior to
357
353
  # https://github.com/antirez/redis/issues/2079
358
354
  raise "Not yet implemented"
359
355
  when :hash
360
356
  Zermelo.redis.hdel(complex_attr_key, *value.keys)
361
- Zermelo.redis.hset(key_to_redis_key(key_to), *value_to.to_a.flatten)
357
+ Zermelo.redis.hset(key_to_backend_key(key_to), *value_to.to_a.flatten)
362
358
  when :sorted_set
363
359
  Zermelo.redis.zadd(complex_attr_key, *value_to)
364
360
  end
@@ -380,7 +376,7 @@ module Zermelo
380
376
  elsif :purge.eql?(op)
381
377
  purges << ["#{key.klass.send(:class_key)}:#{key.id}:attrs"]
382
378
  else
383
- simple_attr_key = key_to_redis_key(key)
379
+ simple_attr_key = key_to_backend_key(key)
384
380
  simple_attrs[simple_attr_key] ||= {}
385
381
 
386
382
  case op
@@ -8,6 +8,10 @@ module Zermelo
8
8
 
9
9
  include Zermelo::Backend
10
10
 
11
+ def key_to_backend_key(key)
12
+ raise "Not supported"
13
+ end
14
+
11
15
  def filter(ids_key, associated_class, callback_target_class = nil,
12
16
  callback_target_id = nil, callbacks = nil, sort_order = nil)
13
17
 
@@ -89,7 +89,7 @@ module Zermelo
89
89
  end
90
90
 
91
91
  sc = Zermelo::Filters::Redis::SHORTCUTS[@initial_key.type][shortcut]
92
- r_key = backend.key_to_redis_key(@initial_key)
92
+ r_key = backend.key_to_backend_key(@initial_key)
93
93
  shortcut_params = if @initial_key.type == :sorted_set
94
94
  [r_key, @sort_order] + args
95
95
  else
@@ -21,7 +21,7 @@ module Zermelo
21
21
  shortcut = opts[:shortcut]
22
22
 
23
23
  dest_set = associated_class.send(:temp_key, source.type)
24
- r_dest_set = backend.key_to_redis_key(dest_set)
24
+ r_dest_set = backend.key_to_backend_key(dest_set)
25
25
  temp_keys << dest_set
26
26
 
27
27
  return dest_set if shortcut.nil?
@@ -33,13 +33,13 @@ module Zermelo
33
33
  # TODO need a guaranteed non-existing key for non-sorting 'sort'
34
34
 
35
35
  # TODO check if source is in temp_keys, use a generated temp_key instead if not
36
- r_source = backend.key_to_redis_key(source)
36
+ r_source = backend.key_to_backend_key(source)
37
37
 
38
38
  result, r_result = case source.type
39
39
  when :sorted_set
40
40
  limited = associated_class.send(:temp_key, :sorted_set)
41
41
  temp_keys << limited
42
- r_limited = backend.key_to_redis_key(limited)
42
+ r_limited = backend.key_to_backend_key(limited)
43
43
 
44
44
  lim = Zermelo.redis.send(
45
45
  :desc.eql?(opts[:sort_order]) ? :zrevrange : :zrange,
@@ -68,7 +68,7 @@ module Zermelo
68
68
  else
69
69
  limited = associated_class.send(:temp_key, :list)
70
70
  temp_keys << limited
71
- r_limited = backend.key_to_redis_key(limited)
71
+ r_limited = backend.key_to_backend_key(limited)
72
72
 
73
73
  Zermelo.redis.rpush(r_limited, data)
74
74
 
@@ -39,14 +39,14 @@ module Zermelo
39
39
  if [Set, Array].any? {|t| value.is_a?(t) }
40
40
  conditions_set = associated_class.send(:temp_key, source.type)
41
41
  temp_keys << conditions_set
42
- r_conditions_set = backend.key_to_redis_key(conditions_set)
42
+ r_conditions_set = backend.key_to_backend_key(conditions_set)
43
43
 
44
44
  backend.temp_key_wrap do |conditions_temp_keys|
45
45
  if use_sort_attr
46
46
  range_keys = value.collect {|v|
47
47
  rl = backend.range_lookup(associated_class.ids_key, v,
48
48
  source_type, attr_types[att], associated_class, conditions_temp_keys)
49
- backend.key_to_redis_key(rl)
49
+ backend.key_to_backend_key(rl)
50
50
  }
51
51
 
52
52
  case source.type
@@ -69,7 +69,7 @@ module Zermelo
69
69
  when Zermelo::Associations::Multiple
70
70
  co.instance_variable_get('@record_ids_key')
71
71
  end
72
- backend.key_to_redis_key(k)
72
+ backend.key_to_backend_key(k)
73
73
  end
74
74
 
75
75
  case source.type
@@ -100,7 +100,7 @@ module Zermelo
100
100
  index_keys = value.collect {|v|
101
101
  il = backend.index_lookup(att, associated_class, source.type,
102
102
  idx_class, v, attr_types[att], conditions_temp_keys)
103
- backend.key_to_redis_key(il)
103
+ backend.key_to_backend_key(il)
104
104
  }
105
105
 
106
106
  case source.type
@@ -126,7 +126,7 @@ module Zermelo
126
126
  else
127
127
  ts = associated_class.send(:temp_key, source.type)
128
128
  temp_keys << ts
129
- r_ts = backend.key_to_redis_key(ts)
129
+ r_ts = backend.key_to_backend_key(ts)
130
130
  case source.type
131
131
  when :set
132
132
  s_id = value.is_a?(Zermelo::Associations::Singular) ? value.id : value
@@ -144,8 +144,8 @@ module Zermelo
144
144
  end
145
145
  end
146
146
 
147
- r_source_key = backend.key_to_redis_key(source)
148
- r_source_keys = source_keys.collect {|sk| backend.key_to_redis_key(sk) }
147
+ r_source_key = backend.key_to_backend_key(source)
148
+ r_source_keys = source_keys.collect {|sk| backend.key_to_backend_key(sk) }
149
149
 
150
150
  op = @options[:op]
151
151
  shortcut = opts[:shortcut]
@@ -156,7 +156,7 @@ module Zermelo
156
156
  backend.temp_key_wrap do |shortcut_temp_keys|
157
157
  dest_set = associated_class.send(:temp_key, :set)
158
158
  shortcut_temp_keys << dest_set
159
- r_dest_set = backend.key_to_redis_key(dest_set)
159
+ r_dest_set = backend.key_to_backend_key(dest_set)
160
160
 
161
161
  Zermelo.redis.sinterstore(r_dest_set, *r_source_keys)
162
162
  Set.new(Zermelo.redis.sunion(r_source_key, r_dest_set))
@@ -167,7 +167,7 @@ module Zermelo
167
167
  backend.temp_key_wrap do |shortcut_temp_keys|
168
168
  dest_set = associated_class.send(:temp_key, :set)
169
169
  shortcut_temp_keys << dest_set
170
- r_dest_set = backend.key_to_redis_key(dest_set)
170
+ r_dest_set = backend.key_to_backend_key(dest_set)
171
171
 
172
172
  Zermelo.redis.sinterstore(r_dest_set, *r_source_keys)
173
173
  Set.new(Zermelo.redis.sdiff(r_source_key, r_dest_set))
@@ -175,12 +175,12 @@ module Zermelo
175
175
  end
176
176
  else
177
177
  dest_set = associated_class.send(:temp_key, source.type)
178
- r_dest_set = backend.key_to_redis_key(dest_set)
178
+ r_dest_set = backend.key_to_backend_key(dest_set)
179
179
  temp_keys << dest_set
180
180
 
181
181
  case op
182
182
  when :union
183
- r_initial_key = backend.key_to_redis_key(initial_key)
183
+ r_initial_key = backend.key_to_backend_key(initial_key)
184
184
 
185
185
  if source.type == :sorted_set
186
186
  Zermelo.redis.zinterstore(r_dest_set,
@@ -22,7 +22,7 @@ module Zermelo
22
22
 
23
23
  dest_list = associated_class.send(:temp_key, :list)
24
24
  temp_keys << dest_list
25
- r_dest_list = backend.key_to_redis_key(dest_list)
25
+ r_dest_list = backend.key_to_backend_key(dest_list)
26
26
 
27
27
  # TODO raise error in step construction if keys not
28
28
  # passed as expected below
@@ -40,7 +40,7 @@ module Zermelo
40
40
  # TODO check if complex attribute types or associations
41
41
  # can be used for sorting
42
42
 
43
- r_source = backend.key_to_redis_key(source)
43
+ r_source = backend.key_to_backend_key(source)
44
44
 
45
45
  # this set will be overwritten by the result list
46
46
  case source.type
@@ -64,6 +64,16 @@ module Zermelo
64
64
  @backend
65
65
  end
66
66
 
67
+ def key_dump
68
+ klass_keys = [backend.key_to_backend_key(ids_key), ids_key]
69
+ self.send(:with_index_data) do |d|
70
+ d.keys.each do |k|
71
+ klass_keys += self.send("#{k}_index".to_sym).key_dump
72
+ end
73
+ end
74
+ Hash[ *klass_keys ]
75
+ end
76
+
67
77
  protected
68
78
 
69
79
  def set_backend(backend_type)
@@ -95,7 +95,7 @@ module Zermelo
95
95
  run_callbacks( (creating ? :create : :update) ) do
96
96
 
97
97
  idx_attrs = self.class.send(:with_index_data) do |d|
98
- idx_attrs = d.each_with_object({}) do |(name, data), memo|
98
+ d.each_with_object({}) do |(name, data), memo|
99
99
  memo[name.to_s] = data.index_klass
100
100
  end
101
101
  end
@@ -164,7 +164,7 @@ module Zermelo
164
164
  end
165
165
 
166
166
  def destroy
167
- raise "Record was not persisted" if !persisted?
167
+ raise "Record was not persisted" unless persisted?
168
168
 
169
169
  run_callbacks :destroy do
170
170
 
@@ -197,6 +197,21 @@ module Zermelo
197
197
  end
198
198
  end
199
199
 
200
+ def key_dump
201
+ inst_keys = []
202
+
203
+ attr_key = attribute_keys.values.first
204
+ unless attr_key.nil?
205
+ inst_keys += [backend.key_to_backend_key(attr_key), attr_key]
206
+ end
207
+
208
+ self.class.send(:with_associations, self) do |assoc|
209
+ inst_keys += assoc.key_dump
210
+ end
211
+
212
+ Hash[*inst_keys]
213
+ end
214
+
200
215
  private
201
216
 
202
217
  def backend
@@ -1,3 +1,3 @@
1
1
  module Zermelo
2
- VERSION = '1.4.1'
2
+ VERSION = '1.4.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zermelo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ali Graham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-24 00:00:00.000000000 Z
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel