model_cached 0.1.0 → 0.1.1

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.
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = model_cached plugin
2
2
 
3
- This Rails 3 plugin gives you the ability to transparently cache single active record objects using memcached.
3
+ This Rails 3 gem gives you the ability to transparently cache single active record objects using memcached.
4
4
 
5
5
  The purpose is to cache by fields that are being validated for unique values.
6
6
 
@@ -8,6 +8,7 @@ Cache gets refresh after save, and expire after destroy or after a logical delet
8
8
 
9
9
  It is less than 100 lines of code, so don't be shy to look at the source for full understanding.
10
10
 
11
+ NOTE: For rails 2.x use the unmaintained rails2 branch.
11
12
 
12
13
  == Usage
13
14
 
@@ -74,7 +75,9 @@ In your model:
74
75
 
75
76
  == Install
76
77
 
77
- ./script/plugin install git://github.com/arydjmal/model_cached.git
78
+ In your Gemfile:
79
+
80
+ gem 'model_cached'
78
81
 
79
82
 
80
83
 
data/lib/model_cached.rb CHANGED
@@ -16,7 +16,7 @@ module ModelCached
16
16
  if column_names.include?(:id)
17
17
  class_eval do
18
18
  def self.find(*args)
19
- if args.size == 1 && (id = args.first).is_a?(Integer)
19
+ if args.size == 1 and (id = args.first).is_a?(Integer)
20
20
  find_by_id(id) || raise(ActiveRecord::RecordNotFound, "Couldn't find #{name} with ID=#{id}")
21
21
  else
22
22
  super(*args)
@@ -64,11 +64,11 @@ module ModelCached
64
64
  end
65
65
 
66
66
  def refresh_mc_keys
67
- if mc_logical_delete && send(mc_logical_delete)
67
+ if mc_logical_delete and send(mc_logical_delete)
68
68
  expire_mc_keys
69
69
  else
70
70
  mc_columns.each do |column|
71
- Rails.cache.write(mc_key(column), self)
71
+ Rails.cache.write(mc_key(column), self) unless send(column).blank?
72
72
  if send("#{column}_changed?")
73
73
  Rails.cache.delete(mc_key(column, send("#{column}_was")))
74
74
  end
Binary file
data/model_cached.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'model_cached'
3
- s.version = '0.1.0'
3
+ s.version = '0.1.1'
4
4
  s.authors = ['Ary Djmal']
5
5
  s.email = ['arydjmal@gmail.com']
6
6
  s.summary = 'Rails gem that gives you the ability to transparently cache single active record objects using memcached.'
@@ -71,6 +71,12 @@ class ModelCachedTest < Test::Unit::TestCase
71
71
  @ary.destroy
72
72
  assert_equal nil, Rails.cache.read("users/id/#{@ary.id}")
73
73
  end
74
+
75
+ def test_refresh_should_not_happen_if_value_is_blank
76
+ @ary.update_attributes!(email: '')
77
+ assert_equal @ary, Rails.cache.read(@ary.mc_key(:id))
78
+ assert_equal nil, Rails.cache.read(@ary.mc_key(:email))
79
+ end
74
80
  end
75
81
 
76
82
  class ModelCachedWithScopeTest < Test::Unit::TestCase
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_cached
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-08-28 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70255150855040 !ruby/object:Gem::Requirement
16
+ requirement: &70242198005580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70255150855040
24
+ version_requirements: *70242198005580
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70255150852720 !ruby/object:Gem::Requirement
27
+ requirement: &70242198004980 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70255150852720
35
+ version_requirements: *70242198004980
36
36
  description:
37
37
  email:
38
38
  - arydjmal@gmail.com
@@ -42,6 +42,7 @@ extra_rdoc_files: []
42
42
  files:
43
43
  - ./lib/model_cached.rb
44
44
  - ./MIT-LICENSE
45
+ - ./model_cached-0.1.0.gem
45
46
  - ./model_cached.gemspec
46
47
  - ./Rakefile
47
48
  - ./README.rdoc