refinerycms-varnish-pages 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -15,7 +15,7 @@ Jeweler::Tasks.new do |gem|
15
15
  gem.name = "refinerycms-varnish-pages"
16
16
  gem.homepage = "http://github.com/bitflut/refinerycms-varnish-pages"
17
17
  gem.license = "MIT"
18
- gem.summary = %Q{Purges caches from varnish for your shellac setup}
18
+ gem.summary = %Q{Purges refinerycms-pages from varnish}
19
19
  gem.description = %Q{Makes use of the shellac gem to purge caches on varnish servers of your refinerycms pages on create, update, destroy and reorder}
20
20
  gem.email = "marian@bitflut.com"
21
21
  gem.authors = ["Marian"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -1,16 +1,23 @@
1
- require 'refinerycms-base'
2
1
  require 'refinerycms-pages'
3
2
  require 'shellac'
4
3
 
5
- class Railtie < Rails::Railtie
6
-
7
- # Enable caching on refinerycms-pages
8
- config.after_initialize do
4
+ module Refinery
5
+ module VarnishPages
6
+ class Engine < Rails::Engine
7
+
8
+ config.before_initialize do
9
+ require File.expand_path('../refinerycms_varnish/pages_controller_extension', __FILE__)
10
+ require File.expand_path('../refinerycms_varnish/page_extension', __FILE__)
11
+ end
12
+
13
+ refinery.after_inclusion do
14
+ ::Admin::PagesController.send :include, RefinerycmsVarnish::PagesControllerExtension
15
+ end
16
+
17
+ config.to_prepare do
18
+ ::Page.send :include, ::RefinerycmsVarnish::PageExtension
19
+ end
9
20
 
10
- Admin::PagesController.class_eval do
11
- cache_sweeper :page_sweeper, :only => [:create, :update, :destroy]
12
21
  end
13
-
14
22
  end
15
-
16
23
  end
@@ -0,0 +1,37 @@
1
+ module RefinerycmsVarnish
2
+ module PageExtension
3
+
4
+ def self.included(base)
5
+ base.after_save :purge_page
6
+ base.after_destroy :purge_page
7
+
8
+ base.class_eval do
9
+
10
+ private
11
+ def purge_page
12
+
13
+ if ((self.respond_to?(:title_changed?) and self.title_changed?) or self.link_url_changed?) and self.show_in_menu
14
+
15
+ # it seems that attributes possibly relevant to other pages have changed
16
+ # -> we expire all urls
17
+ ActionController::Base.purge "/", true
18
+
19
+ elsif self.link_url and self.link_url.starts_with?("/")
20
+
21
+ # by now we assume that no attributes relevant to other pages have
22
+ # changed -> we expire this page only
23
+ ActionController::Base.purge self.link_url
24
+
25
+ else
26
+
27
+ # by now we know that there is no link_url -> we expire this page only
28
+ ActionController::Base.purge "/#{self.slug.name}"
29
+
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,18 @@
1
+ module RefinerycmsVarnish
2
+ module PagesControllerExtension
3
+
4
+ # register after filter
5
+ def self.included(c)
6
+ c.after_filter :purge_all, :only => [:update_positions]
7
+ end
8
+
9
+
10
+ def purge_all
11
+ Rails.logger.info "*** Purge all"
12
+
13
+ # purge all pages
14
+ purge "/", true
15
+ end
16
+
17
+ end
18
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{refinerycms-varnish-pages}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marian"]
@@ -25,7 +25,8 @@ Gem::Specification.new do |s|
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "lib/refinerycms-varnish-pages.rb",
28
- "lib/sweepers/page_sweeper.rb",
28
+ "lib/refinerycms_varnish/page_extension.rb",
29
+ "lib/refinerycms_varnish/pages_controller_extension.rb",
29
30
  "refinerycms-varnish-pages.gemspec",
30
31
  "test/helper.rb",
31
32
  "test/test_refinerycms-varnish-pages.rb"
@@ -34,7 +35,7 @@ Gem::Specification.new do |s|
34
35
  s.licenses = ["MIT"]
35
36
  s.require_paths = ["lib"]
36
37
  s.rubygems_version = %q{1.5.2}
37
- s.summary = %q{Purges caches from varnish for your shellac setup}
38
+ s.summary = %q{Purges refinerycms-pages from varnish}
38
39
  s.test_files = [
39
40
  "test/helper.rb",
40
41
  "test/test_refinerycms-varnish-pages.rb"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: refinerycms-varnish-pages
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Marian
@@ -97,7 +97,8 @@ files:
97
97
  - Rakefile
98
98
  - VERSION
99
99
  - lib/refinerycms-varnish-pages.rb
100
- - lib/sweepers/page_sweeper.rb
100
+ - lib/refinerycms_varnish/page_extension.rb
101
+ - lib/refinerycms_varnish/pages_controller_extension.rb
101
102
  - refinerycms-varnish-pages.gemspec
102
103
  - test/helper.rb
103
104
  - test/test_refinerycms-varnish-pages.rb
@@ -115,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
116
  requirements:
116
117
  - - ">="
117
118
  - !ruby/object:Gem::Version
118
- hash: 284842659046978568
119
+ hash: 260484902261579464
119
120
  segments:
120
121
  - 0
121
122
  version: "0"
@@ -131,7 +132,7 @@ rubyforge_project:
131
132
  rubygems_version: 1.5.2
132
133
  signing_key:
133
134
  specification_version: 3
134
- summary: Purges caches from varnish for your shellac setup
135
+ summary: Purges refinerycms-pages from varnish
135
136
  test_files:
136
137
  - test/helper.rb
137
138
  - test/test_refinerycms-varnish-pages.rb
@@ -1,46 +0,0 @@
1
- class PageSweeper < ActionController::Caching::Sweeper
2
- observe Page, Slug
3
-
4
- def after_save model
5
- expire_cache model
6
- end
7
-
8
- def after_destroy model
9
- expire_cache model
10
- end
11
-
12
- private
13
-
14
- def expire_cache model
15
- case model.class.name.to_s
16
- when "Page"
17
- # only expire latest slug
18
- # in case title changes, it will trigger the expire_slug function from the observer
19
- purge "/#{model.slug.name}"
20
-
21
- # expire all cache if we change root page
22
- purge nil, true if (model.root?)
23
- when "Slug"
24
- # expire from parent level down
25
- expire_parent_and_descendants model
26
- end
27
- end
28
-
29
- private
30
-
31
- # expire the parent directory and page
32
- def expire_parent_and_descendants slug
33
- purge parent_slug(slug), true
34
- end
35
-
36
- def parent_slug slug
37
- if slug.sluggable_type == "Page"
38
- if slug.sluggable.root?
39
- slug
40
- else
41
- slug.sluggable.parent.slug.name
42
- end
43
- end
44
- end
45
-
46
- end