pack_rat 1.1.1 → 1.1.2
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.
- data/VERSION +1 -1
- data/lib/pack_rat/cache_helper.rb +11 -4
- data/lib/pack_rat/cache_helper/cacher.rb +9 -4
- data/lib/pack_rat/extensions/active_record.rb +2 -0
- data/pack_rat.gemspec +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.2
|
@@ -4,22 +4,24 @@ module PackRat
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
+
# Include and Extend so cache method is available in all contexts
|
7
8
|
extend Cacher
|
8
9
|
include Cacher
|
10
|
+
self.file_location = file_location_guesser
|
11
|
+
self.updated_attribute_name = :updated_at
|
9
12
|
end
|
10
13
|
|
11
14
|
module ClassMethods
|
12
|
-
def extended(base)
|
13
|
-
base.send(:file_location=, file_location_guesser)
|
14
|
-
base.send(:updated_attribute_name=, :updated_at) unless base.updated_attribute_name
|
15
|
-
end
|
16
15
|
|
16
|
+
# Instance attribute name that stores the last time the object was updated, usually :updated_at
|
17
17
|
def updated_attribute_name
|
18
18
|
@updated_attribute_name
|
19
19
|
end
|
20
20
|
def updated_attribute_name=(name)
|
21
21
|
@updated_attribute_name = name
|
22
22
|
end
|
23
|
+
|
24
|
+
# File path of the class
|
23
25
|
def file_location
|
24
26
|
@file_location
|
25
27
|
end
|
@@ -27,6 +29,8 @@ module PackRat
|
|
27
29
|
@file_location = path
|
28
30
|
generate_file_digest
|
29
31
|
end
|
32
|
+
|
33
|
+
# Stores the MD5 Digest of the class
|
30
34
|
def file_digest
|
31
35
|
@file_digest
|
32
36
|
end
|
@@ -48,6 +52,9 @@ module PackRat
|
|
48
52
|
|
49
53
|
# Uses Rails conventions to determine location of the defined class
|
50
54
|
def file_location_guesser
|
55
|
+
# This needs to be refactored to take a prefix to replace the rails/app/models
|
56
|
+
# AR Extension would be then include a prefix that this picks up
|
57
|
+
# Haven't decided on a clean way to implement this
|
51
58
|
"#{Rails.root}/app/models/#{self.to_s.split('::').join('/').underscore.downcase}.rb" if defined? Rails
|
52
59
|
end
|
53
60
|
|
@@ -2,22 +2,27 @@ module PackRat
|
|
2
2
|
module CacheHelper
|
3
3
|
module Cacher
|
4
4
|
def cache(key='', options={}, &block)
|
5
|
-
unless options[:overwrite_key]
|
6
|
-
calling_method = caller[0][/`([^']*)'/, 1]
|
5
|
+
unless options[:overwrite_key] # if overwrite_key was set, we skip creating our own key
|
6
|
+
calling_method = caller[0][/`([^']*)'/, 1] # Hack to get the method that called cache
|
7
7
|
key << calling_method << '/'
|
8
8
|
key << self.cache_key << '/'
|
9
|
+
|
10
|
+
# Since this same method is used in both class and instance contexts, we need to check that here
|
9
11
|
if self.is_a? Class
|
10
12
|
key << self.file_digest
|
11
13
|
else
|
12
14
|
key << self.class.file_digest
|
13
15
|
end
|
14
16
|
end
|
15
|
-
puts key if options[:debug]
|
16
|
-
filtered_options = options.except(:debug, :overwrite_key)
|
17
17
|
|
18
|
+
puts key if options[:debug] # Output the generated cache key to the console if debug is set
|
19
|
+
filtered_options = options.except(:debug, :overwrite_key) # Remove PackRat related options so we can pass to Rails.cache
|
20
|
+
|
21
|
+
# Make the actual Rails.cache call
|
18
22
|
Rails.cache.fetch key, filtered_options do
|
19
23
|
block.call
|
20
24
|
end
|
25
|
+
|
21
26
|
end
|
22
27
|
end
|
23
28
|
end
|
data/pack_rat.gemspec
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: pack_rat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.1.
|
5
|
+
version: 1.1.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Brian Goff
|
@@ -129,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
129
|
version: '0'
|
130
130
|
segments:
|
131
131
|
- 0
|
132
|
-
hash: -
|
132
|
+
hash: -617294814959193562
|
133
133
|
none: false
|
134
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|