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
f81d61a3
authored
Jul 10, 2016
by
John Doe
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fixed metadata parsing
parent
6e571f5a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
13 deletions
app/adapters/db_adapter.rb
app/models/db_file.rb
app/models/db_folder.rb
app/services/db/update_db.rb
spec/services/db/update_db_spec.rb
app/adapters/db_adapter.rb
View file @
f81d61a3
...
...
@@ -24,6 +24,7 @@ class DbAdapter
"description"
,
"hidden"
,
"name"
))
metadata
.
symbolize_keys!
# Create the schema:
# 3 elements: path, attributes, streams
{
path:
entry
[
0
],
...
...
@@ -33,7 +34,7 @@ class DbAdapter
end_time:
entry
[
3
]
||
0
,
total_rows:
entry
[
4
],
total_time:
entry
[
5
]
}.
merge
(
metadata
.
except
(
"streams"
)),
}.
merge
(
metadata
.
except
(
:streams
)),
streams:
streams
}
end
...
...
app/models/db_file.rb
View file @
f81d61a3
...
...
@@ -7,6 +7,10 @@ class DbFile < ActiveRecord::Base
has_many
:db_decimations
,
dependent: :destroy
def
defined_attributes
[
:name
,
:name_abbrev
,
:description
,
:hidden
]
end
def
remove
(
db_service
:)
db_service
.
remove_file
(
path
)
destroy
...
...
app/models/db_folder.rb
View file @
f81d61a3
...
...
@@ -7,6 +7,10 @@ class DbFolder < ActiveRecord::Base
has_many
:subfolders
,
class_name:
'DbFolder'
,
foreign_key:
'parent_id'
has_many
:db_files
def
defined_attributes
[
:name
,
:description
,
:hidden
]
end
def
insert_file
(
file
:)
# add the file to this folder
file
.
db_folder
=
self
...
...
app/services/db/update_db.rb
View file @
f81d61a3
...
...
@@ -61,12 +61,13 @@ class UpdateDb # rubocop:disable Metrics/ClassLength
# if this folder has an info stream, find that entry and
# use its metadata to update the folder's attributes
def
__read_info_entry
(
entries
)
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
[
:attributes
]
end
info_entry
=
entries
.
detect
{
|
entry
|
entry
[
:chunks
]
==
[
'info'
]}
||
{}
# if there is an info entry, remove it from the array
# so we don't process it as a seperate file
entries
.
delete
(
info_entry
)
# return the attributes
info_entry
[
:attributes
]
end
# all entries agree on a common path
...
...
@@ -86,7 +87,9 @@ 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
)
folder
.
update_attributes
(
info
.
slice
(
:name
))
byebug
folder
.
update_attributes
(
info
.
slice
(
*
folder
.
defined_attributes
))
folder
.
save!
folder
end
...
...
@@ -160,7 +163,6 @@ class UpdateDb # rubocop:disable Metrics/ClassLength
# if the file doesn't have a name, use the default
base
[
:attributes
][
:name
]
||=
default_name
# automatically updates the streams for this file
byebug
if
base
[
:attributes
][
:streams
]
!=
nil
file
.
update_attributes
(
base
[
:attributes
])
file
.
save!
__build_decimations
(
file:
file
,
...
...
spec/services/db/update_db_spec.rb
View file @
f81d61a3
...
...
@@ -94,16 +94,16 @@ describe 'UpdateDb' do
end
# info streams and metadata
describe
'
given info streams
'
do
it
'
uses info stream to set folder data
'
do
describe
'
uses metadata
'
do
it
'
from folder info stream
'
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
'
reads metadata
from base file'
it
'
reads metadata
from decimations'
it
'from base file'
it
'from decimations'
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