Class: Rack::Cache::Tags::Store::ActiveRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/cache/tags/store/active_record.rb

Defined Under Namespace

Classes: Tagging

Instance Method Summary collapse

Instance Method Details

#purge(tags) ⇒ Object



16
17
18
# File 'lib/rack/cache/tags/store/active_record.rb', line 16

def purge(tags)
  urls_by_tags(tags).tap { |urls| Tagging.where(:url => urls).delete_all }
end

#store(url, tags) ⇒ Object



12
13
14
# File 'lib/rack/cache/tags/store/active_record.rb', line 12

def store(url, tags)
  tags.each { |tag| Tagging.find_or_create_by_url_and_tag(url, tag) }
end

#taggings_by_tags(tags) ⇒ Object



24
25
26
27
# File 'lib/rack/cache/tags/store/active_record.rb', line 24

def taggings_by_tags(tags)
  sql = "tag IN (?) #{[' OR tag LIKE ?'] * tags.size}"
  Tagging.where(sql, tags, *tags.map { |tag| "#{tag.split(':').first}%" })
end

#urls_by_tags(tags) ⇒ Object



20
21
22
# File 'lib/rack/cache/tags/store/active_record.rb', line 20

def urls_by_tags(tags)
  taggings_by_tags(tags).map(&:url)
end