class ActiveMemoize::Instance
Public Class Methods
new()
click to toggle source
# File lib/active_memoize/instance.rb, line 9 def initialize; end
Public Instance Methods
[](key)
click to toggle source
# File lib/active_memoize/instance.rb, line 11 def [](key) cache[key] end
[]=(key, val)
click to toggle source
# File lib/active_memoize/instance.rb, line 15 def []=(key, val) cache[key] = val end
clear()
click to toggle source
# File lib/active_memoize/instance.rb, line 19 def clear cache.clear end
delete(key)
click to toggle source
# File lib/active_memoize/instance.rb, line 23 def delete(key) cache.delete(key) end
each() { |key, val| ... }
click to toggle source
:nocov:
# File lib/active_memoize/instance.rb, line 28 def each cache.each { |key, val| yield(key, val) } end
empty?()
click to toggle source
:nocov:
# File lib/active_memoize/instance.rb, line 33 def empty? cache.empty? end
Also aliased as: blank?
key?(key)
click to toggle source
# File lib/active_memoize/instance.rb, line 39 def key?(key) cache.key?(key) end
Also aliased as: hit?
keys()
click to toggle source
# File lib/active_memoize/instance.rb, line 45 def keys cache.keys end
memoize(as: nil, refresh: false) { |block| ... }
click to toggle source
# File lib/active_memoize/instance.rb, line 53 def memoize(as: nil, refresh: false, &block) key = key(as || caller_method, caller_locals(block)) return cache[key] if !refresh && cache.key?(key) cache[key] = yield(block) end
merge!(hash)
click to toggle source
# File lib/active_memoize/instance.rb, line 49 def merge!(hash) cache.merge!(hash) end
present?()
click to toggle source
# File lib/active_memoize/instance.rb, line 60 def present? !blank? end
Also aliased as: hits?
size()
click to toggle source
# File lib/active_memoize/instance.rb, line 66 def size cache.size end
to_hash()
click to toggle source
# File lib/active_memoize/instance.rb, line 70 def to_hash cache end
values()
click to toggle source
# File lib/active_memoize/instance.rb, line 77 def values cache.values end
Private Instance Methods
caller_locals(block)
click to toggle source
# File lib/active_memoize/instance.rb, line 83 def caller_locals(block) local_vars = block.binding.local_variables local_vars.flat_map { |name| [name, block.binding.local_variable_get(name)] } end
caller_method()
click to toggle source
# File lib/active_memoize/instance.rb, line 88 def caller_method val = caller(2..2).first[CALLER_METHOD_REGEX, 1] return val unless val.include?('<top (required)>') caller(1..1).first[CALLER_METHOD_REGEX, 1] end