def_cache 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZTEyMGI3NjEzNjA5ZWEzOTZhYmI2OGY1MTY0ZjhhZDRlMGYwZGM3MQ==
5
- data.tar.gz: !binary |-
6
- ZDU2YjJiODFiOTI0MmMzNTVmZTQ5ZjVlYjI3ZGRhNmU0ZjRlZmFiYQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZjIxYTlmMDc1ZTk5ZDA2NTEwZjMzZDU4NmJhNDExNjk3MzYxMDk2ODYwZjU4
10
- MWI1YTZkYjNhZWViMjA4YzA4OWNiM2RmYzYxOTJlYzE1ZGVkZjA3YWViMzg3
11
- YTE4ZjZiYTVhNTNlNDY3Y2U2MjkzMDExZGI1YTdmZWRkYjUxN2M=
12
- data.tar.gz: !binary |-
13
- YjQ2YmU1ZDNlYzY4NGFkZmE2NjMyYWVhMjE1MDhlYTA5MTE0YTViNjZkNDJl
14
- NTlhY2U5ZDU1Zjk5ZmEwM2UyYWEzMzNiNDU2NzZhYTUzNWEzYWM4ZTY0MDgz
15
- Y2VhOTgwOWJmMDNmYWJjMDM4NmRhNjRjMzFmMGUzZDMzNmJhNzg=
2
+ SHA1:
3
+ metadata.gz: 8f562213e73efa88b61a7eb92cb144c6198f3975
4
+ data.tar.gz: ec7c67194b038d4f698bdcd287a236c2488187bc
5
+ SHA512:
6
+ metadata.gz: c153c3926c0c32bc423afb07a80c4054e95ba5f1d678b0ef61f114145b9f91d65b7564b01794b307c271fd644439db21d963df22225bae23250bcc7bc5897f24
7
+ data.tar.gz: 5ce5dd50a90990a38a44011b1175c403988e1900455e3a73ceb609da96357eb0b148548c7ae2b842a1cf7dbd64221dd8a7828d137b17dcf2104e3c88687aeea4
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_development_dependency "yard"
25
25
  spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "rspec-its"
26
27
  spec.add_development_dependency "pry"
27
28
  spec.add_development_dependency "bundler", "~> 1.3"
28
29
  spec.add_development_dependency "rake"
@@ -1,3 +1,5 @@
1
+ require 'set'
2
+
1
3
  module DefCache::ClassMethods
2
4
 
3
5
  protected
@@ -14,22 +16,23 @@ module DefCache::ClassMethods
14
16
 
15
17
  # Define the cache_method
16
18
  def define_cache_method(method, options={})
19
+ __cached_methods__ << method.to_sym
17
20
  stub_cache_method_original(method)
18
21
  define_cache_handler_method(method, options)
19
22
  define_cache_with_method(method)
20
- cached_methods_just_added << method
21
23
  alias_method_chain method, :cache
22
24
  end
23
25
 
24
26
  # Define cache with method
25
27
  def define_cache_with_method(method)
26
28
  target, punctuation = method.to_s.sub(/([?!=])$/, ''), $1
29
+ raise PunctuationError, 'methods ending in `=` cannot be cached.' if punctuation == '='
27
30
  class_eval <<-RUBY
28
31
  def #{target}_with_cache#{punctuation}(*args, &block)
29
32
  handler = cache_handler_for_#{method}
30
33
  handler.cache_store.fetch(handler.cache_key, handler.cache_options) do
31
34
  handler.add_reference(handler.cache_key)
32
- #{target}_without_cache#{punctuation} *args, &block
35
+ #{target}_without_cache#{punctuation}(*args, &block)
33
36
  end
34
37
  rescue MethodSource::SourceNotFoundError => e
35
38
  warn e
@@ -58,13 +61,14 @@ module DefCache::ClassMethods
58
61
 
59
62
  # Relink the original method if it is redefined
60
63
  def method_added(method)
61
- define_cache_method(method) if !cached_methods_just_added.delete(method) && method_defined?("#{method}_with_cache")
64
+ if __cached_methods__.include? method.to_sym
65
+ define_cache_method(method) unless caller.any? { |files| files.include? __FILE__ }
66
+ end
62
67
  super
63
68
  end
64
69
 
65
- # A collection for just added methods
66
- def cached_methods_just_added
67
- @cached_methods_added ||= []
70
+ def __cached_methods__
71
+ @__cached_methods__ ||= Set.new
68
72
  end
69
73
 
70
- end
74
+ end
@@ -1,3 +1,3 @@
1
1
  module DefCache
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -119,22 +119,4 @@ describe DefCache::ClassMethods do
119
119
  end
