covercache 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/Rakefile +5 -16
- data/covercache.gemspec +6 -4
- data/lib/covercache/version.rb +1 -1
- data/lib/covercache.rb +45 -17
- data/spec/covercache.sqlite3 +0 -0
- data/spec/libs/covercache_spec.rb +17 -5
- data/spec/spec_helper.rb +2 -1
- metadata +64 -45
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
MjBmOWZkNmNhYmFlN2U1ZmFhYmFhYTI3NmQ0ZGQ3OWZiZTI3NDQyNjVjOTA3
|
10
|
-
M2I4ZjZjOWVjMWFlMDU0MjRlMTcyZTQ3NTg2ZjNiNWUzNmM4YTRjYmNjMDRk
|
11
|
-
Y2Q4YThmYzQ4Zjk3MDlkYTNkOTAxYjdmNmIwZjY1ODBlZWE1YmQ=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YzI4ODI0OWZkZDI2ZTAzZTMyMWE1MDMxOGI4ZDZhZThlZGJjNTNkOTY1MjVi
|
14
|
-
Njg1ZDJjMTA1NTMxYWIxOTQ0ZmRhYzU4MmVmZjNmNGRmZWRhOWQ5YmNmNjhk
|
15
|
-
OGNhZGE0ZTE5MTYwMzRhNWNiZGEwODdlYmU0YWUwY2RkYWM3YzA=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 67fd5cda6532ead49dccc9024d97ba5c18f30c4c
|
4
|
+
data.tar.gz: 4e6cddd4883669b1b1049b8774bee0610b8674e2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1309aea0cf020fca3b156c1343c96aa157b3c9353432104bcce6bb18787bfa5e99be01b47b9764a038d7e342db70f7e21b66177d423d1ab1ed74eb6eab69c041
|
7
|
+
data.tar.gz: 5de15c9308b8b980dc5e2876531299bc252098d38793f0997f9beacba8dca54758ebec17e26f3280015b48d27b3f83ff2705ce68a297811c0e6cefa8d5b318f7
|
data/Rakefile
CHANGED
@@ -1,18 +1,7 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
# test.verbose = true
|
8
|
-
# end
|
9
|
-
#
|
10
|
-
# require 'rdoc/task'
|
11
|
-
# Rake::RDocTask.new do |rdoc|
|
12
|
-
# version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
13
|
-
#
|
14
|
-
# rdoc.rdoc_dir = 'rdoc'
|
15
|
-
# rdoc.title = "covercashe #{version}"
|
16
|
-
# rdoc.rdoc_files.include('README*')
|
17
|
-
# rdoc.rdoc_files.include('lib/**/*.rb')
|
18
|
-
# end
|
4
|
+
RSpec::Core::RakeTask.new
|
5
|
+
|
6
|
+
task :default => :spec
|
7
|
+
task :test => :spec
|
data/covercache.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
|
+
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'covercache/version'
|
@@ -18,13 +19,14 @@ Gem::Specification.new do |spec|
|
|
18
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
20
|
spec.require_paths = ["lib"]
|
20
21
|
|
22
|
+
spec.add_dependency "activesupport", '>= 3.2.0', '< 4'
|
23
|
+
spec.add_dependency "activerecord", '>= 3.2.0', '< 4'
|
24
|
+
|
21
25
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
-
spec.add_development_dependency "rails",
|
26
|
+
spec.add_development_dependency "rails", '>= 3.2.0', '< 4'
|
23
27
|
spec.add_development_dependency "rdoc"
|
24
28
|
spec.add_development_dependency "rspec"
|
25
29
|
spec.add_development_dependency "rake"
|
26
30
|
spec.add_development_dependency "sqlite3"
|
27
31
|
|
28
|
-
spec.add_dependency "activesupport", "~> 3.0"
|
29
|
-
spec.add_dependency "activerecord", "~> 3.0"
|
30
32
|
end
|
data/lib/covercache/version.rb
CHANGED
data/lib/covercache.rb
CHANGED
@@ -52,6 +52,29 @@ require 'active_record'
|
|
52
52
|
# Comments.cached_for_post_ids post_ids, cache_key: post_ids.hash
|
53
53
|
#
|
54
54
|
module Covercache
|
55
|
+
|
56
|
+
def self.logger
|
57
|
+
@logger ||= rails_logger || default_logger
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.rails_logger
|
61
|
+
(defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger) ||
|
62
|
+
(defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER.respond_to?(:debug) && RAILS_DEFAULT_LOGGER)
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.default_logger
|
66
|
+
require 'logger'
|
67
|
+
l = Logger.new(STDOUT)
|
68
|
+
l.level = Logger::DEBUG
|
69
|
+
l
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.logger=(logger)
|
73
|
+
@logger = logger
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
|
55
78
|
# General helper method (ex <tt>cache</tt> helper in PackRat)
|
56
79
|
module Base
|
57
80
|
# Arguments:
|
@@ -87,25 +110,25 @@ module Covercache
|
|
87
110
|
# if :no_auto_cache_keys was set, we skip creating our own key
|
88
111
|
keys.prepend get_auto_cache_key(klass.name, caller) unless cover_opts[:without_auto_key]
|
89
112
|
|
90
|
-
keys.flatten!
|
113
|
+
keys.flatten!.select!{|i| i.present? }
|
91
114
|
|
92
115
|
if !!cover_opts[:debug]
|
93
|
-
|
94
|
-
Rails.logger.info keys
|
116
|
+
Covercache.logger.debug keys.inspect
|
95
117
|
end
|
96
118
|
# puts caller.inspect if !!cover_opts[:debug],
|
97
119
|
|
98
120
|
Rails.cache.fetch keys, options do
|
99
121
|
klass.covercache_keys |= [ keys.join('/') ]
|
100
|
-
|
122
|
+
Covercache.logger.debug(klass.covercache_keys.inspect) if !!cover_opts[:debug]
|
101
123
|
block.call
|
102
124
|
end
|
103
125
|
end
|
104
126
|
|
105
127
|
def get_auto_cache_key(class_name, _caller)
|
106
128
|
caller_method = _caller.map {|c| c[/`([^']*)'/, 1] }.detect {|m| !m.start_with?('block') }
|
107
|
-
|
108
|
-
|
129
|
+
keys = [class_name, covercache_model_digest, caller_method].compact
|
130
|
+
keys << cache_key if self.respond_to?(:cache_key)
|
131
|
+
keys
|
109
132
|
end
|
110
133
|
|
111
134
|
def class_or_instance_class
|
@@ -117,6 +140,8 @@ module Covercache
|
|
117
140
|
end
|
118
141
|
end
|
119
142
|
|
143
|
+
|
144
|
+
|
120
145
|
# == Defining Helper
|
121
146
|
#
|
122
147
|
module DefiningHelper
|
@@ -145,7 +170,7 @@ module Covercache
|
|
145
170
|
|
146
171
|
class_eval <<-EOS, file, line - 2
|
147
172
|
def #{method}(*args, &block) # def cached_example(*args, &block)
|
148
|
-
options = Array(#{method}_data[:args]) + extract_cache_key(*args) # options = Array(cached_example_data[:args]) +
|
173
|
+
options = Array(#{method}_data[:args]) + extract_cache_key(*args) # options = Array(cached_example_data[:args]) + extract_cache_key(*args)
|
149
174
|
covercache *options, #{method}_data[:opts] do # covercache *options, cached_example_data[:opts] do
|
150
175
|
cache_block = #{method}_data[:block] # cache_block = cached_example_data[:block]
|
151
176
|
if cache_block.present? # if cache_block.present?
|
@@ -154,7 +179,7 @@ module Covercache
|
|
154
179
|
self.send :#{original_method}, *args, &block # self.send :example, *args, &block
|
155
180
|
end # end
|
156
181
|
end # end
|
157
|
-
end #
|
182
|
+
end # end
|
158
183
|
EOS
|
159
184
|
end
|
160
185
|
|
@@ -221,17 +246,20 @@ module Covercache
|
|
221
246
|
end
|
222
247
|
end
|
223
248
|
|
224
|
-
|
225
|
-
#
|
226
|
-
|
227
|
-
|
249
|
+
|
250
|
+
# == Injecting
|
251
|
+
#
|
252
|
+
module Inject
|
253
|
+
def covers_with_cache
|
254
|
+
caller_source = caller.first[/[^:]+/]
|
228
255
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
256
|
+
class_eval do
|
257
|
+
@covercache_caller_source = caller_source
|
258
|
+
include Covercache::ModelConcern
|
259
|
+
extend Covercache::DefiningHelper
|
260
|
+
end
|
233
261
|
end
|
234
262
|
end
|
235
263
|
end
|
236
264
|
|
237
|
-
ActiveRecord::Base.extend Covercache
|
265
|
+
ActiveRecord::Base.extend Covercache::Inject
|
data/spec/covercache.sqlite3
CHANGED
Binary file
|
@@ -5,39 +5,51 @@ describe "covercache" do
|
|
5
5
|
it 'should respond to covers_with_cache' do
|
6
6
|
Post.should respond_to(:covers_with_cache)
|
7
7
|
end
|
8
|
+
|
8
9
|
it 'should have covercache_model_source attribute' do
|
9
10
|
pp Post.covercache_model_source
|
10
11
|
Post.covercache_model_source.should be_an(String)
|
11
12
|
end
|
13
|
+
|
12
14
|
it 'should have covercache_model_digest attribute' do
|
13
15
|
pp Post.covercache_model_digest
|
14
16
|
Post.covercache_model_digest.should be_an(String)
|
15
17
|
end
|
16
|
-
|
18
|
+
|
19
|
+
it 'should respounds to instance method defined by define_cached' do
|
17
20
|
comment = Comment.last
|
18
21
|
comment.cached_post.should == comment.post
|
19
22
|
end
|
23
|
+
|
20
24
|
it "should respounds to class method defined by define_cached" do
|
21
|
-
comments = Comment.cached_for_post(1)
|
25
|
+
comments = Comment.cached_for_post(1, cache_key: 1)
|
26
|
+
comments2 = Comment.cached_for_post(2, cache_key: 2)
|
22
27
|
Post.find(1).comments.should == comments
|
28
|
+
Post.find(2).comments.should == comments2
|
23
29
|
end
|
30
|
+
|
24
31
|
it 'should return the same digest for class and instance' do
|
25
32
|
post1 = Post.find(1)
|
26
33
|
pp post1.covercache_model_digest
|
27
34
|
Post.covercache_model_digest.should == post1.covercache_model_digest
|
28
35
|
end
|
36
|
+
|
29
37
|
it 'should return the same values with or without cache' do
|
30
38
|
test = Post.find(1)
|
31
39
|
pp test.inspect
|
32
40
|
pp test.cached_comments.inspect
|
33
41
|
test.cached_comments.count.should == test.comments.count
|
34
42
|
end
|
35
|
-
|
43
|
+
|
44
|
+
it 'post should have non-empty class keys storage' do
|
36
45
|
pp Post.covercache_keys
|
37
46
|
Post.covercache_keys.should be_an(Array)
|
47
|
+
Post.covercache_keys.count.should > 0
|
38
48
|
end
|
39
|
-
|
49
|
+
|
50
|
+
it 'comments should non-empty have class keys storage' do
|
40
51
|
pp Comment.covercache_keys
|
41
|
-
Comment.covercache_keys.should be_an(Array)
|
52
|
+
Comment.covercache_keys.should be_an(Array)
|
53
|
+
Comment.covercache_keys.count.should > 0
|
42
54
|
end
|
43
55
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'covercache'
|
3
2
|
require 'bundler'
|
3
|
+
|
4
4
|
begin
|
5
5
|
Bundler.setup(:default, :development)
|
6
6
|
rescue Bundler::BundlerError => e
|
@@ -8,6 +8,7 @@ rescue Bundler::BundlerError => e
|
|
8
8
|
$stderr.puts "Run `bundle install` to install missing gems"
|
9
9
|
exit e.status_code
|
10
10
|
end
|
11
|
+
|
11
12
|
require 'rspec'
|
12
13
|
require 'rspec/autorun'
|
13
14
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: covercache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tõnis Simo
|
@@ -9,120 +9,138 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: activesupport
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - '>='
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
21
|
-
|
20
|
+
version: 3.2.0
|
21
|
+
- - <
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '4'
|
24
|
+
type: :runtime
|
22
25
|
prerelease: false
|
23
26
|
version_requirements: !ruby/object:Gem::Requirement
|
24
27
|
requirements:
|
25
|
-
- -
|
28
|
+
- - '>='
|
26
29
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
30
|
+
version: 3.2.0
|
31
|
+
- - <
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4'
|
28
34
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
35
|
+
name: activerecord
|
30
36
|
requirement: !ruby/object:Gem::Requirement
|
31
37
|
requirements:
|
32
|
-
- -
|
38
|
+
- - '>='
|
33
39
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
35
|
-
|
40
|
+
version: 3.2.0
|
41
|
+
- - <
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '4'
|
44
|
+
type: :runtime
|
36
45
|
prerelease: false
|
37
46
|
version_requirements: !ruby/object:Gem::Requirement
|
38
47
|
requirements:
|
39
|
-
- -
|
48
|
+
- - '>='
|
40
49
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
50
|
+
version: 3.2.0
|
51
|
+
- - <
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '4'
|
42
54
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
55
|
+
name: bundler
|
44
56
|
requirement: !ruby/object:Gem::Requirement
|
45
57
|
requirements:
|
46
|
-
- -
|
58
|
+
- - ~>
|
47
59
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
60
|
+
version: '1.3'
|
49
61
|
type: :development
|
50
62
|
prerelease: false
|
51
63
|
version_requirements: !ruby/object:Gem::Requirement
|
52
64
|
requirements:
|
53
|
-
- -
|
65
|
+
- - ~>
|
54
66
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
67
|
+
version: '1.3'
|
56
68
|
- !ruby/object:Gem::Dependency
|
57
|
-
name:
|
69
|
+
name: rails
|
58
70
|
requirement: !ruby/object:Gem::Requirement
|
59
71
|
requirements:
|
60
|
-
- -
|
72
|
+
- - '>='
|
61
73
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
74
|
+
version: 3.2.0
|
75
|
+
- - <
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '4'
|
63
78
|
type: :development
|
64
79
|
prerelease: false
|
65
80
|
version_requirements: !ruby/object:Gem::Requirement
|
66
81
|
requirements:
|
67
|
-
- -
|
82
|
+
- - '>='
|
68
83
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
84
|
+
version: 3.2.0
|
85
|
+
- - <
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '4'
|
70
88
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
89
|
+
name: rdoc
|
72
90
|
requirement: !ruby/object:Gem::Requirement
|
73
91
|
requirements:
|
74
|
-
- -
|
92
|
+
- - '>='
|
75
93
|
- !ruby/object:Gem::Version
|
76
94
|
version: '0'
|
77
95
|
type: :development
|
78
96
|
prerelease: false
|
79
97
|
version_requirements: !ruby/object:Gem::Requirement
|
80
98
|
requirements:
|
81
|
-
- -
|
99
|
+
- - '>='
|
82
100
|
- !ruby/object:Gem::Version
|
83
101
|
version: '0'
|
84
102
|
- !ruby/object:Gem::Dependency
|
85
|
-
name:
|
103
|
+
name: rspec
|
86
104
|
requirement: !ruby/object:Gem::Requirement
|
87
105
|
requirements:
|
88
|
-
- -
|
106
|
+
- - '>='
|
89
107
|
- !ruby/object:Gem::Version
|
90
108
|
version: '0'
|
91
109
|
type: :development
|
92
110
|
prerelease: false
|
93
111
|
version_requirements: !ruby/object:Gem::Requirement
|
94
112
|
requirements:
|
95
|
-
- -
|
113
|
+
- - '>='
|
96
114
|
- !ruby/object:Gem::Version
|
97
115
|
version: '0'
|
98
116
|
- !ruby/object:Gem::Dependency
|
99
|
-
name:
|
117
|
+
name: rake
|
100
118
|
requirement: !ruby/object:Gem::Requirement
|
101
119
|
requirements:
|
102
|
-
- -
|
120
|
+
- - '>='
|
103
121
|
- !ruby/object:Gem::Version
|
104
|
-
version: '
|
105
|
-
type: :
|
122
|
+
version: '0'
|
123
|
+
type: :development
|
106
124
|
prerelease: false
|
107
125
|
version_requirements: !ruby/object:Gem::Requirement
|
108
126
|
requirements:
|
109
|
-
- -
|
127
|
+
- - '>='
|
110
128
|
- !ruby/object:Gem::Version
|
111
|
-
version: '
|
129
|
+
version: '0'
|
112
130
|
- !ruby/object:Gem::Dependency
|
113
|
-
name:
|
131
|
+
name: sqlite3
|
114
132
|
requirement: !ruby/object:Gem::Requirement
|
115
133
|
requirements:
|
116
|
-
- -
|
134
|
+
- - '>='
|
117
135
|
- !ruby/object:Gem::Version
|
118
|
-
version: '
|
119
|
-
type: :
|
136
|
+
version: '0'
|
137
|
+
type: :development
|
120
138
|
prerelease: false
|
121
139
|
version_requirements: !ruby/object:Gem::Requirement
|
122
140
|
requirements:
|
123
|
-
- -
|
141
|
+
- - '>='
|
124
142
|
- !ruby/object:Gem::Version
|
125
|
-
version: '
|
143
|
+
version: '0'
|
126
144
|
description: Helper method to simplify Rails caching, based on PackRat
|
127
145
|
email:
|
128
146
|
- anton.estum@gmail.com
|
@@ -152,17 +170,17 @@ require_paths:
|
|
152
170
|
- lib
|
153
171
|
required_ruby_version: !ruby/object:Gem::Requirement
|
154
172
|
requirements:
|
155
|
-
- -
|
173
|
+
- - '>='
|
156
174
|
- !ruby/object:Gem::Version
|
157
175
|
version: '0'
|
158
176
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
177
|
requirements:
|
160
|
-
- -
|
178
|
+
- - '>='
|
161
179
|
- !ruby/object:Gem::Version
|
162
180
|
version: '0'
|
163
181
|
requirements: []
|
164
182
|
rubyforge_project:
|
165
|
-
rubygems_version: 2.0.
|
183
|
+
rubygems_version: 2.0.5
|
166
184
|
signing_key:
|
167
185
|
specification_version: 4
|
168
186
|
summary: Rails cache helper based on PackRat gem
|
@@ -170,3 +188,4 @@ test_files:
|
|
170
188
|
- spec/covercache.sqlite3
|
171
189
|
- spec/libs/covercache_spec.rb
|
172
190
|
- spec/spec_helper.rb
|
191
|
+
has_rdoc:
|