class CacheRocket::Fragment
Public Class Methods
new(value)
click to toggle source
# File lib/cache_rocket/fragment.rb, line 7 def initialize(value) @value = value.to_s.dup end
Public Instance Methods
gsub!(key, value)
click to toggle source
# File lib/cache_rocket/fragment.rb, line 15 def gsub!(key, value) @value.gsub! key, value end
replace(hash, collection = nil)
click to toggle source
# File lib/cache_rocket/fragment.rb, line 19 def replace(hash, collection = nil) if collection replace_collection collection, hash else replace_from_hash hash end self end
to_s()
click to toggle source
# File lib/cache_rocket/fragment.rb, line 11 def to_s @value end
Private Instance Methods
replace_collection(collection, replace_hash)
click to toggle source
# File lib/cache_rocket/fragment.rb, line 36 def replace_collection(collection, replace_hash) html = "" collection.each do |item| html += replace_item_hash(item, replace_hash) end @value = html end
replace_from_hash(hash)
click to toggle source
# File lib/cache_rocket/fragment.rb, line 30 def replace_from_hash(hash) hash.each do |key, value| gsub! cache_replace_key(key), value.to_s end end
replace_item_hash(item, hash)
click to toggle source
# File lib/cache_rocket/fragment.rb, line 46 def replace_item_hash(item, hash) item_fragment = @value.dup hash.each do |key, proc| item_fragment.gsub! cache_replace_key(key), proc.call(item) end item_fragment end