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
f56b2319
authored
May 21, 2016
by
John Doe
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
build file names from metadata
parent
60ff3dd1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
24 deletions
app/builders/db_builder.rb
spec/builders/db_builder_spec.rb
app/builders/db_builder.rb
View file @
f56b2319
...
...
@@ -108,12 +108,10 @@ class DbBuilder
def
__process_folder_contents
(
folder
,
groups
)
groups
.
each
do
|
name
,
entry_group
|
if
entry_group
.
length
==
1
folder
.
db_files
<<
__build_file
(
folder:
folder
,
entry:
entry_group
[
0
],
default_name:
name
)
__build_file
(
folder:
folder
,
entry:
entry_group
[
0
],
default_name:
name
)
elsif
entry_group
.
length
>
1
folder
.
subfolders
<<
__parse_folder_entries
(
parent:
folder
,
entries:
entry_group
,
default_name:
name
)
__parse_folder_entries
(
parent:
folder
,
entries:
entry_group
,
default_name:
name
)
end
end
end
...
...
@@ -122,7 +120,9 @@ class DbBuilder
# specified path.
def
__build_file
(
folder
:,
entry
:,
default_name
:)
file
=
folder
.
db_files
.
find_by_path
(
entry
[
:path
])
file
||=
DbFile
.
new
(
name:
default_name
)
file
||=
DbFile
.
new
(
db_folder:
folder
,
path:
entry
[
:path
])
info
=
{
name:
default_name
}.
merge
(
entry
[
:metadata
])
file
.
update_attributes
(
info
)
file
.
save!
file
end
...
...
spec/builders/db_builder_spec.rb
View file @
f56b2319
...
...
@@ -5,30 +5,37 @@ helper = DbSchemaHelper.new
# a simple schema that could be returned
# from DbAdapater.schema
simple_db
=
[
# folder1
helper
.
entry
(
'/folder1/file1_1'
),
# `- file1_1
helper
.
entry
(
'/folder1/file1_2'
),
# - file1_2
helper
.
entry
(
'/folder2/file2_1'
),
# folder2
helper
.
entry
(
'/folder2/file2_2'
),
# '- file2_1
]
# `- file2_2
# folder1
# `- file1_1
# - file1_2
# folder2
# '- file2_1
# `- file2_2
simple_db
=
[
helper
.
entry
(
'/folder1/f1_1'
,
metadata:
{
name:
'file1_1'
}),
helper
.
entry
(
'/folder1/f1_2'
,
metadata:
{
name:
'file1_2'
}),
helper
.
entry
(
'/folder2/f2_1'
,
metadata:
{
name:
'file2_1'
}),
helper
.
entry
(
'/folder2/f2_2'
,
metadata:
{
name:
'file2_2'
})
]
describe
DbBuilder
do
describe
'*update_db*'
do
before
(
:all
)
do
def
update_with_schema
(
schema
)
@db
=
Db
.
new
@db_builder
=
DbBuilder
.
new
(
db:
@db
)
@db_builder
.
update_db
(
schema:
schema
)
@root
=
@db
.
root_folder
end
describe
'given the simple_db schema'
do
before
(
:all
)
do
@db_builder
.
update_db
(
schema:
simple_db
)
@root
=
@db
.
root_folder
end
it
'builds a root folder'
do
update_with_schema
(
simple_db
)
expect
(
@root
.
name
).
to
eq
(
'root'
)
expect
(
@root
.
subfolders
.
count
).
to
eq
(
2
)
expect
(
@root
.
db_files
.
count
).
to
eq
(
0
)
end
it
'builds sub-folder1'
do
update_with_schema
(
simple_db
)
folder1
=
@root
.
subfolders
[
0
]
expect
(
folder1
.
name
).
to
eq
(
'folder1'
)
expect
(
folder1
.
db_files
.
count
).
to
eq
(
2
)
...
...
@@ -36,6 +43,7 @@ describe DbBuilder do
expect
(
folder1
.
db_files
[
1
].
name
).
to
eq
(
'file1_2'
)
end
it
'builds sub-folder2'
do
update_with_schema
(
simple_db
)
folder2
=
@root
.
subfolders
[
1
]
expect
(
folder2
.
name
).
to
eq
(
'folder2'
)
expect
(
folder2
.
db_files
.
count
).
to
eq
(
2
)
...
...
@@ -43,13 +51,18 @@ describe DbBuilder do
expect
(
folder2
.
db_files
[
1
].
name
).
to
eq
(
'file2_2'
)
end
end
describe
'given simple_db schema with folder info streams'
do
before
(
:all
)
do
simple_db
<<
helper
.
entry
(
'/folder1/info'
,
metadata:
{
name:
'first'
})
simple_db
<<
helper
.
entry
(
'/folder2/info'
,
metadata:
{
name:
'second'
})
@db_builder
.
update_db
(
schema:
simple_db
)
end
it
'uses the name info'
it
'uses folder info streams if available'
do
schema
=
Array
.
new
(
simple_db
)
schema
<<
helper
.
entry
(
'/folder1/info'
,
metadata:
{
name:
'first'
})
update_with_schema
(
schema
)
folder1
=
@root
.
subfolders
[
0
]
expect
(
folder1
.
name
).
to
eq
(
'first'
)
end
it
'builds file streams'
do
schema
=
Array
.
new
(
simple_db
)
schema
<<
helper
.
entry
(
'/folder1/info'
,
metadata:
{
name:
'first'
})
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