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
Léo-Paul Géneau
gitlab-ce
Commits
7ff2a51e
Commit
7ff2a51e
authored
May 09, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more refactoring to import export reader
parent
3f87387b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
31 deletions
+34
-31
lib/gitlab/import_export/attributes_finder.rb
lib/gitlab/import_export/attributes_finder.rb
+7
-2
lib/gitlab/import_export/import_export_reader.rb
lib/gitlab/import_export/import_export_reader.rb
+27
-29
No files found.
lib/gitlab/import_export/attributes_finder.rb
View file @
7ff2a51e
...
@@ -11,8 +11,9 @@ module Gitlab
...
@@ -11,8 +11,9 @@ module Gitlab
parsed_hash
.
empty?
?
model_object
:
{
model_object
=>
parsed_hash
}
parsed_hash
.
empty?
?
model_object
:
{
model_object
=>
parsed_hash
}
end
end
def
find_attributes_only
(
value
)
def
parse
(
model_object
)
find_included
(
value
).
merge
(
find_excluded
(
value
))
parsed_hash
=
find_attributes_only
(
model_object
)
yield
parsed_hash
unless
parsed_hash
.
empty?
end
end
def
find_included
(
value
)
def
find_included
(
value
)
...
@@ -27,6 +28,10 @@ module Gitlab
...
@@ -27,6 +28,10 @@ module Gitlab
private
private
def
find_attributes_only
(
value
)
find_included
(
value
).
merge
(
find_excluded
(
value
))
end
def
key_from_hash
(
value
)
def
key_from_hash
(
value
)
value
.
is_a?
(
Hash
)
?
value
.
keys
.
first
:
value
value
.
is_a?
(
Hash
)
?
value
.
keys
.
first
:
value
end
end
...
...
lib/gitlab/import_export/import_export_reader.rb
View file @
7ff2a51e
module
Gitlab
module
Gitlab
module
ImportExport
module
ImportExport
class
ImportExportReader
class
ImportExportReader
#FIXME
def
initialize
(
config:
'lib/gitlab/import_export/import_export.yml'
)
def
initialize
(
config:
'lib/gitlab/import_export/import_export.yml'
)
config_hash
=
YAML
.
load_file
(
config
).
with_indifferent_access
config_hash
=
YAML
.
load_file
(
config
).
with_indifferent_access
@tree
=
config_hash
[
:project_tree
]
@tree
=
config_hash
[
:project_tree
]
@attributes_parser
=
Gitlab
::
ImportExport
::
AttributesFinder
.
new
(
included_attributes:
config_hash
[
:included_attributes
],
@attributes_parser
=
Gitlab
::
ImportExport
::
AttributesFinder
.
new
(
included_attributes:
config_hash
[
:included_attributes
],
excluded_attributes:
config_hash
[
:excluded_attributes
])
excluded_attributes:
config_hash
[
:excluded_attributes
])
@json_config_hash
=
{}
end
end
def
project_tree
def
project_tree
...
@@ -19,51 +19,49 @@ module Gitlab
...
@@ -19,51 +19,49 @@ module Gitlab
def
build_hash
(
model_list
)
def
build_hash
(
model_list
)
model_list
.
map
do
|
model_object_hash
|
model_list
.
map
do
|
model_object_hash
|
if
model_object_hash
.
is_a?
(
Hash
)
if
model_object_hash
.
is_a?
(
Hash
)
process_model_object
(
model_object_hash
)
build_json_config_hash
(
model_object_hash
)
else
else
@attributes_parser
.
find
(
model_object_hash
)
@attributes_parser
.
find
(
model_object_hash
)
end
end
end
end
end
end
def
process_model_object
(
model_object_hash
,
included_classes_hash
=
{}
)
def
build_json_config_hash
(
model_object_hash
)
model_object_hash
.
values
.
flatten
.
each
do
|
model_object
|
model_object_hash
.
values
.
flatten
.
each
do
|
model_object
|
current_key
=
model_object_hash
.
keys
.
first
current_key
=
model_object_hash
.
keys
.
first
model_object
=
process_current_class
(
model_object_hash
,
included_classes_hash
,
model_object
)
if
included_classes_hash
[
current_key
]
@attributes_parser
.
parse
(
current_key
)
{
|
hash
|
@json_config_hash
[
current_key
]
||=
hash
}
add_to_class
(
current_key
,
included_classes_hash
,
model_object
)
else
handle_model_object
(
current_key
,
model_object
)
add_new_class
(
current_key
,
included_classes_hash
,
model_object
)
end
end
end
included_classes
_hash
@json_config
_hash
end
end
def
process_current_class
(
hash
,
included_classes_hash
,
value
)
def
handle_model_object
(
current_key
,
model_object
)
value
=
value
.
is_a?
(
Hash
)
?
process_model_object
(
hash
,
included_classes_hash
)
:
value
if
@json_config_hash
[
current_key
]
attributes_hash
=
@attributes_parser
.
find_attributes_only
(
hash
.
keys
.
first
)
add_model_value
(
current_key
,
model_object
)
included_classes_hash
[
hash
.
keys
.
first
]
||=
attributes_hash
unless
attributes_hash
.
empty?
else
value
create_model_value
(
current_key
,
model_object
)
end
end
end
def
add_new_class
(
current_key
,
included_classes_hash
,
value
)
def
create_model_value
(
current_key
,
value
)
attributes_hash
=
@attributes_parser
.
find_attributes_only
(
value
)
parsed_hash
=
{
include:
value
}
parsed_hash
=
{
include:
value
}
unless
attributes_hash
.
empty?
if
value
.
is_a?
(
Hash
)
@attributes_parser
.
parse
(
value
)
do
|
hash
|
parsed_hash
=
{
include:
value
.
merge
(
attributes_hash
)
}
parsed_hash
=
{
include:
hash_or_merge
(
value
,
hash
)
}
else
parsed_hash
=
{
include:
{
value
=>
attributes_hash
}
}
end
end
@json_config_hash
[
current_key
]
=
parsed_hash
end
end
included_classes_hash
[
current_key
]
=
parsed_hash
def
add_model_value
(
current_key
,
value
)
@attributes_parser
.
parse
(
value
)
{
|
hash
|
value
=
{
value
=>
hash
}
}
old_values
=
@json_config_hash
[
current_key
][
:include
]
@json_config_hash
[
current_key
][
:include
]
=
([
old_values
]
+
[
value
]).
compact
.
flatten
end
end
def
add_to_class
(
current_key
,
included_classes_hash
,
value
)
def
hash_or_merge
(
value
,
hash
)
attributes_hash
=
@attributes_parser
.
find_attributes_only
(
value
)
value
.
is_a?
(
Hash
)
?
value
.
merge
(
hash
)
:
hash
value
=
{
value
=>
attributes_hash
}
unless
attributes_hash
.
empty?
old_values
=
included_classes_hash
[
current_key
][
:include
]
included_classes_hash
[
current_key
][
:include
]
=
([
old_values
]
+
[
value
]).
compact
.
flatten
end
end
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