timed_fragment_cache 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jeroen Jacobs
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = timed_fragment_cache
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Jeroen Jacobs. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "timed_fragment_cache"
8
+ gem.summary = "Timed fragment caching"
9
+ gem.description = "You'll be able to automatically invalidate a cache on a specified time."
10
+ gem.email = "jj@redstorm.be"
11
+ gem.homepage = "http://github.com/jeroenj/timed_fragment_cache"
12
+ gem.authors = ["Jeroen Jacobs"]
13
+ gem.add_development_dependency "rspec", ">= 2.0.0.beta.15"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "timed_fragment_cache #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require "#{File.dirname(__FILE__)}/rails/init"
@@ -0,0 +1,45 @@
1
+ module ActionController
2
+ module Caching
3
+ module TimedFragment
4
+ def when_fragment_expired(name, expiry=nil)
5
+ if fragment_exist?(name)
6
+ if fragment_expired?(name)
7
+ expire_timed_fragment(name)
8
+ write_meta_fragment(name, expiry)
9
+ write_fragment(name, yield)
10
+ else
11
+ read_fragment(name)
12
+ end
13
+ else
14
+ write_meta_fragment(name, expiry)
15
+ write_fragment(name, yield)
16
+ end
17
+ end
18
+
19
+ def expire_timed_fragment(name)
20
+ expire_meta_fragment(name)
21
+ expire_fragment(name)
22
+ end
23
+
24
+ private
25
+ def fragment_expired?(name)
26
+ expiry = read_meta_fragment(name)
27
+ expiry && expiry < Time.zone.now
28
+ end
29
+
30
+ def write_meta_fragment(name, content)
31
+ write_fragment("#{name}_meta", content)
32
+ end
33
+
34
+ def read_meta_fragment(name)
35
+ read_fragment("#{name}_meta")
36
+ end
37
+
38
+ def expire_meta_fragment(name)
39
+ expire_fragment("#{name}_meta")
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ ActionController::Base.send :include, ActionController::Caching::TimedFragment
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'timed_fragment_cache'
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'timed_fragment_cache'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "TimedFragmentCache" do
4
+ it "is not covered yet, shame on me!" do
5
+ pending "It's about time that you cover this code, don't you think?"
6
+ end
7
+ end
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{timed_fragment_cache}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jeroen Jacobs"]
12
+ s.date = %q{2010-07-01}
13
+ s.description = %q{You'll be able to automatically invalidate a cache on a specified time.}
14
+ s.email = %q{jj@redstorm.be}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ ".rspec",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "init.rb",
28
+ "lib/timed_fragment_cache.rb",
29
+ "rails/init.rb",
30
+ "spec/spec_helper.rb",
31
+ "spec/timed_fragment_cache_spec.rb",
32
+ "timed_fragment_cache.gemspec"
33
+ ]
34
+ s.homepage = %q{http://github.com/jeroenj/timed_fragment_cache}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.6}
38
+ s.summary = %q{Timed fragment caching}
39
+ s.test_files = [
40
+ "spec/spec_helper.rb",
41
+ "spec/timed_fragment_cache_spec.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.15"])
50
+ else
51
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.15"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.15"])
55
+ end
56
+ end
57
+
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: timed_fragment_cache
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Jeroen Jacobs
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-01 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 0
30
+ - 0
31
+ - beta
32
+ - 15
33
+ version: 2.0.0.beta.15
34
+ type: :development
35
+ version_requirements: *id001
36
+ description: You'll be able to automatically invalidate a cache on a specified time.
37
+ email: jj@redstorm.be
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - LICENSE
44
+ - README.rdoc
45
+ files:
46
+ - .document
47
+ - .gitignore
48
+ - .rspec
49
+ - LICENSE
50
+ - README.rdoc
51
+ - Rakefile
52
+ - VERSION
53
+ - init.rb
54
+ - lib/timed_fragment_cache.rb
55
+ - rails/init.rb
56
+ - spec/spec_helper.rb
57
+ - spec/timed_fragment_cache_spec.rb
58
+ - timed_fragment_cache.gemspec
59
+ has_rdoc: true
60
+ homepage: http://github.com/jeroenj/timed_fragment_cache
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --charset=UTF-8
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirements: []
83
+
84
+ rubyforge_project:
85
+ rubygems_version: 1.3.6
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Timed fragment caching
89
+ test_files:
90
+ - spec/spec_helper.rb
91
+ - spec/timed_fragment_cache_spec.rb