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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
539bdf73
Commit
539bdf73
authored
Mar 14, 2018
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address review comments.
parent
d9a953c8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
17 deletions
+15
-17
app/models/concerns/atomic_internal_id.rb
app/models/concerns/atomic_internal_id.rb
+12
-15
app/models/internal_id.rb
app/models/internal_id.rb
+3
-2
No files found.
app/models/concerns/atomic_internal_id.rb
View file @
539bdf73
...
@@ -24,17 +24,15 @@
...
@@ -24,17 +24,15 @@
module
AtomicInternalId
module
AtomicInternalId
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
included
do
module
ClassMethods
class
<<
self
def
has_internal_id
(
on
,
scope
:,
usage:
nil
,
init
:)
# rubocop:disable Naming/PredicateName
def
has_internal_id
(
on
,
scope
:,
usage:
nil
,
init
:)
# rubocop:disable Naming/PredicateName
before_validation
(
on: :create
)
do
before_validation
(
on: :create
)
do
if
self
.
public_send
(
on
).
blank?
# rubocop:disable GitlabSecurity/PublicSend
if
self
.
public_send
(
on
).
blank?
# rubocop:disable GitlabSecurity/PublicSend
scope_attrs
=
[
scope
].
flatten
.
compact
.
each_with_object
({})
do
|
e
,
h
|
scope_attrs
=
[
scope
].
flatten
.
compact
.
each_with_object
({})
do
|
e
,
h
|
h
[
e
]
=
self
.
public_send
(
e
)
# rubocop:disable GitlabSecurity/PublicSend
h
[
e
]
=
self
.
public_send
(
e
)
# rubocop:disable GitlabSecurity/PublicSend
end
end
usage
=
(
usage
||
self
.
class
.
name
.
tableiz
e
).
to_sym
usage
=
(
usage
||
self
.
class
.
table_nam
e
).
to_sym
new_iid
=
InternalId
.
generate_next
(
self
,
scope_attrs
,
usage
,
init
)
new_iid
=
InternalId
.
generate_next
(
self
,
scope_attrs
,
usage
,
init
)
self
.
public_send
(
"
#{
on
}
="
,
new_iid
)
# rubocop:disable GitlabSecurity/PublicSend
self
.
public_send
(
"
#{
on
}
="
,
new_iid
)
# rubocop:disable GitlabSecurity/PublicSend
end
end
...
@@ -43,7 +41,6 @@ module AtomicInternalId
...
@@ -43,7 +41,6 @@ module AtomicInternalId
validates
on
,
presence:
true
,
numericality:
true
validates
on
,
presence:
true
,
numericality:
true
end
end
end
end
end
def
to_param
def
to_param
iid
.
to_s
iid
.
to_s
...
...
app/models/internal_id.rb
View file @
539bdf73
...
@@ -67,16 +67,17 @@ class InternalId < ActiveRecord::Base
...
@@ -67,16 +67,17 @@ class InternalId < ActiveRecord::Base
# usage: Symbol to define the usage of the internal id, see InternalId.usages
# usage: Symbol to define the usage of the internal id, see InternalId.usages
# init: Block that gets called to initialize InternalId record if not present
# init: Block that gets called to initialize InternalId record if not present
attr_reader
:subject
,
:scope
,
:init
,
:scope_attrs
,
:usage
attr_reader
:subject
,
:scope
,
:init
,
:scope_attrs
,
:usage
def
initialize
(
subject
,
scope
,
usage
,
init
)
def
initialize
(
subject
,
scope
,
usage
,
init
)
@subject
=
subject
@subject
=
subject
@scope
=
scope
@scope
=
scope
@init
=
init
@init
=
init
@usage
=
usage
@usage
=
usage
raise
'scope is not well-defined, need at least one column for scope (given: 0)'
if
scope
.
empty?
raise
ArgumentError
,
'scope is not well-defined, need at least one column for scope (given: 0)'
if
scope
.
empty?
unless
InternalId
.
usages
.
keys
.
include?
(
usage
.
to_s
)
unless
InternalId
.
usages
.
keys
.
include?
(
usage
.
to_s
)
raise
"Usage '
#{
usage
}
' is unknown. Supported values are
#{
InternalId
.
usages
.
keys
}
from InternalId.usages"
raise
ArgumentError
,
"Usage '
#{
usage
}
' is unknown. Supported values are
#{
InternalId
.
usages
.
keys
}
from InternalId.usages"
end
end
end
end
...
...
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