cachethod 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +32 -0
- data/lib/cachethod/active_record_base_ext.rb +43 -0
- data/lib/cachethod/version.rb +3 -0
- data/lib/cachethod.rb +1 -0
- data/lib/tasks/cachethod_tasks.rake +4 -0
- data/test/cachethod_test.rb +4 -0
- data/test/test_helper.rb +15 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NDhhYzg2NzMyZjJjMTYwMzc3NTVmMDIxZTU4ZjZhZGJkODBkZTRhYg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NmIzZWI1MDQ4MGUxYTNmN2MxYTE2NjQwN2VmMGM3MWZjYjMzNGVhYg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NGQyYjU5YWIzZGYyMzViZjQ3ZTIyNmM0OTY5NGQ4MjUzN2E1MzI0NWVjNDI4
|
10
|
+
YjQwYmNkMzY2ZDU5MjMxMmI5YjVlYmM5NTUyMzUzOGI5NzA5OWNiZGFhYjkx
|
11
|
+
Nzg3OWU1YmE4MTJlZGVmODE5Yzk4YzUyMjI1MDcxZTc3YTAxOTI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NTcwZmE0YTQ2OGEyZGViZWZhNzA4NTQ1NTk1Njk3MjI3MDFlN2NkYWVhZDNl
|
14
|
+
NjA1MDJhNWQzNWYwMGVmNTEwOTk1YjQ0N2Y3NDQ4OTc5YTk1ZDk0NTlhYjMx
|
15
|
+
MmU4ZWUwZmI5OTViMTNlMDYxNmZmOTI5NmY5NzM5ZGMwNzhiMWM=
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
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/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Cachethod'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
|
24
|
+
Rake::TestTask.new(:test) do |t|
|
25
|
+
t.libs << 'lib'
|
26
|
+
t.libs << 'test'
|
27
|
+
t.pattern = 'test/**/*_test.rb'
|
28
|
+
t.verbose = false
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
task default: :test
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class ActiveRecord::Base
|
2
|
+
class << self
|
3
|
+
alias_method :method_added_original, :method_added
|
4
|
+
|
5
|
+
def cache_method name, *args
|
6
|
+
@methods_to_cache ||= {}
|
7
|
+
|
8
|
+
if name.is_a?(String) || name.is_a?(Symbol)
|
9
|
+
@methods_to_cache[name.to_sym] = args
|
10
|
+
elsif method_name.is_a?(Array)
|
11
|
+
cache_methods(name, *args)
|
12
|
+
else
|
13
|
+
raise Exception.new('Invalid first argument for cachethod method!')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def cache_methods names, *args
|
18
|
+
@methods_to_cache ||= {}
|
19
|
+
|
20
|
+
names.each do |name|
|
21
|
+
@methods_to_cache[name.to_sym] = args
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
alias_method :cachethod, :cache_method
|
26
|
+
alias_method :cachethods, :cache_method
|
27
|
+
|
28
|
+
def method_added name
|
29
|
+
return if @methods_to_cache.nil? || @methods_to_cache[name].nil?
|
30
|
+
|
31
|
+
args = @methods_to_cache.delete(name)
|
32
|
+
|
33
|
+
define_method "#{name}_cached" do
|
34
|
+
Rails.cache.fetch("user#{id}.#{name}", *args) do
|
35
|
+
send("#{name}!")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
alias_method "#{name}!", name
|
40
|
+
alias_method name, "#{name}_cached"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/cachethod.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'cachethod/active_record_base_ext'
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
require "rails/test_help"
|
6
|
+
|
7
|
+
Rails.backtrace_cleaner.remove_silencers!
|
8
|
+
|
9
|
+
# Load support files
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
11
|
+
|
12
|
+
# Load fixtures from the engine
|
13
|
+
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
14
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cachethod
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rene Klacan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4'
|
41
|
+
description: Rails plugin for caching model methods
|
42
|
+
email:
|
43
|
+
- rene@klacan.sk
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- MIT-LICENSE
|
49
|
+
- Rakefile
|
50
|
+
- lib/cachethod.rb
|
51
|
+
- lib/cachethod/active_record_base_ext.rb
|
52
|
+
- lib/cachethod/version.rb
|
53
|
+
- lib/tasks/cachethod_tasks.rake
|
54
|
+
- test/cachethod_test.rb
|
55
|
+
- test/test_helper.rb
|
56
|
+
homepage: http://github.com/reneklacan
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.2.2
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Rails plugin for caching model methods
|
80
|
+
test_files:
|
81
|
+
- test/test_helper.rb
|
82
|
+
- test/cachethod_test.rb
|
83
|
+
has_rdoc:
|