Module: SafeMemoize
- Defined in:
- lib/safe_memoize.rb,
lib/safe_memoize/version.rb,
lib/safe_memoize/release_tooling.rb
Defined Under Namespace
Modules: ClassMethods, ReleaseTooling
Classes: Error
Constant Summary
collapse
- VERSION =
"0.1.2"
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.prepended(base) ⇒ Object
8
9
10
|
# File 'lib/safe_memoize.rb', line 8
def self.prepended(base)
base.extend(ClassMethods)
end
|
Instance Method Details
#memo_count(*method_name) ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/safe_memoize.rb', line 56
def memo_count(*method_name)
scoped_method = safe_memo_scoped_method(method_name)
with_memo_lock do
safe_memo_count_for(scoped_method)
end
end
|
#memo_keys(*method_name) ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/safe_memoize.rb', line 64
def memo_keys(*method_name)
scoped_method = safe_memo_scoped_method(method_name)
with_memo_lock do
safe_memo_keys_for(scoped_method)
end
end
|
#memo_values(*method_name) ⇒ Object
72
73
74
75
76
77
78
|
# File 'lib/safe_memoize.rb', line 72
def memo_values(*method_name)
scoped_method = safe_memo_scoped_method(method_name)
with_memo_lock do
safe_memo_values_for(scoped_method)
end
end
|
#memoized?(method_name, *args, **kwargs, &block) ⇒ Boolean
46
47
48
49
50
51
52
53
54
|
# File 'lib/safe_memoize.rb', line 46
def memoized?(method_name, *args, **kwargs, &block)
return false if block
cache_key = safe_memo_cache_key(method_name, args, kwargs)
with_memo_lock do
with_memo_cache { |cache| cache.key?(cache_key) } || false
end
end
|
#reset_all_memos ⇒ Object
92
93
94
95
96
|
# File 'lib/safe_memoize.rb', line 92
def reset_all_memos
with_memo_lock do
@__safe_memo_cache__ = {}
end
end
|
#reset_memo(method_name, *args, **kwargs) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/safe_memoize.rb', line 80
def reset_memo(method_name, *args, **kwargs)
method_name = method_name.to_sym
matcher = memo_matcher_for(method_name, args, kwargs)
with_memo_lock do
with_memo_cache do |cache|
cache.delete_if { |key, _| matcher.call(key) }
end
end
end
|