pack_rat 1.0.0 → 1.1.0

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/Gemfile CHANGED
@@ -13,7 +13,6 @@ group :development do
13
13
  end
14
14
  group :test do
15
15
  gem 'rspec'
16
- gem 'factory_girl'
17
16
  end
18
17
 
19
18
  gem 'rails'
data/Gemfile.lock CHANGED
@@ -32,8 +32,6 @@ GEM
32
32
  builder (3.0.4)
33
33
  diff-lcs (1.1.3)
34
34
  erubis (2.7.0)
35
- factory_girl (4.1.0)
36
- activesupport (>= 3.0.0)
37
35
  git (1.2.5)
38
36
  hike (1.2.1)
39
37
  i18n (0.6.1)
@@ -105,7 +103,6 @@ PLATFORMS
105
103
 
106
104
  DEPENDENCIES
107
105
  bundler
108
- factory_girl
109
106
  jeweler
110
107
  rails
111
108
  rdoc
data/Rakefile CHANGED
@@ -27,8 +27,8 @@ Jeweler::RubygemsDotOrgTasks.new
27
27
 
28
28
  require 'rake/testtask'
29
29
  Rake::TestTask.new(:test) do |test|
30
- test.libs << 'lib' << 'test'
31
- test.pattern = 'test/**/test_*.rb'
30
+ test.libs << 'lib' << 'spec'
31
+ test.pattern = 'spec/**/*_spec.rb'
32
32
  test.verbose = true
33
33
  end
34
34
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
@@ -13,7 +13,9 @@ module PackRat
13
13
  end
14
14
  end
15
15
  puts key if options[:debug]
16
- filtered_options = options.except(:overwrite_key, :debug)
16
+ filtered_options = options.dup
17
+ filtered_options.delete(:debug)
18
+ filtered_options.delete(:overwrite_key)
17
19
  Rails.cache.fetch key, filtered_options do
18
20
  block.call
19
21
  end
@@ -6,28 +6,38 @@ module PackRat
6
6
  included do
7
7
  extend Cacher
8
8
  include Cacher
9
- cattr_accessor :updated_attribute_name
10
9
  self.updated_attribute_name ||= :updated_at
11
- cattr_accessor :file_location
12
10
  self.file_location = file_location_guesser
13
11
  end
14
12
 
15
- module ClassMethods
16
- # Create cache_key for class, use most recently updated record
17
- unless self.respond_to? :cache_key
18
- define_method :cache_key do
19
- key = order("#{self.updated_attribute_name} DESC").first.cache_key if self.superclass.to_s == "ActiveRecord::Base"
20
- key << "/#{self.to_s}"
21
- end
13
+ module ClassMethods
14
+ def updated_attribute_name
15
+ @updated_attribute_name
16
+ end
17
+ def updated_attribute_name=(name)
18
+ @updated_attribute_name = name
19
+ end
20
+ def file_location
21
+ @file_location
22
+ end
23
+ def file_location=(path)
24
+ @file_location = path
25
+ generate_file_digest
22
26
  end
23
-
24
27
  def file_digest
28
+ @file_digest
29
+ end
30
+ def file_digest=(digest)
31
+ @file_digest = digest
32
+ end
33
+
34
+ def generate_file_digest
25
35
  if self.file_location
26
36
  begin
27
37
  file = File.read(self.file_location)
28
- Digest::MD5.hexdigest(file)
38
+ self.file_digest = Digest::MD5.hexdigest(file)
29
39
  rescue
30
- nil
40
+ self.file_digest = nil
31
41
  end
32
42
  end
33
43
  end
@@ -35,6 +45,13 @@ module PackRat
35
45
  def file_location_guesser
36
46
  "#{Rails.root}/app/models/#{self.to_s.split('::').join('/').underscore.downcase}.rb" if defined? Rails
37
47
  end
48
+ # Create cache_key for class, use most recently updated record
49
+ unless self.respond_to? :cache_key
50
+ define_method :cache_key do
51
+ key = order("#{self.updated_attribute_name} DESC").first.cache_key if self.superclass.to_s == "ActiveRecord::Base"
52
+ key << "/#{self.to_s}" if key
53
+ end
54
+ end
38
55
 
39
56
  end
40
57
  end
data/lib/pack_rat.rb CHANGED
@@ -3,7 +3,4 @@ require 'pack_rat/active_record_extension'
3
3
  require 'pack_rat/cache_helper'
4
4
  if defined? ActiveRecord::Base
5
5
  ActiveRecord::Base.send(:include, PackRat::ActiveRecordExtension)
6
- end
7
-
8
-
9
-
6
+ end
data/pack_rat.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "pack_rat"
8
- s.version = "1.0.0"
8
+ s.version = "1.1.0"
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"]
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  "lib/pack_rat/cache_helper.rb",
30
30
  "lib/pack_rat/cache_helper/cacher.rb",
31
31
  "pack_rat.gemspec",
32
+ "spec/models/test_class_spec.rb",
32
33
  "spec/spec_helper.rb"
33
34
  ]
34
35
  s.homepage = "http://github.com/cpuguy83/pack_rat"
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe TestClass do
4
+ it 'should respond to cache_key' do
5
+ TestClass.cache_key
6
+ end
7
+ it 'should return the same values with or without cache' do
8
+ test = TestClass.new
9
+ test.some_method_with_cache.should == test.some_method_without_cache
10
+ end
11
+ end
data/spec/spec_helper.rb CHANGED
@@ -9,16 +9,43 @@ rescue Bundler::BundlerError => e
9
9
  end
10
10
  require 'rspec'
11
11
  require 'rspec/autorun'
12
- require 'shoulda'
13
- require 'factory_girl'
14
12
 
15
13
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
16
14
  $LOAD_PATH.unshift(File.dirname(__FILE__))
17
15
  require 'pack_rat'
18
16
 
19
- Rspec.configure do |config|
17
+ RSpec.configure do |config|
20
18
  config.filter_run :focus => true
21
19
  config.run_all_when_everything_filtered = true
22
20
  config.treat_symbols_as_metadata_keys_with_true_values = true
23
- config.include FactoryGirl::Syntax::Methods
21
+ end
22
+
23
+ class TestClass
24
+ include PackRat::CacheHelper
25
+ self.file_location = '/dev/null'
26
+ def some_method_with_cache
27
+ cache do
28
+ puts 'test'
29
+ end
30
+ end
31
+
32
+ def some_method_without_cache
33
+ puts 'test'
34
+ end
35
+
36
+ def cache_key
37
+ 'stuff'
38
+ end
39
+ end
40
+
41
+ class Rails
42
+ def self.cache
43
+ Rails::Cache
44
+ end
45
+ end
46
+
47
+ class Rails::Cache
48
+ def self.fetch(*options, &block)
49
+ block.call
50
+ end
24
51
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: pack_rat
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.0
5
+ version: 1.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brian Goff
@@ -112,6 +112,7 @@ files:
112
112
  - lib/pack_rat/cache_helper.rb
113
113
  - lib/pack_rat/cache_helper/cacher.rb
114
114
  - pack_rat.gemspec
115
+ - spec/models/test_class_spec.rb
115
116
  - spec/spec_helper.rb
116
117
  homepage: http://github.com/cpuguy83/pack_rat
117
118
  licenses:
@@ -127,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
128
  version: '0'
128
129
  segments:
129
130
  - 0
130
- hash: -2074664687036877359
131
+ hash: -463278824765411924
131
132
  none: false
132
133
  required_rubygems_version: !ruby/object:Gem::Requirement
133
134
  requirements: