redis-column 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -0,0 +1,11 @@
1
+ ## RedisColumn 0.0.3 (7th Dec, 2011) ##
2
+
3
+ * Adding the redis_columns in an after_initialize callback for better compatibility
4
+
5
+ ## RedisColumn 0.0.2 (5th Dec, 2011) ##
6
+
7
+ * Added deleting of values in Redis after_destroy
8
+
9
+ ## RedisColumn 0.0.1 (2nd Dec, 2011) ##
10
+
11
+ * Initial Release
@@ -1,3 +1,3 @@
1
1
  module RedisColumn
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/redis-column.rb CHANGED
@@ -30,12 +30,12 @@ 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
+ # Assign redis_columns
34
+ after_initialize :assign_redis_columns
33
35
  # Save the columns after_save
34
36
  after_save :save_redis_columns!
35
37
  # Delete the columns after_destroy
36
38
  after_destroy :delete_redis_columns!
37
- # Boosh!
38
- alias_method_chain :attributes, :redis_columns
39
39
  end
40
40
 
41
41
  module ClassMethods
@@ -43,10 +43,8 @@ module RedisColumn
43
43
  # Setup a redis column
44
44
  def redis_column column_name
45
45
  self.redis_columns += [column_name]
46
- attr_writer column_name
47
- define_method column_name do # read the attribute or find from Redis and set to instance var
48
- send(:instance_variable_get, "@#{column_name}") || send("#{column_name}=", read_redis_attribute(column_name))
49
- end
46
+ define_method(column_name) { @attributes[column_name.to_s] }
47
+ define_method("#{column_name}=") {|val| @attributes[column_name.to_s] = val }
50
48
  end
51
49
  alias_method :redis_col, :redis_column
52
50
 
@@ -75,18 +73,17 @@ module RedisColumn
75
73
  redis_instance.del(redis_key(column_name))
76
74
  end
77
75
 
78
- # Returns both the AR attributes and the Redis attributes in one hash
79
- def attributes_with_redis_columns
80
- _attributes = attributes_without_redis_columns.with_indifferent_access
81
- redis_columns.inject(_attributes) do |res, column_name|
82
- res.merge(column_name => send(column_name))
76
+ # Assigns the values from Redis unless already specified
77
+ def assign_redis_columns
78
+ redis_columns.each do |column_name|
79
+ write_attribute column_name, read_redis_attribute(column_name) unless read_attribute(column_name.to_s).present?
83
80
  end
84
81
  end
85
82
 
86
83
  # Save all values back to Redis
87
84
  def save_redis_columns!
88
85
  redis_columns.each do |column_name|
89
- write_redis_attribute column_name, send(column_name)
86
+ write_redis_attribute column_name, read_attribute(column_name)
90
87
  end
91
88
  end
92
89
 
@@ -67,7 +67,19 @@ describe DescriptionInRedisModel do
67
67
  @instance.attributes.should have_key('description')
68
68
  end
69
69
 
70
- context "And destroying" do
70
+ context "and finding" do
71
+
72
+ before do
73
+ @instance = DescriptionInRedisModel.find(@instance.id)
74
+ end
75
+
76
+ it "should set the redis_columns after find" do
77
+ @instance.attributes['description'].should == "A looong description"
78
+ @instance.description.should == "A looong description"
79
+ end
80
+ end
81
+
82
+ context "and destroying" do
71
83
  before do
72
84
  @instance.destroy
73
85
  end
@@ -77,6 +89,22 @@ describe DescriptionInRedisModel do
77
89
  end
78
90
 
79
91
  end
92
+
93
+ context "and duping" do
94
+
95
+ before do
96
+ @new_instance = @instance.dup
97
+ @new_instance.save!
98
+ @new_instance = DescriptionInRedisModel.find(@new_instance.id)
99
+ end
100
+
101
+ it { @new_instance.should_not == @instance }
102
+
103
+ it "should set the redis_columns after find" do
104
+ @new_instance.attributes['description'].should == "A looong description"
105
+ @new_instance.description.should == "A looong description"
106
+ end
107
+ end
80
108
  end
81
109
 
82
110
  end
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.2
4
+ version: 0.0.3
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-05 00:00:00.000000000 Z
12
+ date: 2011-12-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &2152133180 !ruby/object:Gem::Requirement
16
+ requirement: &2152310300 !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: *2152133180
24
+ version_requirements: *2152310300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redis
27
- requirement: &2152132480 !ruby/object:Gem::Requirement
27
+ requirement: &2152309820 !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: *2152132480
35
+ version_requirements: *2152309820
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &2152131800 !ruby/object:Gem::Requirement
38
+ requirement: &2152309400 !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: *2152131800
46
+ version_requirements: *2152309400
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: autotest
49
- requirement: &2152153200 !ruby/object:Gem::Requirement
49
+ requirement: &2152308960 !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: *2152153200
57
+ version_requirements: *2152308960
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sqlite3
60
- requirement: &2152151300 !ruby/object:Gem::Requirement
60
+ requirement: &2152308540 !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: *2152151300
68
+ version_requirements: *2152308540
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: fakeredis
71
- requirement: &2152150160 !ruby/object:Gem::Requirement
71
+ requirement: &2152308120 !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: *2152150160
79
+ version_requirements: *2152308120
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.