blanket_cachekey 0.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c43fd6f678e4f9481bf71a1b1770af8dd7251b1e
4
+ data.tar.gz: 5d89e7eebcc30c4522f1c8451e10a767982175c2
5
+ SHA512:
6
+ metadata.gz: a4fe76b95dec7bbc2666b885beb65b061c68df9a981e1a32d5aff24787459245bddc7433c51d679f127fcd4b72370edc9f471929bb61156c405e1bcffea48e5b
7
+ data.tar.gz: 70cc8a76bc0128699aced831b63cd6a6c9274969b69fd8e96f9c51ecfee95d27669dc8414a631ce87409c33e0d9e25e6f17545b66a0f4375b51c5c8e8573d02a
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in blanket_cachekey.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Karl Baum
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,56 @@
1
+ # BlanketCachekey
2
+
3
+ [![Build Status](https://secure.travis-ci.org/kbaum/blanket_cachekey.png)](http://travis-ci.org/kbaum/blanket_cachekey)
4
+
5
+
6
+ Provides a rails cache key for caching data that should be invalidated whenever any ActiveRecord instance of a specific type is created, updated, or destroyed.
7
+
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'blanket_cachekey'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install blanket_cachekey
22
+
23
+ ## Usage
24
+
25
+ Include BlanketCachekey within your ActiveRecord class:
26
+
27
+ ```ruby
28
+ class Bar < ActiveRecord::Base
29
+
30
+ include BlanketCachekey
31
+
32
+ end
33
+ ```
34
+
35
+ Now Bar has a blanket_cachekey method which is updated whenever any instance of Bar is created, updated, or destroyed. This key can be used
36
+ as part of a cache key.
37
+
38
+ ```haml
39
+ = cache ['bars_selector', Bar.blanket_cachekey] do
40
+ f.input :bars, collection: Bar.all
41
+ ```
42
+
43
+ Now whenever any Bar is created, updated, or saved, the cache fragment above will be regenerated on the next hit.
44
+
45
+
46
+
47
+
48
+
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'blanket_cachekey/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "blanket_cachekey"
8
+ spec.version = BlanketCachekey::VERSION
9
+ spec.authors = ["Karl Baum"]
10
+ spec.email = ["karl.baum@gmail.com"]
11
+ spec.description = %q{Provides a rails cache key for caching data that should be invalidated whenever any ActiveRecord instance of a specific type is created, updated, or destroyed.}
12
+ spec.summary = %q{Provides a rails cache key for caching data that should be invalidated whenever any ActiveRecord instance of a specific type is created, updated, or destroyed.}
13
+ spec.homepage = "https://github.com/kbaum/blanket_cachekey"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rails"
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "sqlite3"
26
+ end
@@ -0,0 +1,51 @@
1
+ require 'blanket_cachekey/version'
2
+ require 'rails'
3
+ require 'blanket_cachekey/engine'
4
+
5
+ module BlanketCachekey
6
+
7
+ class << self
8
+ attr_accessor :cache
9
+ end
10
+
11
+
12
+ def self.included(model)
13
+ model.class_eval do
14
+
15
+ after_save :invalidate_blanket_cachekey
16
+ after_destroy :invalidate_blanket_cachekey
17
+
18
+ private
19
+
20
+ def invalidate_blanket_cachekey
21
+ self.class.invalidate_blanket_cachekey
22
+ end
23
+
24
+
25
+ class << self
26
+
27
+
28
+ def blanket_cachekey
29
+ BlanketCachekey.cache.fetch(blanket_cachekey_name) do
30
+ "#{table_name}:#{Time.now.to_i}:#{Time.now.nsec}"
31
+ end
32
+ end
33
+
34
+ def invalidate_blanket_cachekey
35
+ BlanketCachekey.cache.delete blanket_cachekey_name
36
+ end
37
+
38
+ private
39
+
40
+ def blanket_cachekey_name
41
+ "blanket_cachekey:name:#{self.table_name}"
42
+ end
43
+
44
+
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -0,0 +1,7 @@
1
+ module BlanketCachekey
2
+ class Engine < ::Rails::Engine
3
+ config.after_initialize do
4
+ BlanketCachekey.cache = Rails.cache
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module BlanketCachekey
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+ require 'active_record'
3
+
4
+ ActiveRecord::Base.establish_connection(
5
+ :adapter => 'sqlite3',
6
+ :database => ':memory:'
7
+ )
8
+
9
+ class Bar < ActiveRecord::Base
10
+
11
+ include BlanketCachekey
12
+
13
+ end
14
+
15
+ ActiveRecord::Schema.define(:version => 1) do
16
+ create_table :bars do |t|
17
+ end
18
+ end
19
+
20
+
21
+ describe BlanketCachekey do
22
+
23
+ before :all do
24
+ BlanketCachekey.cache = ActiveSupport::Cache::MemoryStore.new
25
+ end
26
+
27
+ it 'should have a version number' do
28
+ BlanketCachekey::VERSION.should_not be_nil
29
+ end
30
+
31
+ describe '#blanket_cachekey' do
32
+
33
+ subject { Bar }
34
+
35
+ its(:blanket_cachekey){ should_not be_nil }
36
+
37
+ specify 'blanket_cachekey should not change if no Bar has been modified in any way' do
38
+ Bar.blanket_cachekey.should == Bar.blanket_cachekey
39
+ end
40
+
41
+ describe 'adding a new model causes a new blanket cache key to be invalidated for bar' do
42
+
43
+ before do
44
+ @old_cache_key = Bar.blanket_cachekey
45
+ Bar.create!
46
+ end
47
+
48
+ its(:blanket_cachekey){ should_not == @old_cache_key }
49
+
50
+ end
51
+
52
+ describe 'updating a model causes blanket cache key to be invalidated for bar' do
53
+
54
+ before do
55
+ bar = Bar.create!
56
+ @old_cache_key = Bar.blanket_cachekey
57
+ bar.save!
58
+ end
59
+
60
+ its(:blanket_cachekey){ should_not == @old_cache_key }
61
+
62
+
63
+ end
64
+
65
+ describe 'destroying a model causes blanket cache key to be invalidated for bar' do
66
+
67
+ before do
68
+ bar = Bar.create!
69
+ @old_cache_key = Bar.blanket_cachekey
70
+ bar.destroy
71
+ end
72
+
73
+ its(:blanket_cachekey){ should_not == @old_cache_key }
74
+
75
+
76
+ end
77
+
78
+
79
+
80
+
81
+ end
82
+
83
+ end
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'blanket_cachekey'
3
+
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blanket_cachekey
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Karl Baum
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
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
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Provides a rails cache key for caching data that should be invalidated
84
+ whenever any ActiveRecord instance of a specific type is created, updated, or destroyed.
85
+ email:
86
+ - karl.baum@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .rspec
93
+ - .travis.yml
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - blanket_cachekey.gemspec
99
+ - lib/blanket_cachekey.rb
100
+ - lib/blanket_cachekey/engine.rb
101
+ - lib/blanket_cachekey/version.rb
102
+ - spec/blanket_cachekey_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: https://github.com/kbaum/blanket_cachekey
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.0.3
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Provides a rails cache key for caching data that should be invalidated whenever
128
+ any ActiveRecord instance of a specific type is created, updated, or destroyed.
129
+ test_files:
130
+ - spec/blanket_cachekey_spec.rb
131
+ - spec/spec_helper.rb