cache_column 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/Manifest +11 -0
- data/README.rdoc +15 -0
- data/Rakefile +15 -0
- data/cache_column.gemspec +31 -0
- data/init.rb +3 -0
- data/install.rb +1 -0
- data/lib/cache_column.rb +72 -0
- data/lib/tasks/cache_column.rake +4 -0
- data/test/cache_column_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- data/uninstall.rb +1 -0
- metadata +87 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
== Intro
|
2
|
+
Cache-column aims to make it easy to store the return values of functoins in the database for recall later.
|
3
|
+
|
4
|
+
== Examples
|
5
|
+
First add the following code to set-up the before_save filter and include the rest of the methods:
|
6
|
+
|
7
|
+
has_cached_columns
|
8
|
+
|
9
|
+
Next add a cache column
|
10
|
+
cache_column :column_name, options
|
11
|
+
|
12
|
+
=== Valid Options
|
13
|
+
|
14
|
+
|
15
|
+
Copyright (c) 2010 [name of plugin creator], released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('cache_column', '0.1.1') do |p|
|
6
|
+
p.description = "Utilize the database to cache complex operations."
|
7
|
+
p.url = "http://github.com/arjes/Cache-Column"
|
8
|
+
p.author = "Brian Malinconico"
|
9
|
+
p.email = "arjesins@gmail.com"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.development_dependencies = []
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
15
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{cache_column}
|
5
|
+
s.version = "0.1.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Brian Malinconico"]
|
9
|
+
s.date = %q{2010-08-13}
|
10
|
+
s.description = %q{Utilize the database to cache complex operations.}
|
11
|
+
s.email = %q{arjesins@gmail.com}
|
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", "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"]
|
14
|
+
s.homepage = %q{http://github.com/arjes/Cache-Column}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Cache_column", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{cache_column}
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
|
+
s.summary = %q{Utilize the database to cache complex operations.}
|
20
|
+
s.test_files = ["test/test_helper.rb", "test/cache_column_test.rb"]
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
+
s.specification_version = 3
|
25
|
+
|
26
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
27
|
+
else
|
28
|
+
end
|
29
|
+
else
|
30
|
+
end
|
31
|
+
end
|
data/init.rb
ADDED
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
data/lib/cache_column.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# CacheColumn
|
2
|
+
|
3
|
+
module CacheColumn
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def has_cached_columns
|
11
|
+
before_save :update_cache_columns
|
12
|
+
include CacheColumn::InstanceMethods
|
13
|
+
end
|
14
|
+
|
15
|
+
def cache_column(cache_name, options = {})
|
16
|
+
cached_columns = self.instance_variable_get('@cached_columns')
|
17
|
+
cached_columns = {} if cached_columns.nil?
|
18
|
+
cached_columns[cache_name] = options
|
19
|
+
self.instance_variable_set('@cached_columns', cached_columns)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
module InstanceMethods
|
25
|
+
def update_cache_columns
|
26
|
+
cached_columns = self.class.instance_variable_get('@cached_columns')
|
27
|
+
set = false
|
28
|
+
|
29
|
+
return if cached_columns.nil?
|
30
|
+
|
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
|
+
|
34
|
+
if params[:on_save] == :blank
|
35
|
+
new_value = ""
|
36
|
+
set = true
|
37
|
+
elsif params[:on_save] == :recheck and params[:action].present? and self.respond_to?(params[:action].to_sym)
|
38
|
+
new_value = self.send(params[:action].to_sym)
|
39
|
+
set = true
|
40
|
+
end
|
41
|
+
|
42
|
+
self.send("cache_#{key}=".to_sym, new_value) if set == true
|
43
|
+
end
|
44
|
+
|
45
|
+
self.cache_updated_at = Time.now if self.respond_to?(:cached_updated_at)
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
def respond_to?(method, include_priv=false)
|
50
|
+
cached_columns = self.class.instance_variable_get('@cached_columns')
|
51
|
+
return if cached_columns.nil?
|
52
|
+
cached_columns.each do |key, value|
|
53
|
+
return true if method.to_s == key.to_s
|
54
|
+
return true if method.to_s == "#{key.to_s}=" and value[:action].blank?
|
55
|
+
end
|
56
|
+
|
57
|
+
super
|
58
|
+
end
|
59
|
+
|
60
|
+
def method_missing(method, *arguments, &block)
|
61
|
+
if self.respond_to?("cache_#{method}".to_sym)
|
62
|
+
return self.send("cache_#{method}".to_sym, *arguments)
|
63
|
+
elsif self.respond_to?("cache_#{method.to_s.chop}")
|
64
|
+
return self.send("cache_#{method.to_s.chop}".to_sym)
|
65
|
+
end
|
66
|
+
super
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
|
data/test/test_helper.rb
ADDED
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cache_column
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Brian Malinconico
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-13 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Utilize the database to cache complex operations.
|
23
|
+
email: arjesins@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README.rdoc
|
30
|
+
- lib/cache_column.rb
|
31
|
+
- lib/tasks/cache_column.rake
|
32
|
+
files:
|
33
|
+
- MIT-LICENSE
|
34
|
+
- Manifest
|
35
|
+
- README.rdoc
|
36
|
+
- Rakefile
|
37
|
+
- init.rb
|
38
|
+
- install.rb
|
39
|
+
- lib/cache_column.rb
|
40
|
+
- lib/tasks/cache_column.rake
|
41
|
+
- test/cache_column_test.rb
|
42
|
+
- test/test_helper.rb
|
43
|
+
- uninstall.rb
|
44
|
+
- cache_column.gemspec
|
45
|
+
has_rdoc: true
|
46
|
+
homepage: http://github.com/arjes/Cache-Column
|
47
|
+
licenses: []
|
48
|
+
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options:
|
51
|
+
- --line-numbers
|
52
|
+
- --inline-source
|
53
|
+
- --title
|
54
|
+
- Cache_column
|
55
|
+
- --main
|
56
|
+
- README.rdoc
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 11
|
74
|
+
segments:
|
75
|
+
- 1
|
76
|
+
- 2
|
77
|
+
version: "1.2"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project: cache_column
|
81
|
+
rubygems_version: 1.3.7
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Utilize the database to cache complex operations.
|
85
|
+
test_files:
|
86
|
+
- test/test_helper.rb
|
87
|
+
- test/cache_column_test.rb
|