cache_column 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -1,5 +1,4 @@
1
1
  MIT-LICENSE
2
- Manifest
3
2
  README.rdoc
4
3
  Rakefile
5
4
  generators/cache_column/cache_column_generator.rb
@@ -11,3 +10,4 @@ lib/tasks/cache_column.rake
11
10
  test/cache_column_test.rb
12
11
  test/test_helper.rb
13
12
  uninstall.rb
13
+ Manifest
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('cache_column', '0.1.2') do |p|
5
+ Echoe.new('cache_column', '0.1.3') do |p|
6
6
  p.description = "Utilize the database to cache complex operations."
7
7
  p.url = "http://github.com/arjes/Cache-Column"
8
8
  p.author = "Brian Malinconico"
data/cache_column.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{cache_column}
5
- s.version = "0.1.2"
5
+ s.version = "0.1.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Brian Malinconico"]
9
- s.date = %q{2010-08-21}
9
+ s.date = %q{2010-08-23}
10
10
  s.description = %q{Utilize the database to cache complex operations.}
11
11
  s.email = %q{arjesins@gmail.com}
12
12
  s.extra_rdoc_files = ["README.rdoc", "lib/cache_column.rb", "lib/tasks/cache_column.rake"]
13
- s.files = ["MIT-LICENSE", "Manifest", "README.rdoc", "Rakefile", "generators/cache_column/cache_column_generator.rb", "generators/cache_column/templates/cache_column_migration.rb.erb", "init.rb", "install.rb", "lib/cache_column.rb", "lib/tasks/cache_column.rake", "test/cache_column_test.rb", "test/test_helper.rb", "uninstall.rb", "cache_column.gemspec"]
13
+ s.files = ["MIT-LICENSE", "README.rdoc", "Rakefile", "generators/cache_column/cache_column_generator.rb", "generators/cache_column/templates/cache_column_migration.rb.erb", "init.rb", "install.rb", "lib/cache_column.rb", "lib/tasks/cache_column.rake", "test/cache_column_test.rb", "test/test_helper.rb", "uninstall.rb", "Manifest", "cache_column.gemspec"]
14
14
  s.homepage = %q{http://github.com/arjes/Cache-Column}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Cache_column", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
data/lib/cache_column.rb CHANGED
@@ -29,21 +29,33 @@ module CacheColumn
29
29
  return if cached_columns.nil?
30
30
 
31
31
  cached_columns.each do |key,params|
32
- next if params[:update_validation].present? and self.respond_to?(params[:update_validation]) and self.send("#{params[:update_validation]}") == false
33
- next if params[:on_save].blank?
32
+ update_cache(key,params)
33
+ end
34
34
 
35
- if params[:on_save] == :blank
36
- new_value = ""
37
- set = true
38
- elsif params[:on_save] == :recheck and params[:action].present? and self.respond_to?(params[:action].to_sym)
39
- new_value = self.send(params[:action].to_sym)
40
- set = true
41
- end
35
+ #self.cache_updated_at = Time.now if self.respond_to?(:cached_updated_at)
36
+ end
37
+
38
+ def update_cache(key, params=nil)
39
+ if params.nil?
40
+ cached_columns = self.class.instance_variable_get('@cached_columns')
41
+ params = cached_columns[key]
42
+ end
43
+
44
+ return if params.nil?
45
+
46
+ next if params[:update_validation].present? and self.respond_to?(params[:update_validation]) and self.send("#{params[:update_validation]}") == false
47
+ next if params[:on_save].blank?
42
48
 
43
- self["#{key}_cache".to_sym] = new_value if set == true
49
+ if params[:on_save] == :blank
50
+ new_value = ""
51
+ set = true
52
+ elsif params[:on_save] == :recheck and params[:action].present? and self.respond_to?(params[:action].to_sym)
53
+ new_value = self.send(params[:action].to_sym)
54
+ set = true
44
55
  end
45
56
 
46
- #self.cache_updated_at = Time.now if self.respond_to?(:cached_updated_at)
57
+ self["#{key}_cache".to_sym] = new_value if set == true
58
+
47
59
  end
48
60
 
49
61
 
@@ -62,7 +74,15 @@ module CacheColumn
62
74
  cached_columns = self.class.instance_variable_get('@cached_columns')
63
75
 
64
76
  if cached_columns.keys.include?(method) #then its a getter
65
- return self["#{method}_cache".to_sym]
77
+ cached_value = self["#{method}_cache".to_sym]
78
+
79
+ #If the cached_value is nil we should check to see if we can get a new value
80
+ if cached_value.nil?
81
+ update_cache(method)
82
+ cached_value = self["#{method}_cache".to_sym]
83
+ end
84
+
85
+ return cached_value
66
86
  elsif method.to_s[-1,1] == '=' and cached_columns.keys.include?(method.to_s.chop.to_sym) and cached_columns[method.to_s.chop.to_sym][:action].blank? #then its a setter
67
87
  return self["#{method.to_s.chop}_cache".to_sym] = arguments[0]
68
88
  else
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cache_column
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian Malinconico
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-21 00:00:00 -04:00
18
+ date: 2010-08-23 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -31,7 +31,6 @@ extra_rdoc_files:
31
31
  - lib/tasks/cache_column.rake
32
32
  files:
33
33
  - MIT-LICENSE
34
- - Manifest
35
34
  - README.rdoc
36
35
  - Rakefile
37
36
  - generators/cache_column/cache_column_generator.rb
@@ -43,6 +42,7 @@ files:
43
42
  - test/cache_column_test.rb
44
43
  - test/test_helper.rb
45
44
  - uninstall.rb
45
+ - Manifest
46
46
  - cache_column.gemspec
47
47
  has_rdoc: true
48
48
  homepage: http://github.com/arjes/Cache-Column