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
01a9b8e0
authored
May 24, 2016
by
John
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
ignoring class length warning for UpdateDb, added more comments
parent
9ae9c64b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
4 deletions
app/services/db/update_db.rb
app/services/db/update_db.rb
View file @
01a9b8e0
# frozen_string_literal: true
# frozen_string_literal: true
# Handles construction of database objects
# Handles construction of database objects
class
UpdateDb
class
UpdateDb
# rubocop:disable Metrics/ClassLength
attr_accessor
:warnings
,
:errors
attr_accessor
:warnings
,
:errors
def
initialize
(
db
:)
def
initialize
(
db
:)
...
@@ -30,6 +30,10 @@ class UpdateDb
...
@@ -30,6 +30,10 @@ class UpdateDb
# Adds :chunks to each schema element
# Adds :chunks to each schema element
# :chunks is an array of the entry's path elements
# :chunks is an array of the entry's path elements
# this makes it easier to traverse the database structure.
# this makes it easier to traverse the database structure.
# The array is reversed so the chunks can be popped off in order
# path: '/data/meter/prep-a'
# chunks: ['prep-a','meter','data']
#
def
__create_entries
(
schema
)
def
__create_entries
(
schema
)
schema
.
map
do
|
entry
|
schema
.
map
do
|
entry
|
entry
[
:chunks
]
=
entry
[
:path
][
1
..-
1
].
split
(
'/'
).
reverse
entry
[
:chunks
]
=
entry
[
:path
][
1
..-
1
].
split
(
'/'
).
reverse
...
@@ -50,7 +54,7 @@ class UpdateDb
...
@@ -50,7 +54,7 @@ class UpdateDb
groups
=
__group_entries
(
entries
)
groups
=
__group_entries
(
entries
)
# process the groups as subfolders or files
# process the groups as subfolders or files
__process_folder_contents
(
folder
,
groups
)
__process_folder_contents
(
folder
,
groups
)
# return the updated folder
folder
folder
end
end
...
@@ -58,6 +62,8 @@ class UpdateDb
...
@@ -58,6 +62,8 @@ class UpdateDb
# use its metadata to update the folder's attributes
# use its metadata to update the folder's attributes
def
__read_info_entry
(
entries
)
def
__read_info_entry
(
entries
)
if
entries
[
0
][
:chunks
]
==
[
'info'
]
if
entries
[
0
][
:chunks
]
==
[
'info'
]
# if there is an info entry, remove it from the array
# so we don't process it as a seperate file
info_entry
=
entries
.
slice!
(
0
)
info_entry
=
entries
.
slice!
(
0
)
info_entry
[
:metadata
]
info_entry
[
:metadata
]
end
end
...
@@ -85,7 +91,7 @@ class UpdateDb
...
@@ -85,7 +91,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
...
@@ -93,7 +99,7 @@ class UpdateDb
...
@@ -93,7 +99,7 @@ class UpdateDb
def
__group_entries
(
entries
)
def
__group_entries
(
entries
)
entry_groups
=
{}
entry_groups
=
{}
entries
.
map
do
|
entry
|
entries
.
map
do
|
entry
|
# group streams by their base paths
# group streams by their base paths
(ignore ~decim endings)
group_name
=
entry
[
:chunks
].
pop
.
gsub
(
decimation_tag
,
''
)
group_name
=
entry
[
:chunks
].
pop
.
gsub
(
decimation_tag
,
''
)
__add_to_group
(
entry_groups
,
group_name
,
entry
)
__add_to_group
(
entry_groups
,
group_name
,
entry
)
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