surveillance_authority 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +58 -0
- data/README.md +151 -0
- data/VERSION +1 -1
- data/lib/surveillance_authority.rb +9 -0
- data/spec/plugin_configuration_spec.rb +33 -0
- data/surveillance_authority.gemspec +10 -4
- metadata +34 -18
- data/README.rdoc +0 -81
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
archive-tar-minitar (0.5.2)
|
5
|
+
columnize (0.3.1)
|
6
|
+
diff-lcs (1.1.2)
|
7
|
+
git (1.2.5)
|
8
|
+
jeweler (1.5.0.pre3)
|
9
|
+
bundler (~> 1.0.0)
|
10
|
+
git (>= 1.2.5)
|
11
|
+
rake
|
12
|
+
linecache19 (0.5.11)
|
13
|
+
ruby_core_source (>= 0.1.4)
|
14
|
+
rake (0.8.7)
|
15
|
+
rcov (0.9.9)
|
16
|
+
reek (1.2.8)
|
17
|
+
ruby2ruby (~> 1.2)
|
18
|
+
ruby_parser (~> 2.0)
|
19
|
+
sexp_processor (~> 3.0)
|
20
|
+
rspec (2.0.0.beta.22)
|
21
|
+
rspec-core (= 2.0.0.beta.22)
|
22
|
+
rspec-expectations (= 2.0.0.beta.22)
|
23
|
+
rspec-mocks (= 2.0.0.beta.22)
|
24
|
+
rspec-core (2.0.0.beta.22)
|
25
|
+
rspec-expectations (2.0.0.beta.22)
|
26
|
+
diff-lcs (>= 1.1.2)
|
27
|
+
rspec-mocks (2.0.0.beta.22)
|
28
|
+
rspec-core (= 2.0.0.beta.22)
|
29
|
+
rspec-expectations (= 2.0.0.beta.22)
|
30
|
+
ruby-debug-base19 (0.11.24)
|
31
|
+
columnize (>= 0.3.1)
|
32
|
+
linecache19 (>= 0.5.11)
|
33
|
+
ruby_core_source (>= 0.1.4)
|
34
|
+
ruby-debug19 (0.11.6)
|
35
|
+
columnize (>= 0.3.1)
|
36
|
+
linecache19 (>= 0.5.11)
|
37
|
+
ruby-debug-base19 (>= 0.11.19)
|
38
|
+
ruby2ruby (1.2.5)
|
39
|
+
ruby_parser (~> 2.0)
|
40
|
+
sexp_processor (~> 3.0)
|
41
|
+
ruby_core_source (0.1.4)
|
42
|
+
archive-tar-minitar (>= 0.5.2)
|
43
|
+
ruby_parser (2.0.5)
|
44
|
+
sexp_processor (~> 3.0)
|
45
|
+
sexp_processor (3.0.5)
|
46
|
+
yard (0.6.1)
|
47
|
+
|
48
|
+
PLATFORMS
|
49
|
+
ruby
|
50
|
+
|
51
|
+
DEPENDENCIES
|
52
|
+
bundler (~> 1.0.0)
|
53
|
+
jeweler (~> 1.5.0.pre3)
|
54
|
+
rcov
|
55
|
+
reek (~> 1.2.8)
|
56
|
+
rspec (>= 2.0.0.beta.19)
|
57
|
+
ruby-debug19
|
58
|
+
yard (~> 0.6.0)
|
data/README.md
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
surveillance_authority
|
2
|
+
======================
|
3
|
+
|
4
|
+
Introduction
|
5
|
+
------------
|
6
|
+
|
7
|
+
This gem provides a dsl to easily write observers in one or more centralized files.
|
8
|
+
|
9
|
+
Installation
|
10
|
+
------------
|
11
|
+
|
12
|
+
Install _surveillance_authority_ by adding
|
13
|
+
|
14
|
+
`gem 'surveillance_authority'`
|
15
|
+
|
16
|
+
to your Gemfile or install it using
|
17
|
+
|
18
|
+
`gem install surveillance_authority`
|
19
|
+
|
20
|
+
Integration into your project
|
21
|
+
-----------------------------
|
22
|
+
|
23
|
+
In
|
24
|
+
|
25
|
+
`config/initializers`
|
26
|
+
|
27
|
+
create one or more ruby files in which you can define your surveillance rules. For example:
|
28
|
+
|
29
|
+
<code>
|
30
|
+
SurveillanceAuthority.observe do
|
31
|
+
# Do something after a new movie was created
|
32
|
+
after "Movie#create" do |movie|
|
33
|
+
# ... do stuff
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
# Do something before a User gets updated
|
38
|
+
before "User#update" do |user|
|
39
|
+
# ... do stuff
|
40
|
+
end
|
41
|
+
end
|
42
|
+
</code>
|
43
|
+
|
44
|
+
Uhm ...so what?
|
45
|
+
---------------
|
46
|
+
|
47
|
+
_surveillance_authority_ is meant to be used together with some plugins. One of those is varnish_sweeper, which invalidates certain routes.
|
48
|
+
|
49
|
+
Writing plugins for _surveillance_authority_
|
50
|
+
------------------------------------------
|
51
|
+
|
52
|
+
### Making methods available to _surveillance_authority_
|
53
|
+
|
54
|
+
In order to write a plugin for _surveillance_authority_, simply create a class that inherits from
|
55
|
+
|
56
|
+
`SurveillanceAuthority::Sanctions`
|
57
|
+
|
58
|
+
all public methods of that class will be available in the blocks. E.g.
|
59
|
+
|
60
|
+
<code>
|
61
|
+
|
62
|
+
class VarnishSweeper < SurveillanceAuthority::Sanctions
|
63
|
+
def sweep(url, options = {})
|
64
|
+
options.reverse_merge(
|
65
|
+
:method => :invalidate
|
66
|
+
}
|
67
|
+
|
68
|
+
options[:method] == :purge ? purge_url(url) : invalidate(url)
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
def purge_url(url)
|
73
|
+
...
|
74
|
+
end
|
75
|
+
|
76
|
+
def invalidate(url)
|
77
|
+
...
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
</code>
|
82
|
+
|
83
|
+
will make the sweep method available:
|
84
|
+
|
85
|
+
<code>
|
86
|
+
|
87
|
+
SurveillanceAuthority.observe do
|
88
|
+
# Do something after a new movie was updated
|
89
|
+
after "Movie#update" do |movie|
|
90
|
+
sweep movie_path(movie), :method => :invalidate
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
</code>
|
95
|
+
|
96
|
+
### Configuration for plugins
|
97
|
+
|
98
|
+
Configuring plugins should be made with the central config method provided by _surveillance_authority_. If we again use a plugin called `VarnishSweeper`, configuring this plugin should happen like this:
|
99
|
+
|
100
|
+
`SurveillanceAuthority.config(VarnishSweeper, <hash with options>)`
|
101
|
+
|
102
|
+
Withing your plugin, you will be able to access your options simply by calling `config`.
|
103
|
+
|
104
|
+
#### Example: `VarnishSweep` needs to be configured with a base url to varnish
|
105
|
+
|
106
|
+
<code>
|
107
|
+
|
108
|
+
class VarnishSweeper < SurveillanceAuthority::Sanctions
|
109
|
+
def sweep(url, options = {})
|
110
|
+
options.reverse_merge(
|
111
|
+
:method => :invalidate
|
112
|
+
}
|
113
|
+
|
114
|
+
options[:method] == :purge ? purge_url(url) : invalidate(url)
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
def varnish_base_url
|
119
|
+
config[:base_url]
|
120
|
+
end
|
121
|
+
|
122
|
+
def purge_url(url)
|
123
|
+
...
|
124
|
+
end
|
125
|
+
|
126
|
+
def invalidate(url)
|
127
|
+
...
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
</code>
|
132
|
+
|
133
|
+
In the project using this plugin:
|
134
|
+
|
135
|
+
<code>
|
136
|
+
|
137
|
+
SurveillanceAuthority.config(VarnishSweeper, :base_url => "http://varnish.example.com")
|
138
|
+
|
139
|
+
...
|
140
|
+
</code>
|
141
|
+
|
142
|
+
If you want to access the config of other plugins, use:
|
143
|
+
|
144
|
+
`SurveillanceAuthority.config_for(<plugin>)`
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
Copyright
|
149
|
+
---------
|
150
|
+
|
151
|
+
Copyright (c) 2010 Daniel Bornkessel. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -4,6 +4,7 @@ require 'singleton'
|
|
4
4
|
class SurveillanceAuthority
|
5
5
|
|
6
6
|
class Sanction
|
7
|
+
attr_accessor :config
|
7
8
|
include Singleton
|
8
9
|
|
9
10
|
VALID_HOOKS = [:validation, :validation_on_create, :save, :create]
|
@@ -85,6 +86,14 @@ class SurveillanceAuthority
|
|
85
86
|
end
|
86
87
|
end
|
87
88
|
|
89
|
+
def self.config(klass, config)
|
90
|
+
klass.instance.config = config
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.config_for(klass)
|
94
|
+
klass.instance.config
|
95
|
+
end
|
96
|
+
|
88
97
|
def self.observe(&block)
|
89
98
|
SurveillanceAuthority::Sanction.instance.instance_eval(&block)
|
90
99
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
class Notify < SurveillanceAuthority::Sanction
|
4
|
+
def my_config
|
5
|
+
config
|
6
|
+
end
|
7
|
+
|
8
|
+
def notify2(message1, message2, message3)
|
9
|
+
puts message1
|
10
|
+
puts message2
|
11
|
+
puts message3
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "plugin configuration" do
|
16
|
+
it "should be possible to configure plugins with the SurveillanceAuthority.config method" do
|
17
|
+
SurveillanceAuthority.config(Notify, :option1 => true)
|
18
|
+
|
19
|
+
Notify.instance.config.should == {:option1 => true}
|
20
|
+
end
|
21
|
+
|
22
|
+
it "configuration should be accessible within the plugin" do
|
23
|
+
SurveillanceAuthority.config(Notify, :option2 => true)
|
24
|
+
|
25
|
+
Notify.instance.my_config.should == {:option2 => true}
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be possible to configure plugins with the SurveillanceAuthority.config method and retrieve this config with SurveillanceAuthority::config_for" do
|
29
|
+
SurveillanceAuthority.config(Notify, :option3 => true)
|
30
|
+
|
31
|
+
SurveillanceAuthority.config_for(Notify).should == {:option3 => true}
|
32
|
+
end
|
33
|
+
end
|
@@ -5,29 +5,31 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{surveillance_authority}
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.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 = ["Daniel Bornkessel"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-10-20}
|
13
13
|
s.description = %q{Write centralized model observers in a simple DSL}
|
14
14
|
s.email = %q{github@bornkessel.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
"README.
|
17
|
+
"README.md"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
".gitignore",
|
22
22
|
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
23
24
|
"LICENSE",
|
24
|
-
"README.
|
25
|
+
"README.md",
|
25
26
|
"Rakefile",
|
26
27
|
"VERSION",
|
27
28
|
"lib/surveillance_authority.rb",
|
28
29
|
"spec/.rspec",
|
29
30
|
"spec/hook_creation_spec.rb",
|
30
31
|
"spec/method_concatenation_spec.rb",
|
32
|
+
"spec/plugin_configuration_spec.rb",
|
31
33
|
"spec/plugin_tests_spec.rb",
|
32
34
|
"spec/spec_helper.rb",
|
33
35
|
"surveillance_authority.gemspec"
|
@@ -39,6 +41,7 @@ Gem::Specification.new do |s|
|
|
39
41
|
s.test_files = [
|
40
42
|
"spec/hook_creation_spec.rb",
|
41
43
|
"spec/method_concatenation_spec.rb",
|
44
|
+
"spec/plugin_configuration_spec.rb",
|
42
45
|
"spec/plugin_tests_spec.rb",
|
43
46
|
"spec/spec_helper.rb"
|
44
47
|
]
|
@@ -54,6 +57,7 @@ Gem::Specification.new do |s|
|
|
54
57
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.0.pre3"])
|
55
58
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
56
59
|
s.add_development_dependency(%q<reek>, ["~> 1.2.8"])
|
60
|
+
s.add_development_dependency(%q<ruby-debug19>, [">= 0"])
|
57
61
|
s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
58
62
|
s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
|
59
63
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
@@ -67,6 +71,7 @@ Gem::Specification.new do |s|
|
|
67
71
|
s.add_dependency(%q<jeweler>, ["~> 1.5.0.pre3"])
|
68
72
|
s.add_dependency(%q<rcov>, [">= 0"])
|
69
73
|
s.add_dependency(%q<reek>, ["~> 1.2.8"])
|
74
|
+
s.add_dependency(%q<ruby-debug19>, [">= 0"])
|
70
75
|
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
71
76
|
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
72
77
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
@@ -81,6 +86,7 @@ Gem::Specification.new do |s|
|
|
81
86
|
s.add_dependency(%q<jeweler>, ["~> 1.5.0.pre3"])
|
82
87
|
s.add_dependency(%q<rcov>, [">= 0"])
|
83
88
|
s.add_dependency(%q<reek>, ["~> 1.2.8"])
|
89
|
+
s.add_dependency(%q<ruby-debug19>, [">= 0"])
|
84
90
|
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
85
91
|
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
86
92
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 0.0.2
|
9
|
+
version: 0.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Daniel Bornkessel
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-10-20 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -109,8 +109,21 @@ dependencies:
|
|
109
109
|
prerelease: false
|
110
110
|
version_requirements: *id006
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: ruby-debug19
|
113
113
|
requirement: &id007 !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
version: "0"
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: *id007
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
name: rspec
|
126
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
114
127
|
none: false
|
115
128
|
requirements:
|
116
129
|
- - ">="
|
@@ -124,10 +137,10 @@ dependencies:
|
|
124
137
|
version: 2.0.0.beta.19
|
125
138
|
type: :development
|
126
139
|
prerelease: false
|
127
|
-
version_requirements: *
|
140
|
+
version_requirements: *id008
|
128
141
|
- !ruby/object:Gem::Dependency
|
129
142
|
name: yard
|
130
|
-
requirement: &
|
143
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
131
144
|
none: false
|
132
145
|
requirements:
|
133
146
|
- - ~>
|
@@ -139,10 +152,10 @@ dependencies:
|
|
139
152
|
version: 0.6.0
|
140
153
|
type: :development
|
141
154
|
prerelease: false
|
142
|
-
version_requirements: *
|
155
|
+
version_requirements: *id009
|
143
156
|
- !ruby/object:Gem::Dependency
|
144
157
|
name: bundler
|
145
|
-
requirement: &
|
158
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
146
159
|
none: false
|
147
160
|
requirements:
|
148
161
|
- - ~>
|
@@ -154,10 +167,10 @@ dependencies:
|
|
154
167
|
version: 1.0.0
|
155
168
|
type: :development
|
156
169
|
prerelease: false
|
157
|
-
version_requirements: *
|
170
|
+
version_requirements: *id010
|
158
171
|
- !ruby/object:Gem::Dependency
|
159
172
|
name: jeweler
|
160
|
-
requirement: &
|
173
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
161
174
|
none: false
|
162
175
|
requirements:
|
163
176
|
- - ~>
|
@@ -170,10 +183,10 @@ dependencies:
|
|
170
183
|
version: 1.5.0.pre3
|
171
184
|
type: :development
|
172
185
|
prerelease: false
|
173
|
-
version_requirements: *
|
186
|
+
version_requirements: *id011
|
174
187
|
- !ruby/object:Gem::Dependency
|
175
188
|
name: rcov
|
176
|
-
requirement: &
|
189
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
177
190
|
none: false
|
178
191
|
requirements:
|
179
192
|
- - ">="
|
@@ -183,10 +196,10 @@ dependencies:
|
|
183
196
|
version: "0"
|
184
197
|
type: :development
|
185
198
|
prerelease: false
|
186
|
-
version_requirements: *
|
199
|
+
version_requirements: *id012
|
187
200
|
- !ruby/object:Gem::Dependency
|
188
201
|
name: reek
|
189
|
-
requirement: &
|
202
|
+
requirement: &id013 !ruby/object:Gem::Requirement
|
190
203
|
none: false
|
191
204
|
requirements:
|
192
205
|
- - ~>
|
@@ -198,7 +211,7 @@ dependencies:
|
|
198
211
|
version: 1.2.8
|
199
212
|
type: :development
|
200
213
|
prerelease: false
|
201
|
-
version_requirements: *
|
214
|
+
version_requirements: *id013
|
202
215
|
description: Write centralized model observers in a simple DSL
|
203
216
|
email: github@bornkessel.com
|
204
217
|
executables: []
|
@@ -207,19 +220,21 @@ extensions: []
|
|
207
220
|
|
208
221
|
extra_rdoc_files:
|
209
222
|
- LICENSE
|
210
|
-
- README.
|
223
|
+
- README.md
|
211
224
|
files:
|
212
225
|
- .document
|
213
226
|
- .gitignore
|
214
227
|
- Gemfile
|
228
|
+
- Gemfile.lock
|
215
229
|
- LICENSE
|
216
|
-
- README.
|
230
|
+
- README.md
|
217
231
|
- Rakefile
|
218
232
|
- VERSION
|
219
233
|
- lib/surveillance_authority.rb
|
220
234
|
- spec/.rspec
|
221
235
|
- spec/hook_creation_spec.rb
|
222
236
|
- spec/method_concatenation_spec.rb
|
237
|
+
- spec/plugin_configuration_spec.rb
|
223
238
|
- spec/plugin_tests_spec.rb
|
224
239
|
- spec/spec_helper.rb
|
225
240
|
- surveillance_authority.gemspec
|
@@ -237,7 +252,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
237
252
|
requirements:
|
238
253
|
- - ">="
|
239
254
|
- !ruby/object:Gem::Version
|
240
|
-
hash:
|
255
|
+
hash: 1608769546526049591
|
241
256
|
segments:
|
242
257
|
- 0
|
243
258
|
version: "0"
|
@@ -259,5 +274,6 @@ summary: Write centralized model observers in a simple DSL
|
|
259
274
|
test_files:
|
260
275
|
- spec/hook_creation_spec.rb
|
261
276
|
- spec/method_concatenation_spec.rb
|
277
|
+
- spec/plugin_configuration_spec.rb
|
262
278
|
- spec/plugin_tests_spec.rb
|
263
279
|
- spec/spec_helper.rb
|
data/README.rdoc
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
= surveillance_authority
|
2
|
-
|
3
|
-
== Introduction
|
4
|
-
|
5
|
-
This gem provides a dsl to easily write observers in one or more centralized files.
|
6
|
-
|
7
|
-
== Installation
|
8
|
-
|
9
|
-
Install surveillance_authority by adding
|
10
|
-
|
11
|
-
gem 'surveillance_authority'
|
12
|
-
|
13
|
-
to your Gemfile or install it using
|
14
|
-
|
15
|
-
gem install surveillance_authority
|
16
|
-
|
17
|
-
== Integration into your project
|
18
|
-
|
19
|
-
In
|
20
|
-
|
21
|
-
config/initializers
|
22
|
-
|
23
|
-
create one or more ruby files in which you can define your surveillance rules. For example:
|
24
|
-
|
25
|
-
SurveillanceAuthority.observe do
|
26
|
-
# Do something after a new movie was created
|
27
|
-
after "Movie#create" do |movie|
|
28
|
-
# ... do stuff
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
# Do something before a User gets updated
|
33
|
-
before "User#update" do |user|
|
34
|
-
# ... do stuff
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
== Uhm ...so what?
|
39
|
-
|
40
|
-
surveillance_authority is meant to be used together with some plugins. One of those is varnish_sweeper, which invalidates certain routes.
|
41
|
-
|
42
|
-
== Writing plugins for surveillance_authority
|
43
|
-
|
44
|
-
In order to write a plugin for surveillance_authority, simply create a class that inherits from
|
45
|
-
|
46
|
-
SurveillanceAuthority::Sanctions
|
47
|
-
|
48
|
-
all public methods of that class will be available in the blocks. E.g.
|
49
|
-
|
50
|
-
class VarnishSweeper < SurveillanceAuthority::Sanctions
|
51
|
-
def sweep(url, options = {})
|
52
|
-
options.reverse_merge(
|
53
|
-
:method => :invalidate
|
54
|
-
}
|
55
|
-
|
56
|
-
options[:method] == :purge ? purge_url(url) : invalidate(url)
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
def purge_url(url)
|
61
|
-
...
|
62
|
-
end
|
63
|
-
|
64
|
-
def invalidate(url)
|
65
|
-
...
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
will make the sweep method available:
|
70
|
-
|
71
|
-
SurveillanceAuthority.observe do
|
72
|
-
# Do something after a new movie was created
|
73
|
-
after "Movie#create" do |movie|
|
74
|
-
sweep movie_path(movie), :method => :invalidate
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
|
79
|
-
== Copyright
|
80
|
-
|
81
|
-
Copyright (c) 2010 Daniel Bornkessel. See LICENSE for details.
|