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
0c7b1b41
authored
Jun 25, 2016
by
John Doe
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
can now parse decimations
parent
39a780e6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
14 deletions
.rubocop.yml
app/services/db/update_db.rb
.rubocop.yml
View file @
0c7b1b41
...
@@ -12,4 +12,6 @@ AllCops:
...
@@ -12,4 +12,6 @@ AllCops:
-
'
spec/spec_helper.rb'
-
'
spec/spec_helper.rb'
-
'
spec/rails_helper.rb'
-
'
spec/rails_helper.rb'
-
'
test/test_helper.rb'
-
'
test/test_helper.rb'
-
'
features/support/env.rb'
-
'
features/support/env.rb'
\ No newline at end of file
Style/BlockDelimiters
:
EnforcedStyle
:
braces_for_chaining
\ No newline at end of file
app/services/db/update_db.rb
View file @
0c7b1b41
...
@@ -81,7 +81,7 @@ class UpdateDb
...
@@ -81,7 +81,7 @@ class UpdateDb
folder
folder
end
end
# collect the folder's entries into a set groups
# collect the folder's entries into a set
of
groups
# based off the next item in their :chunk array
# based off the next item in their :chunk array
# returns entry_groups which is a Hash with
# returns entry_groups which is a Hash with
# :key = name of the common chunk
# :key = name of the common chunk
...
@@ -111,26 +111,58 @@ class UpdateDb
...
@@ -111,26 +111,58 @@ 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
|
# TODO
if
file?
(
entry_group
)
# if all paths in the entry group are the same up to a ~decim
__build_file
(
folder:
folder
,
entry_group:
entry_group
,
# then this is a file, otherwise this is a subfolder
default_name:
name
)
if
entry_group
.
length
==
1
else
# its a folder
__build_file
(
folder:
folder
,
entry:
entry_group
[
0
],
default_name:
name
)
elsif
entry_group
.
length
>
1
__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
# determine if the entry groups constitute a single file
def
file?
(
entry_group
)
# 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
|
entry
[
:path
].
gsub
(
/~decim[\d]+$/
,
''
)
}.
uniq
.
count
num_files
==
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
:,
entry
:,
default_name
:)
def
__build_file
(
folder
:,
entry_group
:,
file
=
folder
.
db_files
.
find_by_path
(
entry
[
:path
])
default_name
:)
file
||=
DbFile
.
new
(
db_folder:
folder
,
path:
entry
[
:path
])
base
=
__base_entry
(
entry_group
)
info
=
{
name:
default_name
}.
merge
(
entry
[
:metadata
])
# find or create the file
file
=
folder
.
db_files
.
find_by_path
(
base
[
:path
])
file
||=
DbFile
.
new
(
db_folder:
folder
,
path:
base
[
:path
])
info
=
{
name:
default_name
}.
merge
(
base
[
:metadata
])
file
.
update_attributes
(
info
)
file
.
update_attributes
(
info
)
file
.
save!
file
.
save!
file
__build_decimations
(
file:
file
,
entry_group:
entry_group
-
[
base
])
end
# find the base stream in this entry_group
# this is the stream that doesn't have a decimXX tag
def
__base_entry
(
entry_group
)
entry_group
.
select
{
|
entry
|
entry
[
:path
].
match
(
/~decim[\d]+$/
).
nil?
}.
first
end
# create or update DbDecimations for the
# specified DbFile
def
__build_decimations
(
file
:,
entry_group
:)
entry_group
.
each
do
|
entry
|
level
=
entry
[
:path
].
match
(
/~decim([\d]+)$/
)[
1
].
to_i
decim
=
file
.
db_decimations
.
find_by_level
(
level
)
decim
||=
DbDecimation
.
new
(
db_file:
file
,
level:
level
)
decim
.
update_attributes
(
entry
[
:metadata
])
decim
.
save!
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