Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
6ce21a9c
Commit
6ce21a9c
authored
Sep 04, 2019
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a predicate to check for strong memoization
parent
96a9a140
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
1 deletion
+21
-1
lib/gitlab/utils/strong_memoize.rb
lib/gitlab/utils/strong_memoize.rb
+5
-1
spec/lib/gitlab/utils/strong_memoize_spec.rb
spec/lib/gitlab/utils/strong_memoize_spec.rb
+16
-0
No files found.
lib/gitlab/utils/strong_memoize.rb
View file @
6ce21a9c
...
...
@@ -24,13 +24,17 @@ module Gitlab
# end
#
def
strong_memoize
(
name
)
if
instance_variable_defined?
(
ivar
(
name
)
)
if
strong_memoized?
(
name
)
instance_variable_get
(
ivar
(
name
))
else
instance_variable_set
(
ivar
(
name
),
yield
)
end
end
def
strong_memoized?
(
name
)
instance_variable_defined?
(
ivar
(
name
))
end
def
clear_memoization
(
name
)
remove_instance_variable
(
ivar
(
name
))
if
instance_variable_defined?
(
ivar
(
name
))
end
...
...
spec/lib/gitlab/utils/strong_memoize_spec.rb
View file @
6ce21a9c
...
...
@@ -52,6 +52,22 @@ describe Gitlab::Utils::StrongMemoize do
end
end
describe
'#strong_memoized?'
do
let
(
:value
)
{
:anything
}
subject
{
object
.
strong_memoized?
(
:method_name
)
}
it
'returns false if the value is uncached'
do
is_expected
.
to
be
(
false
)
end
it
'returns true if the value is cached'
do
object
.
method_name
is_expected
.
to
be
(
true
)
end
end
describe
'#clear_memoization'
do
let
(
:value
)
{
'mepmep'
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment