Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
wattsworth
/
lumen-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
65a0409f
authored
Jul 10, 2016
by
John Doe
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
handles empty folders
parent
f81d61a3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
5 deletions
app/services/db/update_db.rb
spec/services/db/update_db_spec.rb
app/services/db/update_db.rb
View file @
65a0409f
...
...
@@ -44,10 +44,10 @@ class UpdateDb # rubocop:disable Metrics/ClassLength
# Creates or updates the folder defined by these entries.
# Then adds in any subfolders or subfiles
def
__parse_folder_entries
(
parent
:,
entries
:,
default_name:
''
)
# find the info stream entry if it exists
info
=
__read_info_entry
(
entries
)
||
{
name:
default_name
}
# generate the folder path
path
=
__build_path
(
entries
)
# find the info stream entry if it exists
info
=
__read_info_entry
(
entries
)
||
{
name:
default_name
}
# create or update the folder
folder
=
__build_folder
(
parent:
parent
,
path:
path
,
info:
info
)
# group the folder entries
...
...
@@ -87,7 +87,6 @@ class UpdateDb # rubocop:disable Metrics/ClassLength
return
@root_folder
if
parent
.
nil?
folder
=
parent
.
subfolders
.
find_by_path
(
path
)
folder
||=
DbFolder
.
new
(
parent:
parent
,
path:
path
)
byebug
folder
.
update_attributes
(
info
.
slice
(
*
folder
.
defined_attributes
))
folder
.
save!
...
...
@@ -140,6 +139,14 @@ class UpdateDb # rubocop:disable Metrics/ClassLength
# determine if the entry groups constitute a single file
def
file?
(
entry_group
)
# if any entry_group has multiple chunks left or if the
# last chunk is 'info', this is a folder
folder_entries
=
entry_group
.
select
{
|
entry
|
entry
[
:chunks
].
length
>
1
||
entry
[
:chunks
][
0
]
==
'info'
}.
count
if
(
folder_entries
>
0
)
return
false
end
# if the path's are the same up to a ~decimXX suffix
# this is a file, otherwise return false
num_files
=
entry_group
.
map
{
|
entry
|
...
...
spec/services/db/update_db_spec.rb
View file @
65a0409f
...
...
@@ -102,8 +102,22 @@ describe 'UpdateDb' do
folder1
=
@root
.
subfolders
[
0
]
expect
(
folder1
.
name
).
to
eq
(
'first'
)
end
it
'from base file'
it
'from decimations'
it
'from base file'
do
schema
=
Array
.
new
(
simple_db
)
schema
<<
helper
.
entry
(
'/folder1/f1_meta'
,
metadata:
{
name:
'custom'
})
update_with_schema
(
schema
)
folder1
=
@root
.
subfolders
[
0
]
expect
(
folder1
.
db_files
.
find_by_name
(
'custom'
)).
to
be_present
end
end
# corner cases
describe
'cornercases:'
do
it
'handles empty folders'
do
schema
=
[
helper
.
entry
(
'/folder_lonley/info'
,
metadata:
{
name:
'lonely'
})]
update_with_schema
(
schema
)
expect
(
@root
.
subfolders
.
find_by_name
(
'lonely'
)).
to
be_present
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