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
9ae9c64b
authored
May 24, 2016
by
John
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
refactored, still have long UpdateDb class
parent
80f7dbf8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
25 deletions
app/services/db/update_db.rb
app/services/db/update_db.rb
View file @
9ae9c64b
...
@@ -119,31 +119,32 @@ class UpdateDb
...
@@ -119,31 +119,32 @@ class UpdateDb
# convert the groups into subfolders and files
# convert the groups into subfolders and files
def
__process_folder_contents
(
folder
,
groups
)
def
__process_folder_contents
(
folder
,
groups
)
groups
.
each
do
|
name
,
entry_group
|
groups
.
each
do
|
name
,
entry_group
|
# if all paths in the entry group are the same up to a ~decim
# check if this entry group is a file
# then this is a file
if
__file_entry_group?
entry_group
base_paths
=
entry_group
.
map
do
|
entry
|
entry
[
:path
].
gsub
(
decimation_tag
,
''
)
end
if
base_paths
.
uniq
.
count
==
1
__build_file
(
folder:
folder
,
entries:
entry_group
,
default_name:
name
)
__build_file
(
folder:
folder
,
entries:
entry_group
,
default_name:
name
)
# otherwise this is a subfolder
# otherwise this is a subfolder
els
if
entry_group
.
length
>
1
els
e
__parse_folder_entries
(
parent:
folder
,
entries:
entry_group
,
__parse_folder_entries
(
parent:
folder
,
entries:
entry_group
,
default_name:
name
)
default_name:
name
)
end
end
end
end
end
end
# return true if this entry_group corresponds to a single file
def
__file_entry_group?
(
entry_group
)
# strip decim tag to form base paths
base_paths
=
entry_group
.
map
do
|
entry
|
entry
[
:path
].
gsub
(
decimation_tag
,
''
)
end
# there is only one base path (this is a file)
base_paths
.
uniq
.
count
==
1
end
# create or update a DbFile object at the
# create or update a DbFile object at the
# specified path.
# specified path.
def
__build_file
(
folder
:,
entries
:,
default_name
:)
def
__build_file
(
folder
:,
entries
:,
default_name
:)
# find the base file entry
base_entry
=
__get_base_entry
(
entries
)
base_entry
=
entries
.
select
{
|
entry
|
!
entry
[
:path
].
match
(
decimation_tag
)
}
return
unless
base_entry
# corrupt file, don't process
unless
base_entry
.
count
==
1
warnings
<<
"Missing base stream for
#{
default_name
}
in
#{
folder
.
name
}
"
return
end
base_entry
=
base_entry
.
first
# find or create the DbFile object
# find or create the DbFile object
file
=
folder
.
db_files
.
find_by_path
(
base_entry
[
:path
])
file
=
folder
.
db_files
.
find_by_path
(
base_entry
[
:path
])
file
||=
DbFile
.
new
(
db_folder:
folder
,
path:
base_entry
[
:path
])
file
||=
DbFile
.
new
(
db_folder:
folder
,
path:
base_entry
[
:path
])
...
@@ -152,20 +153,35 @@ class UpdateDb
...
@@ -152,20 +153,35 @@ class UpdateDb
file
.
update_attributes
(
info
.
merge
(
base_entry
[
:attributes
]))
file
.
update_attributes
(
info
.
merge
(
base_entry
[
:attributes
]))
file
.
save!
file
.
save!
# add the decimations
# add the decimations
decim_entries
=
entries
.
select
do
|
entry
|
__process_decimations
(
file:
file
,
entries:
entries
)
entry
[
:path
].
match
(
decimation_tag
)
end
# return the base file entry in an entry group
# adds a warning and returns nil if base entry is missing
def
__get_base_entry
(
entries
)
# find the base file entry
base_entry
=
entries
.
select
{
|
entry
|
!
entry
[
:path
].
match
(
decimation_tag
)
}
unless
base_entry
.
count
==
1
warnings
<<
"Missing base stream for
#{
default_name
}
in
#{
folder
.
name
}
"
return
nil
end
end
__build_decimations
(
file:
file
,
entries:
decim_entries
)
base_entry
.
first
end
end
# create or update DbDecimation objects for a DbFile
# go through all decimation entries and build a DbDecimation
def
__build_decimations
(
file
:,
entries
:)
def
__process_decimations
(
file
:,
entries
:)
entries
.
each
do
|
entry
|
decim_entries
=
entries
.
select
{
|
e
|
e
[
:path
].
match
(
decimation_tag
)
}
level
=
entry
[
:path
].
match
(
decimation_tag
)[
1
].
to_i
decim_entries
.
each
do
|
entry
|
decim
=
file
.
db_decimations
.
find_by_level
(
level
)
__build_decimation
(
file:
file
,
entry:
entry
)
decim
||=
DbDecimation
.
new
(
db_file:
file
,
level:
level
)
decim
.
update_attributes
(
entry
[
:attributes
])
decim
.
save!
end
end
end
end
# create or update DbDecimation object
def
__build_decimation
(
file
:,
entry
:)
level
=
entry
[
:path
].
match
(
decimation_tag
)[
1
].
to_i
decim
=
file
.
db_decimations
.
find_by_level
(
level
)
decim
||=
DbDecimation
.
new
(
db_file:
file
,
level:
level
)
decim
.
update_attributes
(
entry
[
:attributes
])
decim
.
save!
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