class Ruhoh::Cache

Public Class Methods

new(ruhoh) click to toggle source
# File lib/ruhoh/cache.rb, line 3
def initialize(ruhoh)
  @__cache = {}
end

Public Instance Methods

__cache() click to toggle source
# File lib/ruhoh/cache.rb, line 7
def __cache
  @__cache
end
delete(key) click to toggle source
# File lib/ruhoh/cache.rb, line 27
def delete(key)
  @__cache.delete(tokenize(key))
end
get(key) click to toggle source
# File lib/ruhoh/cache.rb, line 18
def get(key)
  key = tokenize(key)
  return nil unless key

  if @__cache[key]
    @__cache[key]
  end
end
set(key, data) click to toggle source
# File lib/ruhoh/cache.rb, line 11
def set(key, data)
  key = tokenize(key)
  return nil unless key

  @__cache[key] = data
end

Private Instance Methods

tokenize(key) click to toggle source
# File lib/ruhoh/cache.rb, line 33
def tokenize(key)
  new_key = case key
            when Hash
              key.to_a.sort.to_s.strip
            when Array
              key.sort.to_s.strip
            else
              key.to_s.strip
            end

  new_key.empty? ? nil : new_key
end