120
120
  end
121
121
 
122
- describe '.method_added' do
123
- context 'if the with cache method is defined' do
124
- before(:each) { klass.send(:define_method, :foo_with_cache) { 'value' } }
125
- it 'should call define_cache_method' do
126
- expect(klass).to receive(:define_cache_method).with(:foo)
127
- klass.send(:method_added, :foo)
128
- end
129
-
130
- context 'if the method has just been added' do
131
- it 'should call define_cache_method' do
132
- klass.send(:cached_methods_just_added) << :foo
133
- expect(klass).to_not receive(:define_cache_method).with(:foo)
134
- klass.send(:method_added, :foo)
135
- end
136
- end
137
- end
138
- end
139
-
140
- end
122
+ end
@@ -1,5 +1,8 @@
1
1
  require 'simplecov'
2
2
  require 'coveralls'
3
+ require 'rspec'
4
+ require 'rspec/its'
5
+ require 'pry'
3
6
 
4
7
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
8
  SimpleCov::Formatter::HTMLFormatter,
metadata CHANGED
@@ -1,181 +1,195 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: def_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Waldrip
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-12 00:00:00.000000000 Z
11
+ date: 2015-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: method_source
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: yard
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-its
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: pry
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - ! '>='
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
89
  version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ! '>='
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: bundler
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - ~>
101
+ - - "~>"
88
102
  - !ruby/object:Gem::Version
89
103
  version: '1.3'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - ~>
108
+ - - "~>"
95
109
  - !ruby/object:Gem::Version
96
110
  version: '1.3'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rake
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - ! '>='
115
+ - - ">="
102
116
  - !ruby/object:Gem::Version
103
117
  version: '0'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - ! '>='
122
+ - - ">="
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: guard
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
- - - ! '>='
129
+ - - ">="
116
130
  - !ruby/object:Gem::Version
117
131
  version: '0'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
- - - ! '>='
136
+ - - ">="
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: guard-rspec
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
- - - ! '>='
143
+ - - ">="
130
144
  - !ruby/object:Gem::Version
131
145
  version: '0'
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
- - - ! '>='
150
+ - - ">="
137
151
  - !ruby/object:Gem::Version
138
152
  version: '0'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: guard-bundler
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
- - - ! '>='
157
+ - - ">="
144
158
  - !ruby/object:Gem::Version
145
159
  version: '0'
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
- - - ! '>='
164
+ - - ">="
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: simplecov
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
- - - ! '>='
171
+ - - ">="
158
172
  - !ruby/object:Gem::Version
159
173
  version: '0'
160
174
  type: :development
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
- - - ! '>='
178
+ - - ">="
165
179
  - !ruby/object:Gem::Version
166
180
  version: '0'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: coveralls
169
183
  requirement: !ruby/object:Gem::Requirement
170
184
  requirements:
171
- - - ! '>='
185
+ - - ">="
172
186
  - !ruby/object:Gem::Version
173
187
  version: '0'
174
188
  type: :development
175
189
  prerelease: false
176
190
  version_requirements: !ruby/object:Gem::Requirement
177
191
  requirements:
178
- - - ! '>='
192
+ - - ">="
179
193
  - !ruby/object:Gem::Version
180
194
  version: '0'
181
195
  description: An agnostic ActiveSupport::Cache helper to enable easy caching of methods
@@ -186,9 +200,9 @@ executables: []
186
200
  extensions: []
187
201
  extra_rdoc_files: []
188
202
  files:
189
- - .gitignore
190
- - .rspec
191
- - .travis.yml
203
+ - ".gitignore"
204
+ - ".rspec"
205
+ - ".travis.yml"
192
206
  - Gemfile
193
207
  - Guardfile
194
208
  - LICENSE.txt
@@ -213,17 +227,17 @@ require_paths:
213
227
  - lib
214
228
  required_ruby_version: !ruby/object:Gem::Requirement
215
229
  requirements:
216
- - - ! '>='
230
+ - - ">="
217
231
  - !ruby/object:Gem::Version
218
232
  version: '0'
219
233
  required_rubygems_version: !ruby/object:Gem::Requirement
220
234
  requirements:
221
- - - ! '>='
235
+ - - ">="
222
236
  - !ruby/object:Gem::Version
223
237
  version: '0'
224
238
  requirements: []
225
239
  rubyforge_project:
226
- rubygems_version: 2.0.6
240
+ rubygems_version: 2.4.5
227
241
  signing_key:
228
242
  specification_version: 4
229
243
  summary: An agnostic ActiveSupport::Cache helper to enable easy caching of methods