Class: NiceCache::Fragment

Inherits:
Object
  • Object
show all
Defined in:
lib/nice_cache/fragment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nice_cache, name, tag_names = []) ⇒ Fragment

Returns a new instance of Fragment.



13
14
15
16
17
18
19
20
# File 'lib/nice_cache/fragment.rb', line 13

def initialize(nice_cache, name, tag_names = [])
  @nice_cache = nice_cache
  @name = name
  unless tag_names.empty?
    attach_tags(tag_names)
    persist
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/nice_cache/fragment.rb', line 3

def name
  @name
end

Class Method Details

.allObject



5
6
7
# File 'lib/nice_cache/fragment.rb', line 5

def self.all
  "AllFragments"
end

.find(nice_cache, name) ⇒ Object



9
10
11
# File 'lib/nice_cache/fragment.rb', line 9

def self.find(nice_cache, name)
  new(nice_cache, name)
end

Instance Method Details

#==(other) ⇒ Object



39
40
41
42
43
# File 'lib/nice_cache/fragment.rb', line 39

def ==(other)
  name == other.name
rescue
  false
end

#attach_with(tag) ⇒ Object



26
27
28
# File 'lib/nice_cache/fragment.rb', line 26

def attach_with(tag)
  store.sadd(tags_for_me, tag.name)
end

#deleteObject



30
31
32
33
34
35
36
37
# File 'lib/nice_cache/fragment.rb', line 30

def delete
  tags.each do |tag|
    tag.remove_from(self)
  end
  # TODO: Timestamps

  destroy
end

#tagsObject



22
23
24
# File 'lib/nice_cache/fragment.rb', line 22

def tags
  Tag.find(@nice_cache, tags_list)
end