redis-column 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
File without changes
@@ -1,3 +1,3 @@
1
1
  module RedisColumn
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/redis-column.rb CHANGED
@@ -30,8 +30,10 @@ module RedisColumn
30
30
  delegate :redis_columns, :to => "self.class"
31
31
  # Allow the instance access to RedisColumn.redis_instance
32
32
  delegate :redis_instance, :to => "RedisColumn"
33
- # Save the columns after
33
+ # Save the columns after_save
34
34
  after_save :save_redis_columns!
35
+ # Delete the columns after_destroy
36
+ after_destroy :delete_redis_columns!
35
37
  # Boosh!
36
38
  alias_method_chain :attributes, :redis_columns
37
39
  end
@@ -68,6 +70,11 @@ module RedisColumn
68
70
  redis_instance.set(redis_key(column_name), val.to_yaml) and return val
69
71
  end
70
72
 
73
+ # Delete value from Redis
74
+ def delete_redis_attribute column_name
75
+ redis_instance.del(redis_key(column_name))
76
+ end
77
+
71
78
  # Returns both the AR attributes and the Redis attributes in one hash
72
79
  def attributes_with_redis_columns
73
80
  _attributes = attributes_without_redis_columns.with_indifferent_access
@@ -83,6 +90,13 @@ module RedisColumn
83
90
  end
84
91
  end
85
92
 
93
+ # Delete all values in Redis
94
+ def delete_redis_columns!
95
+ redis_columns.each do |column_name|
96
+ delete_redis_attribute column_name
97
+ end
98
+ end
99
+
86
100
  end
87
101
  end
88
102
  end
@@ -53,16 +53,29 @@ describe DescriptionInRedisModel do
53
53
  end
54
54
 
55
55
  context "when saved" do
56
+ before do
57
+ @instance = DescriptionInRedisModel.create!(description: "A looong description")
58
+ end
59
+
56
60
  it "should retrive the description from redis, with the key '<model_name>:<id>:<column_name>'" do
57
- instance = DescriptionInRedisModel.create!(description: "A looong description")
58
- instance = DescriptionInRedisModel.find(instance.id)
59
- instance.description.should == "A looong description"
61
+ @instance = DescriptionInRedisModel.find(@instance.id)
62
+ @instance.description.should == "A looong description"
60
63
  end
61
64
 
62
65
  it "should return the redis_columns within :attributes" do
63
- instance = DescriptionInRedisModel.create!(string: "A string", description: "A looong description")
64
- instance.attributes.should have_key('string')
65
- instance.attributes.should have_key('description')
66
+ @instance.attributes.should have_key('string')
67
+ @instance.attributes.should have_key('description')
68
+ end
69
+
70
+ context "And destroying" do
71
+ before do
72
+ @instance.destroy
73
+ end
74
+
75
+ it "should also delete the description from redis" do
76
+ RedisColumn.redis_instance.get("description_in_redis_model:#{@instance.id}:description").should be_blank
77
+ end
78
+
66
79
  end
67
80
  end
68
81
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-column
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
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: 2011-12-02 00:00:00.000000000 Z
12
+ date: 2011-12-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &2152025520 !ruby/object:Gem::Requirement
16
+ requirement: &2152133180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152025520
24
+ version_requirements: *2152133180
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redis
27
- requirement: &2152025060 !ruby/object:Gem::Requirement
27
+ requirement: &2152132480 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2152025060
35
+ version_requirements: *2152132480
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &2152024300 !ruby/object:Gem::Requirement
38
+ requirement: &2152131800 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2152024300
46
+ version_requirements: *2152131800
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: autotest
49
- requirement: &2152023600 !ruby/object:Gem::Requirement
49
+ requirement: &2152153200 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2152023600
57
+ version_requirements: *2152153200
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sqlite3
60
- requirement: &2152022840 !ruby/object:Gem::Requirement
60
+ requirement: &2152151300 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2152022840
68
+ version_requirements: *2152151300
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: fakeredis
71
- requirement: &2152022260 !ruby/object:Gem::Requirement
71
+ requirement: &2152150160 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2152022260
79
+ version_requirements: *2152150160
80
80
  description: The RedisColumn gem allows for the seamless integration of Redis within
81
81
  your ActiveRecord model in order to store heavy objects away from tables with a
82
82
  lot of rows.
@@ -89,6 +89,7 @@ files:
89
89
  - .gitignore
90
90
  - .rspec
91
91
  - .rvmrc
92
+ - CHANGELOG.md
92
93
  - Gemfile
93
94
  - README.md
94
95
  - Rakefile