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
ef043063
Commit
ef043063
authored
Oct 02, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up public/private api of `GroupDescendant`
So only methods that are used elsewhere are public.
parent
6c2de364
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
56 deletions
+22
-56
app/models/concerns/group_descendant.rb
app/models/concerns/group_descendant.rb
+22
-24
spec/models/concerns/group_descendant_spec.rb
spec/models/concerns/group_descendant_spec.rb
+0
-32
No files found.
app/models/concerns/group_descendant.rb
View file @
ef043063
...
...
@@ -3,28 +3,6 @@ module GroupDescendant
expand_hierarchy_for_child
(
self
,
self
,
hierarchy_top
,
preloaded
)
end
def
expand_hierarchy_for_child
(
child
,
hierarchy
,
hierarchy_top
,
preloaded
=
[])
parent
=
preloaded
.
detect
{
|
possible_parent
|
possible_parent
.
is_a?
(
Group
)
&&
possible_parent
.
id
==
child
.
parent_id
}
parent
||=
child
.
parent
if
parent
.
nil?
&&
hierarchy_top
.
present?
raise
ArgumentError
.
new
(
'specified base is not part of the tree'
)
end
if
parent
&&
parent
!=
hierarchy_top
expand_hierarchy_for_child
(
parent
,
{
parent
=>
hierarchy
},
hierarchy_top
,
preloaded
)
else
hierarchy
end
end
def
merge_hierarchy
(
other_element
,
hierarchy_top
=
nil
)
GroupDescendant
.
build_hierarchy
([
self
,
other_element
],
hierarchy_top
)
end
def
self
.
build_hierarchy
(
descendants
,
hierarchy_top
=
nil
)
descendants
=
Array
.
wrap
(
descendants
)
return
if
descendants
.
empty?
...
...
@@ -44,7 +22,27 @@ module GroupDescendant
merged
end
def
self
.
merge_hash_tree
(
first_child
,
second_child
)
private
def
expand_hierarchy_for_child
(
child
,
hierarchy
,
hierarchy_top
,
preloaded
=
[])
parent
=
preloaded
.
detect
{
|
possible_parent
|
possible_parent
.
is_a?
(
Group
)
&&
possible_parent
.
id
==
child
.
parent_id
}
parent
||=
child
.
parent
if
parent
.
nil?
&&
hierarchy_top
.
present?
raise
ArgumentError
.
new
(
'specified base is not part of the tree'
)
end
if
parent
&&
parent
!=
hierarchy_top
expand_hierarchy_for_child
(
parent
,
{
parent
=>
hierarchy
},
hierarchy_top
,
preloaded
)
else
hierarchy
end
end
private_class_method
def
self
.
merge_hash_tree
(
first_child
,
second_child
)
# When the first is an array, we need to go over every element to see if
# we can merge deeper. If no match is found, we add the element to the array
#
...
...
@@ -79,7 +77,7 @@ module GroupDescendant
end
end
def
self
.
merge_hash_into_array
(
array
,
new_hash
)
private_class_method
def
self
.
merge_hash_into_array
(
array
,
new_hash
)
if
mergeable_index
=
array
.
index
{
|
element
|
element
.
is_a?
(
Hash
)
&&
(
element
.
keys
&
new_hash
.
keys
).
any?
}
array
[
mergeable_index
]
=
merge_hash_tree
(
array
[
mergeable_index
],
new_hash
)
else
...
...
spec/models/concerns/group_descendant_spec.rb
View file @
ef043063
...
...
@@ -24,22 +24,6 @@ describe GroupDescendant, :nested_groups do
end
end
describe
'#parent'
do
it
'returns the correct parent'
do
expect
(
subsub_group
.
parent
).
to
eq
(
subgroup
)
end
end
describe
'#merge_hierarchy'
do
it
'combines hierarchies'
do
other_subgroup
=
create
(
:group
,
parent:
parent
)
expected_hierarchy
=
{
parent
=>
[{
subgroup
=>
subsub_group
},
other_subgroup
]
}
expect
(
subsub_group
.
merge_hierarchy
(
other_subgroup
)).
to
eq
(
expected_hierarchy
)
end
end
describe
'.build_hierarchy'
do
it
'combines hierarchies until the top'
do
other_subgroup
=
create
(
:group
,
parent:
parent
)
...
...
@@ -97,22 +81,6 @@ describe GroupDescendant, :nested_groups do
end
end
describe
'#parent'
do
it
'returns the correct parent'
do
expect
(
project
.
parent
).
to
eq
(
subsub_group
)
end
end
describe
'#merge_hierarchy'
do
it
'combines hierarchies'
do
project
=
create
(
:project
,
namespace:
parent
)
expected_hierarchy
=
{
parent
=>
[{
subgroup
=>
subsub_group
},
project
]
}
expect
(
subsub_group
.
merge_hierarchy
(
project
)).
to
eq
(
expected_hierarchy
)
end
end
describe
'.build_hierarchy'
do
it
'combines hierarchies until the top'
do
other_project
=
create
(
:project
,
namespace:
parent
)
...
...
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