pack_rat 1.1.0 → 1.1.1

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.0
1
+ 1.1.1
@@ -13,9 +13,8 @@ module PackRat
13
13
  end
14
14
  end
15
15
  puts key if options[:debug]
16
- filtered_options = options.dup
17
- filtered_options.delete(:debug)
18
- filtered_options.delete(:overwrite_key)
16
+ filtered_options = options.except(:debug, :overwrite_key)
17
+
19
18
  Rails.cache.fetch key, filtered_options do
20
19
  block.call
21
20
  end
@@ -6,11 +6,14 @@ module PackRat
6
6
  included do
7
7
  extend Cacher
8
8
  include Cacher
9
- self.updated_attribute_name ||= :updated_at
10
- self.file_location = file_location_guesser
11
9
  end
12
10
 
13
11
  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
+
14
17
  def updated_attribute_name
15
18
  @updated_attribute_name
16
19
  end
@@ -31,6 +34,7 @@ module PackRat
31
34
  @file_digest = digest
32
35
  end
33
36
 
37
+ # Creates MD5 Digest of the set file_location attribute
34
38
  def generate_file_digest
35
39
  if self.file_location
36
40
  begin
@@ -42,9 +46,11 @@ module PackRat
42
46
  end
43
47
  end
44
48
 
49
+ # Uses Rails conventions to determine location of the defined class
45
50
  def file_location_guesser
46
51
  "#{Rails.root}/app/models/#{self.to_s.split('::').join('/').underscore.downcase}.rb" if defined? Rails
47
52
  end
53
+
48
54
  # Create cache_key for class, use most recently updated record
49
55
  unless self.respond_to? :cache_key
50
56
  define_method :cache_key do
@@ -0,0 +1,20 @@
1
+ module PackRat
2
+ module Extensions
3
+ module ActiveRecord
4
+ def inherited(child_class)
5
+ child_class.send(:include, PackRat::CacheHelper)
6
+ super
7
+ end
8
+ end
9
+ end
10
+ end
11
+
12
+ # Lazy load AR Extension into AR if ActiveSupport is there
13
+ if defined? ActiveSupport
14
+ ActiveSupport.on_load :active_record do
15
+ extend PackRat::Extensions::ActiveRecord
16
+ end
17
+ else
18
+ # Load immediately if no ActiveSupport loaded
19
+ ActiveRecord::Base.send(:extend, PackRat::Extensions::ActiveRecord) if defined? ActiveRecord::Base
20
+ end
@@ -0,0 +1 @@
1
+ require 'pack_rat/extensions/active_record'
data/lib/pack_rat.rb CHANGED
@@ -1,6 +1,3 @@
1
- require 'active_support'
2
- require 'pack_rat/active_record_extension'
1
+ require 'active_support/core_ext'
3
2
  require 'pack_rat/cache_helper'
4
- if defined? ActiveRecord::Base
5
- ActiveRecord::Base.send(:include, PackRat::ActiveRecordExtension)
6
- end
3
+ require 'pack_rat/extensions'
data/pack_rat.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "pack_rat"
8
- s.version = "1.1.0"
8
+ s.version = "1.1.1"
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"]
12
- s.date = "2013-01-12"
12
+ s.date = "2013-01-14"
13
13
  s.description = "Helper method to simplify Rails caching, do Russian-doll caching outside your views"
14
14
  s.email = "cpuguy83@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -25,9 +25,10 @@ Gem::Specification.new do |s|
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "lib/pack_rat.rb",
28
- "lib/pack_rat/active_record_extension.rb",
29
28
  "lib/pack_rat/cache_helper.rb",
30
29
  "lib/pack_rat/cache_helper/cacher.rb",
30
+ "lib/pack_rat/extensions.rb",
31
+ "lib/pack_rat/extensions/active_record.rb",
31
32
  "pack_rat.gemspec",
32
33
  "spec/models/test_class_spec.rb",
33
34
  "spec/spec_helper.rb"
data/spec/spec_helper.rb CHANGED
@@ -23,14 +23,15 @@ end
23
23
  class TestClass
24
24
  include PackRat::CacheHelper
25
25
  self.file_location = '/dev/null'
26
+ @test_string = 'testing'
26
27
  def some_method_with_cache
27
28
  cache do
28
- puts 'test'
29
+ @test_string
29
30
  end
30
31
  end
31
32
 
32
33
  def some_method_without_cache
33
- puts 'test'
34
+ @test_string
34
35
  end
35
36
 
36
37
  def cache_key
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: pack_rat
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.0
5
+ version: 1.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brian Goff
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-12 00:00:00.000000000 Z
12
+ date: 2013-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  type: :runtime
@@ -108,9 +108,10 @@ files:
108
108
  - Rakefile
109
109
  - VERSION
110
110
  - lib/pack_rat.rb
111
- - lib/pack_rat/active_record_extension.rb
112
111
  - lib/pack_rat/cache_helper.rb
113
112
  - lib/pack_rat/cache_helper/cacher.rb
113
+ - lib/pack_rat/extensions.rb
114
+ - lib/pack_rat/extensions/active_record.rb
114
115
  - pack_rat.gemspec
115
116
  - spec/models/test_class_spec.rb
116
117
  - spec/spec_helper.rb
@@ -128,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
129
  version: '0'
129
130
  segments:
130
131
  - 0
131
- hash: -463278824765411924
132
+ hash: -2786484823164904458
132
133
  none: false
133
134
  required_rubygems_version: !ruby/object:Gem::Requirement
134
135
  requirements:
@@ -1,12 +0,0 @@
1
- module PackRat
2
- module ActiveRecordExtension
3
- extend ActiveSupport::Concern
4
-
5
- module ClassMethods
6
- def inherited(child_class)
7
- child_class.send(:include, PackRat::CacheHelper)
8
- super
9
- end
10
- end
11
- end
12
- end