module Memist::InstanceMethods

Public Instance Methods

flush_memoization(method = nil, arg = nil) click to toggle source
# File lib/memist/instance_methods.rb, line 3
def flush_memoization(method = nil, arg = nil)
  return if @memoized_values.nil?

  if method && @memoized_values.key?(method.to_sym)
    flush_memoization_dependencies(method, arg)
    if arg.nil?
      @memoized_values.delete(method.to_sym)
    else
      @memoized_values[method.to_sym].delete(arg)
    end
  elsif method.nil?
    @memoized_values = nil
  end
end
flush_memoization_dependencies(method, arg = nil) click to toggle source
# File lib/memist/instance_methods.rb, line 18
def flush_memoization_dependencies(method, arg = nil)
  deps = self.class.memoization_dependencies[method.to_sym]
  return false if deps.nil? || deps.empty?

  deps.each do |dep|
    flush_memoization(dep, arg)
  end
end
memoize?() click to toggle source
# File lib/memist/instance_methods.rb, line 39
def memoize?
  Thread.current[:without_memoization].nil? ||
  Thread.current[:without_memoization] <= 0
end
memoized?(method) click to toggle source
# File lib/memist/instance_methods.rb, line 27
def memoized?(method)
  !!(@memoized_values && @memoized_values.include?(method.to_sym))
end
without_memoization() { || ... } click to toggle source
# File lib/memist/instance_methods.rb, line 31
def without_memoization
  Thread.current[:without_memoization] ||= 0
  Thread.current[:without_memoization] += 1
  yield
ensure
  Thread.current[:without_memoization] -= 1
end