redis_assist 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6dafb2d6cc1025b12b5a8f44cecafc69203d1bd6
4
- data.tar.gz: e5916815d8c698293226878b5d524e0579901fd7
3
+ metadata.gz: e106eceead9af03beab72f68a1b50447fe5b7ef8
4
+ data.tar.gz: 1074d7edf5d0264c57b1d2b356066983f5226996
5
5
  SHA512:
6
- metadata.gz: 68d5d37e12d0bf269b32ad61f04ba0a793ce8189dbccff940992ecfe3a601e55df12ad57a050cedb39239972ffc659b60cd3ef2447a7c63a1d439017774c4bb4
7
- data.tar.gz: dff0e8116ba7ad407956c2a244cf1c369c9b0e889dbb5b4497026d43f0ebc1dfb2c8f7dd56cda3134dd7437ac0e635586836119dc3c2f0ed8735b7e6b9e69282
6
+ metadata.gz: ab3732eb75c8040010dbd40e2b318abea7faa835192a6fc474ae3c0c09f8c4299db014d002e6cc98742f13cc5e01fec0f1362449a935e93a19a1a17f6317308d
7
+ data.tar.gz: 0f31ad582470bf564cab920d61a9a01d2b00114197e276c87fe1eca2542000907e2b10d22d8bc91991e3c1d4a413cb25d9458db9575349949f63d7473e00f9d2
@@ -33,6 +33,13 @@ module RedisAssist
33
33
  redis.zcard(index_key_for(:id))
34
34
  end
35
35
 
36
+
37
+ def all
38
+ ids = redis.zrange(index_key_for(:id), 0, -1)
39
+ find(ids)
40
+ end
41
+
42
+
36
43
  def first(limit=1, offset=0)
37
44
  from = offset
38
45
  to = from + limit - 1
@@ -238,7 +245,7 @@ module RedisAssist
238
245
 
239
246
 
240
247
  def hash_to_redis(obj)
241
- obj.each_with_object([]) {|kv,args| args<<kv[0]<<kv[1] }
248
+ obj.each_with_object([]) {|kv,args| args << kv[0] << kv[1] }
242
249
  end
243
250
 
244
251
 
@@ -495,8 +502,12 @@ module RedisAssist
495
502
  def redis
496
503
  self.class.redis
497
504
  end
498
-
499
-
505
+
506
+
507
+ def key_for(attribute)
508
+ self.class.key_for(id, attribute)
509
+ end
510
+
500
511
 
501
512
  protected
502
513
 
@@ -519,11 +530,7 @@ module RedisAssist
519
530
  def generate_id
520
531
  redis.incr("#{self.class.key_prefix}:id_sequence")
521
532
  end
522
-
523
- def key_for(attribute)
524
- self.class.key_for(id, attribute)
525
- end
526
-
533
+
527
534
  def load_attributes(raw_attributes)
528
535
  return nil unless raw_attributes
529
536
  self.lists = raw_attributes[:lists]
@@ -0,0 +1,28 @@
1
+ module RedisAssist
2
+ module Utils
3
+ class << self
4
+
5
+ def rename_attribute!(options={})
6
+ raise "model option must be provided" unless klass = options[:model]
7
+ raise "from option must be provided" unless from = options[:from]
8
+ raise "to option must be provided" unless to = options[:to]
9
+
10
+ klass.find_in_batches do |batch|
11
+ batch.each do |record|
12
+ client = record.redis
13
+ attr_key = record.key_for(:attributes)
14
+ value = client.hget(attr_key, from)
15
+
16
+ if value
17
+ client.multi do |multi|
18
+ multi.hset(attr_key, to, value)
19
+ multi.hdel(attr_key, from)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module RedisAssist
2
- VERSION = '0.8.0' unless defined?(::RedisAssist::VERSION)
2
+ VERSION = '0.9.0' unless defined?(::RedisAssist::VERSION)
3
3
  end
data/lib/redis_assist.rb CHANGED
@@ -9,6 +9,7 @@ require 'redis_assist/callbacks'
9
9
  require 'redis_assist/validations'
10
10
  require 'redis_assist/associations'
11
11
  require 'redis_assist/base'
12
+ require 'redis_assist/utils'
12
13
 
13
14
  # == Setup & Configuration
14
15
  # RedisAssist depends on the redis-rb gem to communicate with redis.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_assist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Love
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-21 00:00:00.000000000 Z
11
+ date: 2013-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -111,6 +111,7 @@ files:
111
111
  - lib/redis_assist/transforms/integer_transform.rb
112
112
  - lib/redis_assist/transforms/json_transform.rb
113
113
  - lib/redis_assist/transforms/time_transform.rb
114
+ - lib/redis_assist/utils.rb
114
115
  - lib/redis_assist/validations.rb
115
116
  - lib/redis_assist/version.rb
116
117
  - lib/redis_assist.rb
@@ -133,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
134
  version: '0'
134
135
  requirements: []
135
136
  rubyforge_project: redis_assist
136
- rubygems_version: 2.0.6
137
+ rubygems_version: 2.1.11
137
138
  signing_key:
138
139
  specification_version: 4
139
140
  summary: Persistant object oriented programming with redis