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
Tatuya Kamada
gitlab-ce
Commits
8ac53eb5
Commit
8ac53eb5
authored
May 06, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
started refactoring import export reader - WIP
parent
b6ab4a31
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
52 deletions
+57
-52
lib/gitlab/import_export.rb
lib/gitlab/import_export.rb
+1
-1
lib/gitlab/import_export/attributes_finder.rb
lib/gitlab/import_export/attributes_finder.rb
+35
-0
lib/gitlab/import_export/import_export_reader.rb
lib/gitlab/import_export/import_export_reader.rb
+20
-48
spec/lib/gitlab/import_export/import_export_reader_spec.rb
spec/lib/gitlab/import_export/import_export_reader_spec.rb
+1
-3
No files found.
lib/gitlab/import_export.rb
View file @
8ac53eb5
...
...
@@ -11,7 +11,7 @@ module Gitlab
end
def
project_tree
Gitlab
::
ImportExport
::
ImportExportReader
.
project_tree
Gitlab
::
ImportExport
::
ImportExportReader
.
new
.
project_tree
end
def
storage_path
...
...
lib/gitlab/import_export/attributes_finder.rb
0 → 100644
View file @
8ac53eb5
module
Gitlab
module
ImportExport
class
AttributesFinder
def
initialize
(
included_attributes
:,
excluded_attributes
:)
@included_attributes
=
included_attributes
||
{}
@excluded_attributes
=
excluded_attributes
||
{}
end
def
find
(
model_object
)
parsed_hash
=
find_attributes_only
(
model_object
)
parsed_hash
.
empty?
?
model_object
:
{
model_object
=>
parsed_hash
}
end
def
find_attributes_only
(
value
)
find_included
(
value
).
merge
(
find_excluded
(
value
))
end
def
find_included
(
value
)
key
=
key_from_hash
(
value
)
@included_attributes
[
key
].
nil?
?
{}
:
{
only:
@included_attributes
[
key
]
}
end
def
find_excluded
(
value
)
key
=
key_from_hash
(
value
)
@excluded_attributes
[
key
].
nil?
?
{}
:
{
except:
@excluded_attributes
[
key
]
}
end
private
def
key_from_hash
(
value
)
value
.
is_a?
(
Hash
)
?
value
.
keys
.
first
:
value
end
end
end
end
\ No newline at end of file
lib/gitlab/import_export/import_export_reader.rb
View file @
8ac53eb5
module
Gitlab
module
ImportExport
module
ImportExportReader
extend
self
class
ImportExportReader
#FIXME
def
project_tree
{
only:
included_attributes
[
:project
],
include:
build_hash
(
tree
)
}
def
initialize
(
config:
'lib/gitlab/import_export/import_export.yml'
)
config
=
YAML
.
load_file
(
'lib/gitlab/import_export/import_export.yml'
).
with_indifferent_access
@tree
=
config
[
:project_tree
]
@attributes_parser
=
Gitlab
::
ImportExport
::
AttributesFinder
.
new
(
included_attributes:
config
[
:included_attributes
],
excluded_attributes:
config
[
:excluded_attributes
])
end
def
tree
config
[
:project_tree
]
def
project_
tree
{
only:
@attributes_parser
.
find_included
(
:project
),
include:
build_hash
(
@tree
)
}
end
private
def
config
@config
||=
YAML
.
load_file
(
'lib/gitlab/import_export/import_export.yml'
).
with_indifferent_access
end
def
included_attributes
config
[
:included_attributes
]
||
{}
end
def
excluded_attributes
config
[
:excluded_attributes
]
||
{}
end
def
build_hash
(
array
)
array
.
map
do
|
model_object
|
def
build_hash
(
model_list
)
model_list
.
map
do
|
model_object
|
if
model_object
.
is_a?
(
Hash
)
process_include
(
model_object
)
else
only_except_hash
=
check_only_and_except
(
model_object
)
only_except_hash
.
empty?
?
model_object
:
{
model_object
=>
only_except_hash
}
@attributes_parser
.
find
(
model_object
)
end
end
end
...
...
@@ -51,48 +41,30 @@ module Gitlab
def
process_current_class
(
hash
,
included_classes_hash
,
value
)
value
=
value
.
is_a?
(
Hash
)
?
process_include
(
hash
,
included_classes_hash
)
:
value
only_except_hash
=
check_only_and_except
(
hash
.
keys
.
first
)
included_classes_hash
[
hash
.
keys
.
first
]
||=
only_except_hash
unless
only_except
_hash
.
empty?
attributes_hash
=
@attributes_parser
.
find_attributes_only
(
hash
.
keys
.
first
)
included_classes_hash
[
hash
.
keys
.
first
]
||=
attributes_hash
unless
attributes
_hash
.
empty?
value
end
def
add_new_class
(
current_key
,
included_classes_hash
,
value
)
only_except_hash
=
check_only_and_except
(
value
)
attributes_hash
=
@attributes_parser
.
find_attributes_only
(
value
)
parsed_hash
=
{
include:
value
}
unless
only_except
_hash
.
empty?
unless
attributes
_hash
.
empty?
if
value
.
is_a?
(
Hash
)
parsed_hash
=
{
include:
value
.
merge
(
only_except
_hash
)
}
parsed_hash
=
{
include:
value
.
merge
(
attributes
_hash
)
}
else
parsed_hash
=
{
include:
{
value
=>
only_except
_hash
}
}
parsed_hash
=
{
include:
{
value
=>
attributes
_hash
}
}
end
end
included_classes_hash
[
current_key
]
=
parsed_hash
end
def
add_to_class
(
current_key
,
included_classes_hash
,
value
)
only_except_hash
=
check_only_and_except
(
value
)
value
=
{
value
=>
only_except_hash
}
unless
only_except
_hash
.
empty?
attributes_hash
=
@attributes_parser
.
find_attributes_only
(
value
)
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
def
check_only_and_except
(
value
)
check_only
(
value
).
merge
(
check_except
(
value
))
end
def
check_only
(
value
)
key
=
key_from_hash
(
value
)
included_attributes
[
key
].
nil?
?
{}
:
{
only:
included_attributes
[
key
]
}
end
def
check_except
(
value
)
key
=
key_from_hash
(
value
)
excluded_attributes
[
key
].
nil?
?
{}
:
{
except:
excluded_attributes
[
key
]
}
end
def
key_from_hash
(
value
)
value
.
is_a?
(
Hash
)
?
value
.
keys
.
first
:
value
end
end
end
end
spec/lib/gitlab/import_export/import_export_reader_spec.rb
View file @
8ac53eb5
...
...
@@ -17,8 +17,6 @@ describe Gitlab::ImportExport::ImportExportReader do
end
it
'should generate hash from project tree config'
do
allow
(
described_class
).
to
receive
(
:config
).
and_return
(
YAML
.
load_file
(
test_config
).
deep_symbolize_keys
)
expect
(
described_class
.
project_tree
).
to
eq
(
project_tree_hash
)
expect
(
described_class
.
new
(
config:
test_config
).
project_tree
).
to
eq
(
project_tree_hash
)
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