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
8f4cc359
Commit
8f4cc359
authored
Oct 21, 2019
by
Scott Nevil
Committed by
Russell Dickenson
Oct 21, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update utilities.md
parent
3a23de9d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
17 deletions
+17
-17
doc/development/utilities.md
doc/development/utilities.md
+17
-17
No files found.
doc/development/utilities.md
View file @
8f4cc359
# GitLab utilities
# GitLab utilities
We
developed a number of utilities to ease development.
We
have developed a number of utilities to help ease development:
## `MergeHash`
## `MergeHash`
...
@@ -51,15 +51,15 @@ Refer to: <https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/utils/mer
...
@@ -51,15 +51,15 @@ Refer to: <https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/utils/mer
Refer to
<https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/utils/override.rb>
:
Refer to
<https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/utils/override.rb>
:
-
This utility c
ould help us check if a particular
method would override
-
This utility c
an help you check if one
method would override
another
method or not. It has the same idea of
Java's
`@Override`
annotation
another
or not. It is the same concept as
Java's
`@Override`
annotation
or Scala's
`override`
keyword. However
we
only do this check when
or Scala's
`override`
keyword. However
, you should
only do this check when
`ENV['STATIC_VERIFICATION']`
is set to avoid production runtime overhead.
`ENV['STATIC_VERIFICATION']`
is set to avoid production runtime overhead.
This is useful
to check
:
This is useful
for checking
:
-
If
we
have typos in overriding methods.
-
If
you
have typos in overriding methods.
-
If
we renamed the overridden methods, making original overriding
methods
-
If
you renamed the overridden methods, which make the original override
methods
overrides nothing
.
irrelevant
.
Here's a simple example:
Here's a simple example:
...
@@ -100,11 +100,11 @@ Refer to <https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/utils/stro
...
@@ -100,11 +100,11 @@ Refer to <https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/utils/stro
-
Memoize the value even if it is
`nil`
or
`false`
.
-
Memoize the value even if it is
`nil`
or
`false`
.
We often do
`@value ||= compute`
, however
this doesn't work well if
We often do
`@value ||= compute`
. However,
this doesn't work well if
`compute`
might eventually give
`nil`
and
we
don't want to compute again.
`compute`
might eventually give
`nil`
and
you
don't want to compute again.
Instead
we
could use
`defined?`
to check if the value is set or not.
Instead
you
could use
`defined?`
to check if the value is set or not.
However i
t's tedious to write such pattern, and
`StrongMemoize`
would
I
t's tedious to write such pattern, and
`StrongMemoize`
would
help
us
use such pattern.
help
you
use such pattern.
Instead of writing patterns like this:
Instead of writing patterns like this:
...
@@ -118,7 +118,7 @@ Refer to <https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/utils/stro
...
@@ -118,7 +118,7 @@ Refer to <https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/utils/stro
end
end
```
```
We
could write it like:
You
could write it like:
```
ruby
```
ruby
class
Find
class
Find
...
@@ -151,7 +151,7 @@ and the cache key would be based on the class name, method name,
...
@@ -151,7 +151,7 @@ and the cache key would be based on the class name, method name,
optionally customized instance level values, optionally customized
optionally customized instance level values, optionally customized
method level values, and optional method arguments.
method level values, and optional method arguments.
A simple example that only uses the instance level customised values:
A simple example that only uses the instance level customised values
is
:
```
ruby
```
ruby
class
UserAccess
class
UserAccess
...
@@ -169,8 +169,8 @@ end
...
@@ -169,8 +169,8 @@ end
This way, the result of
`can_push_to_branch?`
would be cached in
This way, the result of
`can_push_to_branch?`
would be cached in
`RequestStore.store`
based on the cache key. If
`RequestStore`
is not
`RequestStore.store`
based on the cache key. If
`RequestStore`
is not
currently active, then it would be stored in a hash saved in an
currently active, then it would be stored in a hash
, and
saved in an
instance variable
,
so the cache logic would be the same.
instance variable so the cache logic would be the same.
We can also set different strategies for different methods:
We can also set different strategies for different methods:
...
...
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