class CacheUtil

Public Class Methods

class_to_type(clazz) click to toggle source
# File lib/cache_driver/cache_util.rb, line 43
def class_to_type(clazz)
  cla_str = clazz.name
  cla_str.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase
end
delete(type, key) click to toggle source
# File lib/cache_driver/cache_util.rb, line 28
def delete(type, key)
  if CacheDriver.logger
    CacheDriver.logger.debug "[CACHE] delete #{type} ##{key} from cache"
  else
    puts "[CACHE] delete #{type} ##{key} from cache"
  end
end
read(type, key) click to toggle source
# File lib/cache_driver/cache_util.rb, line 12
def read(type, key)
  if CacheDriver.logger
    CacheDriver.logger.debug "[CACHE] get #{type} ##{key} from cache"
  else
    puts "[CACHE] get #{type} ##{key} from cache"
  end
end
read_all(type) click to toggle source
# File lib/cache_driver/cache_util.rb, line 20
def read_all(type)
  if CacheDriver.logger
    CacheDriver.logger.debug "[CACHE] get all #{type} from cache"
  else
    puts "[CACHE] get all #{type} from cache"
  end
end
type_to_class(type) click to toggle source

type –> :room class –> Room dir –> 'rooms'

# File lib/cache_driver/cache_util.rb, line 39
def type_to_class(type)
  type.to_s.split('_').map(&:capitalize).join('').constantize
end
type_to_dir(type) click to toggle source
# File lib/cache_driver/cache_util.rb, line 48
def type_to_dir(type)
  type.to_s + 's'
end
write(type, key, data) click to toggle source
# File lib/cache_driver/cache_util.rb, line 4
def write(type, key, data)
  if CacheDriver.logger
    CacheDriver.logger.debug "[CACHE] save #{type} ##{key} to cache"
  else
    puts "[CACHE] save #{type} ##{key} to cache"
  end
end