reference_tracking 0.0.1 → 0.0.2
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/lib/reference_tracking.rb
CHANGED
@@ -2,12 +2,19 @@ require 'active_support/core_ext/kernel/singleton_class'
|
|
2
2
|
require 'action_controller'
|
3
3
|
|
4
4
|
module ReferenceTracking
|
5
|
-
TAGS_HEADER
|
5
|
+
TAGS_HEADER = 'rack-cache.tags'
|
6
|
+
PURGE_TAGS_HEADER = 'rack-cache.purge-tags'
|
6
7
|
|
7
8
|
autoload :ActionController, 'reference_tracking/action_controller'
|
8
9
|
autoload :IvarProxy, 'reference_tracking/ivar_proxy'
|
9
10
|
autoload :Tracker, 'reference_tracking/tracker'
|
10
11
|
autoload :References, 'reference_tracking/references'
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def to_tag(object, method = nil)
|
15
|
+
"#{object.class.name.underscore}-#{object.id}#{":#{method}" if method}"
|
16
|
+
end
|
17
|
+
end
|
11
18
|
end
|
12
19
|
|
13
20
|
ActionController::Base.send(:extend, ReferenceTracking::ActionController::ActMacro)
|
@@ -3,7 +3,7 @@ module ReferenceTracking
|
|
3
3
|
module ActMacro
|
4
4
|
def tracks(*args)
|
5
5
|
unless tracks_references?
|
6
|
-
include ReferenceTracking::ActionController
|
6
|
+
include ReferenceTracking::ActionController::Tracking
|
7
7
|
|
8
8
|
class_inheritable_accessor :reference_tracking_options
|
9
9
|
self.reference_tracking_options = { :header => TAGS_HEADER }
|
@@ -22,19 +22,46 @@ module ReferenceTracking
|
|
22
22
|
def tracks_references?
|
23
23
|
respond_to?(:reference_tracking_options) && reference_tracking_options.present?
|
24
24
|
end
|
25
|
+
|
26
|
+
def purges(*actions)
|
27
|
+
unless purges?
|
28
|
+
include ReferenceTracking::ActionController::Purging
|
29
|
+
class_inheritable_accessor :purging_options
|
30
|
+
self.purging_options = { :header => PURGE_TAGS_HEADER, :actions => [] }
|
31
|
+
end
|
32
|
+
|
33
|
+
self.purging_options[:actions] += actions.map(&:to_sym)
|
34
|
+
self.purging_options[:actions].uniq
|
35
|
+
end
|
36
|
+
|
37
|
+
def purges?
|
38
|
+
respond_to?(:purging_options)
|
39
|
+
end
|
40
|
+
|
41
|
+
def purge?(action)
|
42
|
+
purges? && purging_options[:actions].include?(action.to_sym)
|
43
|
+
end
|
25
44
|
end
|
26
45
|
|
27
46
|
# TODO could this hook into instrumentation?
|
28
47
|
# ActiveSupport::Notifications.instrument("render_template.action_view", ...)?
|
29
48
|
|
30
|
-
|
31
|
-
|
32
|
-
|
49
|
+
module Tracking
|
50
|
+
def render(*)
|
51
|
+
methods = reference_tracking_options[params[:action].to_sym] || {}
|
52
|
+
@_references = ReferenceTracking::References.new(self, methods)
|
53
|
+
|
54
|
+
result = super
|
33
55
|
|
34
|
-
|
56
|
+
headers[reference_tracking_options[:header]] = @_references.tags unless @_references.empty?
|
57
|
+
result
|
58
|
+
end
|
59
|
+
end
|
35
60
|
|
36
|
-
|
37
|
-
|
61
|
+
module Purging
|
62
|
+
def purge(objects)
|
63
|
+
response.headers[purging_options[:header]] = objects.map { |object| ReferenceTracking.to_tag(object) }
|
64
|
+
end
|
38
65
|
end
|
39
66
|
end
|
40
67
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reference_tracking
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sven Fuchs
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-05 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|