Class: Catche::Tag::Collect

Inherits:
Object
  • Object
show all
Defined in:
lib/catche/tag/collect.rb

Class Method Summary collapse

Class Method Details

.collection(context, resource_class = nil, include_base = true) ⇒ Object

Collects collection tags for a given context, for example the resource or a controller

Catche::Tag::Collect.collection(@task)
=> { :set => ["projects_1_tasks"], :expire => ["tasks", "projects_1_tasks"] }


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/catche/tag/collect.rb', line 28

def collection(context, resource_class=nil, include_base=true)
  resource_class  ||= context.class
  associations      = Catche::ResourceLoader.fetch(context, *resource_class.catche_associations)
  association_tags  = associations.map { |a| a.catche_tag }

  set_tags    = []
  expire_tags = []

  association_tags.each do |tag|
    set_tags  << Tag.join(tag, resource_class.catche_tag)
  end

  set_tags    << resource_class.catche_tag if association_tags.blank?

  expire_tags << resource_class.catche_tag if include_base
  expire_tags += set_tags

  {
    :set    => set_tags.uniq,
    :expire => expire_tags.uniq
  }
end

.resource(resource) ⇒ Object

Collects resource tags for a given resource

Catche::Tag::Collect.resource_tags(@task)
=> { :set => ["tasks_1"], :expire => ["tasks_1"] }


11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/catche/tag/collect.rb', line 11

def resource(resource)
  set_tags    = []
  expire_tags = []

  set_tags    << resource.catche_tag
  expire_tags << resource.catche_tag

  {
    :set    => set_tags.uniq,
    :expire => expire_tags.uniq
  }
end