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 CHANGED
@@ -1 +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
@@ -1,6 +1,8 @@
1
1
  module PackRat
2
2
  module Extensions
3
3
  module ActiveRecord
4
+
5
+ # When AR::Base is inherited, incude PackRat into inheriting class
4
6
  def inherited(child_class)
5
7
  child_class.send(:include, PackRat::CacheHelper)
6
8
  super
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "pack_rat"
8
- s.version = "1.1.1"
8
+ s.version = "1.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brian Goff"]
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.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: -2786484823164904458
132
+ hash: -617294814959193562
133
133
  none: false
134
134
  required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  requirements: