reference_tracking 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 = 'rack-cache.tags'
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
- def render(*)
31
- methods = reference_tracking_options[params[:action].to_sym] || {}
32
- @_references = ReferenceTracking::References.new(self, methods)
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
- result = super
56
+ headers[reference_tracking_options[:header]] = @_references.tags unless @_references.empty?
57
+ result
58
+ end
59
+ end
35
60
 
36
- headers[reference_tracking_options[:header]] = @_references.tags
37
- result
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
@@ -5,9 +5,7 @@ module ReferenceTracking
5
5
  end
6
6
 
7
7
  def tags
8
- map do |object, method|
9
- "#{object.class.name.underscore}-#{object.id}#{":#{method}" if method}"
10
- end.uniq
8
+ map { |object, method| ReferenceTracking.to_tag(object, method) }.uniq
11
9
  end
12
10
  end
13
11
  end
@@ -1,3 +1,3 @@
1
1
  module ReferenceTracking
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  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: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
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-04 00:00:00 +02:00
18
+ date: 2010-09-05 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21