Class: Mist::PostSweeper

Inherits:
ActionController::Caching::Sweeper
  • Object
show all
Defined in:
app/models/mist/post_sweeper.rb

Instance Method Summary collapse

Instance Method Details

#after_destroy(post) ⇒ Object



8
9
10
# File 'app/models/mist/post_sweeper.rb', line 8

def after_destroy(post)
  bust! post
end

#after_save(post) ⇒ Object



4
5
6
# File 'app/models/mist/post_sweeper.rb', line 4

def after_save(post)
  bust! post
end

#before_save(post) ⇒ Object



12
13
14
# File 'app/models/mist/post_sweeper.rb', line 12

def before_save(post)
  @tags_were = post.tags_was
end

#bust!(post) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/mist/post_sweeper.rb', line 16

def bust!(post)
  expire_page :action => 'feed', :format => 'atom'

  touched = touched_posts post
  each_combo(Mist.authorized_actions) do |options|
    options.keys.each { |key| options.delete(key) unless options[key] }

    expire_page options.merge(:action => 'index')
    bust_post! post, options
    touched.each { |p| bust_post! p, options }
  end
end

#bust_post!(post, options) ⇒ Object



29
30
31
# File 'app/models/mist/post_sweeper.rb', line 29

def bust_post!(post, options)
  expire_action   options.merge(:action => 'show', :id => post.id)
end

#touched_posts(post) ⇒ Object



33
34
35
# File 'app/models/mist/post_sweeper.rb', line 33

def touched_posts(post)
  (post.similar_posts | Mist::Post.matching_tags(@tags_were)).tap { |a| a.delete post }
end