method_caching 0.0.1 → 1.0.0
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.
- checksums.yaml +15 -0
- data/Gemfile.lock +3 -0
- data/README.md +20 -3
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/method_caching.rb +14 -1
- data/method_caching.gemspec +61 -0
- data/spec/method_caching_spec.rb +2 -4
- metadata +7 -19
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OWJkNTFiYjI4OWVlNWMyOWU0NTdkOWRiNTUzOGNiYWM0MjllYzJhMw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NDFiZWYyNDljODM0YzA5YmI5YTU0YzVmNjY0NTlhNWRkZjdhY2JiMQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NmE5ZjI5ZTZmZjRkYTUwZTIwZTFkMWYxOTQ5YjkwOGZmNTEzZjFhZjY5M2I0
|
10
|
+
MmI5MTJjOGU2MzY5M2M3ZTUxM2M0OGJhOTZjZTZkYmVhYzc2ZjgwNjM2ODAy
|
11
|
+
Mzk3ZWQxNzNiYzI3MDQ0NjEyZDk3ZDkwNDZhYTdlZjI0ZDJjMTk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ODRiM2I5MmZjODczODg1NjE2NDQzY2RlM2Y0MDNmMTNiNzUwZDAwNGM1YTk0
|
14
|
+
ZDMzZjc4ZTRkMjhmZGQwN2U5NTlmYjg1YmNkYTFmOTNjOTgwYjA5ZjdlMjIy
|
15
|
+
YmJiZTZkZmMyNGE1MzA1Zjg4NmNkMTE2NDYxZDE0OTQyOTM3NjI=
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -16,6 +16,8 @@ or add to Gemfile
|
|
16
16
|
|
17
17
|
## Usage
|
18
18
|
|
19
|
+
### With ActiveRecord
|
20
|
+
|
19
21
|
```ruby
|
20
22
|
class User < ActiveRecord::Base
|
21
23
|
method_caching
|
@@ -23,12 +25,27 @@ class User < ActiveRecord::Base
|
|
23
25
|
def full_name
|
24
26
|
"#{first_name} #{last_name}"
|
25
27
|
end
|
26
|
-
cache_method :full_name
|
27
|
-
|
28
|
+
cache_method :full_name, clear_on: :save # Clear cache for method full_name whenever method 'save' is called
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
### Without ActiveRecord (Mongoid, etc)
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
class User
|
36
|
+
include MethodCaching::Generic
|
37
|
+
method_caching
|
38
|
+
|
39
|
+
def full_name
|
40
|
+
"#{first_name} #{last_name}"
|
41
|
+
end
|
42
|
+
cache_method :full_name, clear_on: :save # Clear cache for method full_name whenever method 'save' is called
|
28
43
|
end
|
29
44
|
```
|
30
45
|
|
31
|
-
|
46
|
+
### Custom Identifier
|
47
|
+
|
48
|
+
By default, method_caching will use the record's id as the default identifier to generate the cache key. You can change the default identifier by passing custom identifier
|
32
49
|
|
33
50
|
```ruby
|
34
51
|
class User < ActiveRecord::Base
|
data/Rakefile
CHANGED
@@ -19,7 +19,7 @@ Jeweler::Tasks.new do |gem|
|
|
19
19
|
gem.license = "MIT"
|
20
20
|
gem.summary = %Q{Simple Ruby library for caching instance method of a class}
|
21
21
|
gem.description = %Q{Simple Ruby library for caching instance method of a class. Using Rails.cache as default caching.}
|
22
|
-
gem.email = "
|
22
|
+
gem.email = "hhuy424@gmail.com"
|
23
23
|
gem.authors = ["HuyHa"]
|
24
24
|
# dependencies defined in Gemfile
|
25
25
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
1.0.0
|
data/lib/method_caching.rb
CHANGED
@@ -5,7 +5,7 @@ module MethodCaching
|
|
5
5
|
self.send(:include, InstanceMethods)
|
6
6
|
end
|
7
7
|
|
8
|
-
def cache_method(method)
|
8
|
+
def cache_method(method, options = {})
|
9
9
|
old = "_#{method}".to_sym
|
10
10
|
alias_method old, method
|
11
11
|
define_method method do |*args|
|
@@ -13,6 +13,11 @@ module MethodCaching
|
|
13
13
|
send(old, *args)
|
14
14
|
end
|
15
15
|
end
|
16
|
+
|
17
|
+
clear_methods = [options[:clear_on]].flatten.compact
|
18
|
+
clear_methods.each do |clear_method|
|
19
|
+
cache_method_clear_on(clear_method, method)
|
20
|
+
end
|
16
21
|
end
|
17
22
|
|
18
23
|
def cache_method_clear_on(clear_method, cache_method)
|
@@ -40,6 +45,14 @@ module MethodCaching
|
|
40
45
|
"#{self.class.to_s}_#{self.send(identifier_method)}_#{method.to_s}"
|
41
46
|
end
|
42
47
|
end
|
48
|
+
|
49
|
+
module Generic
|
50
|
+
include ::MethodCaching::InstanceMethods
|
51
|
+
|
52
|
+
def self.included(klass)
|
53
|
+
klass.send(:extend, ::MethodCaching::ClassMethods)
|
54
|
+
end
|
55
|
+
end
|
43
56
|
end
|
44
57
|
|
45
58
|
if defined?(ActiveRecord)
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: method_caching 1.0.0 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "method_caching"
|
9
|
+
s.version = "1.0.0"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["HuyHa"]
|
14
|
+
s.date = "2015-06-19"
|
15
|
+
s.description = "Simple Ruby library for caching instance method of a class. Using Rails.cache as default caching."
|
16
|
+
s.email = "hhuy424@gmail.com"
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.md"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".rspec",
|
24
|
+
"Gemfile",
|
25
|
+
"Gemfile.lock",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README.md",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"lib/method_caching.rb",
|
31
|
+
"method_caching.gemspec",
|
32
|
+
"spec/method_caching_spec.rb",
|
33
|
+
"spec/spec_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = "http://github.com/huyha85/method_caching"
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.rubygems_version = "2.4.6"
|
38
|
+
s.summary = "Simple Ruby library for caching instance method of a class"
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
s.specification_version = 4
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
45
|
+
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
46
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
47
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.7"])
|
48
|
+
else
|
49
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
50
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
51
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
52
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
|
53
|
+
end
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
56
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
57
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
58
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
data/spec/method_caching_spec.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
class TestClass
|
4
|
-
|
5
|
-
include MethodCaching::InstanceMethods
|
4
|
+
include MethodCaching::Generic
|
6
5
|
method_caching :identifier
|
7
6
|
|
8
7
|
def method_to_be_cleared; end
|
@@ -10,8 +9,7 @@ class TestClass
|
|
10
9
|
def method_to_be_cached
|
11
10
|
calculate(2)
|
12
11
|
end
|
13
|
-
cache_method :method_to_be_cached
|
14
|
-
cache_method_clear_on :method_to_be_cleared, :method_to_be_cached
|
12
|
+
cache_method :method_to_be_cached, clear_on: :method_to_be_cleared
|
15
13
|
|
16
14
|
def identifier
|
17
15
|
"id"
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: method_caching
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- HuyHa
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-06-19 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rdoc
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: bundler
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ! '>='
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ! '>='
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -62,7 +55,6 @@ dependencies:
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: jeweler
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
59
|
- - ~>
|
68
60
|
- !ruby/object:Gem::Version
|
@@ -70,14 +62,13 @@ dependencies:
|
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
66
|
- - ~>
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: 1.8.7
|
78
69
|
description: Simple Ruby library for caching instance method of a class. Using Rails.cache
|
79
70
|
as default caching.
|
80
|
-
email:
|
71
|
+
email: hhuy424@gmail.com
|
81
72
|
executables: []
|
82
73
|
extensions: []
|
83
74
|
extra_rdoc_files:
|
@@ -93,34 +84,31 @@ files:
|
|
93
84
|
- Rakefile
|
94
85
|
- VERSION
|
95
86
|
- lib/method_caching.rb
|
87
|
+
- method_caching.gemspec
|
96
88
|
- spec/method_caching_spec.rb
|
97
89
|
- spec/spec_helper.rb
|
98
90
|
homepage: http://github.com/huyha85/method_caching
|
99
91
|
licenses:
|
100
92
|
- MIT
|
93
|
+
metadata: {}
|
101
94
|
post_install_message:
|
102
95
|
rdoc_options: []
|
103
96
|
require_paths:
|
104
97
|
- lib
|
105
98
|
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
-
none: false
|
107
99
|
requirements:
|
108
100
|
- - ! '>='
|
109
101
|
- !ruby/object:Gem::Version
|
110
102
|
version: '0'
|
111
|
-
segments:
|
112
|
-
- 0
|
113
|
-
hash: 3994657104755449766
|
114
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
-
none: false
|
116
104
|
requirements:
|
117
105
|
- - ! '>='
|
118
106
|
- !ruby/object:Gem::Version
|
119
107
|
version: '0'
|
120
108
|
requirements: []
|
121
109
|
rubyforge_project:
|
122
|
-
rubygems_version:
|
110
|
+
rubygems_version: 2.4.6
|
123
111
|
signing_key:
|
124
|
-
specification_version:
|
112
|
+
specification_version: 4
|
125
113
|
summary: Simple Ruby library for caching instance method of a class
|
126
114
|
test_files: []
|