Module: Memist::InstanceMethods
- Defined in:
- lib/memist/instance_methods.rb
Instance Method Summary collapse
- #flush_memoization(method = nil, arg = nil) ⇒ Object
- #flush_memoization_dependencies(method, arg = nil) ⇒ Object
- #memoize? ⇒ Boolean
- #memoized?(method) ⇒ Boolean
- #without_memoization ⇒ Object
Instance Method Details
#flush_memoization(method = nil, arg = nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# 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) ⇒ Object
18 19 20 21 22 23 24 25 |
# 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? ⇒ Boolean
39 40 41 42 |
# File 'lib/memist/instance_methods.rb', line 39 def memoize? Thread.current[:without_memoization].nil? || Thread.current[:without_memoization] <= 0 end |
#memoized?(method) ⇒ Boolean
27 28 29 |
# File 'lib/memist/instance_methods.rb', line 27 def memoized?(method) !!(@memoized_values && @memoized_values.include?(method.to_sym)) end |
#without_memoization ⇒ Object
31 32 33 34 35 36 37 |
# 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 |