Class: NiceCache::Fragment
- Inherits:
-
Object
- Object
- NiceCache::Fragment
- Defined in:
- lib/nice_cache/fragment.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #attach_with(tag) ⇒ Object
- #create(data, tag_names) ⇒ Object
- #destroy ⇒ Object
- #find(name) ⇒ Object
-
#initialize(data = nil, tag_names = nil) ⇒ Fragment
constructor
A new instance of Fragment.
- #tags ⇒ Object
Constructor Details
#initialize(data = nil, tag_names = nil) ⇒ Fragment
Returns a new instance of Fragment.
19 20 21 |
# File 'lib/nice_cache/fragment.rb', line 19 def initialize(data = nil, tag_names = nil) create(data, tag_names) if data && tag_names end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/nice_cache/fragment.rb', line 5 def data @data end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/nice_cache/fragment.rb', line 5 def name @name end |
Class Method Details
.find(name) ⇒ Object
7 8 9 |
# File 'lib/nice_cache/fragment.rb', line 7 def self.find(name) new.find(name) end |
.key(name) ⇒ Object
11 12 13 |
# File 'lib/nice_cache/fragment.rb', line 11 def self.key(name) "Fragment:#{name}" end |
.tags_for(name) ⇒ Object
15 16 17 |
# File 'lib/nice_cache/fragment.rb', line 15 def self.(name) "TagsFor:#{name}" end |
Instance Method Details
#==(other) ⇒ Object
54 55 56 57 58 |
# File 'lib/nice_cache/fragment.rb', line 54 def ==(other) [name, data] == [other.name, other.data] rescue false end |
#attach_with(tag) ⇒ Object
40 41 42 |
# File 'lib/nice_cache/fragment.rb', line 40 def attach_with(tag) redis.sadd(, tag.name) end |
#create(data, tag_names) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/nice_cache/fragment.rb', line 23 def create(data, tag_names) @name = stringify(tag_names) @data = data (tag_names) save_to_redis end |
#destroy ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/nice_cache/fragment.rb', line 44 def destroy .each do |tag| tag.remove_from(self) end redis.srem(NiceCache.all_fragments_key, @name) redis.del redis.del fragment_key end |
#find(name) ⇒ Object
30 31 32 33 34 |
# File 'lib/nice_cache/fragment.rb', line 30 def find(name) @name = name @data = data_from_redis self end |
#tags ⇒ Object
36 37 38 |
# File 'lib/nice_cache/fragment.rb', line 36 def Tag.find(redis_tag_names) end |